1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 13946 13947 13948 13949 13950 13951 13952 13953 13954 13955 13956 13957 13958 13959 13960 13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 13978 13979 13980 13981 13982 13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 14537 14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593 14594 14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 14611 14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634 14635 14636 14637 14638 14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 14755 14756 14757 14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 14793 14794 14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 14849 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 14860 14861 14862 14863 14864 14865 14866 14867 14868 14869 14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882 14883 14884 14885 14886 14887 14888 14889 14890 14891 14892 14893 14894 14895 14896 14897 14898 14899 14900 14901 14902 14903 14904 14905 14906 14907 14908 14909 14910 14911 14912 14913 14914 14915 14916 14917 14918 14919 14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 14931 14932 14933 14934 14935 14936 14937 14938 14939 14940 14941 14942 14943 14944 14945 14946 14947 14948 14949 14950 14951 14952 14953 14954 14955 14956 14957 14958 14959 14960 14961 14962 14963 14964 14965 14966 14967 14968 14969 14970 14971 14972 14973 14974 14975 14976 14977 14978 14979 14980 14981 14982 14983 14984 14985 14986 14987 14988 14989 14990 14991 14992 14993 14994 14995 14996 14997 14998 14999 15000 15001 15002 15003 15004 15005 15006 15007 15008 15009 15010 15011 15012 15013 15014 15015 15016 15017 15018 15019 15020 15021 15022 15023 15024 15025 15026 15027 15028 15029 15030 15031 15032 15033 15034 15035 15036 15037 15038 15039 15040 15041 15042 15043 15044 15045 15046 15047 15048 15049 15050 15051 15052 15053 15054 15055 15056 15057 15058 15059 15060 15061 15062 15063 15064 15065 15066 15067 15068 15069 15070 15071 15072 15073 15074 15075 15076 15077 15078 15079 15080 15081 15082 15083 15084 15085 15086 15087 15088 15089 15090 15091 15092 15093 15094 15095 15096 15097 15098 15099 15100 15101 15102 15103 15104 15105 15106 15107 15108 15109 15110 15111 15112 15113 15114 15115 15116 15117 15118 15119 15120 15121 15122 15123 15124 15125 15126 15127 15128 15129 15130 15131 15132 15133 15134 15135 15136 15137 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 15154 15155 15156 15157 15158 15159 15160 15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 15175 15176 15177 15178 15179 15180 15181 15182 15183 15184 15185 15186 15187 15188 15189 15190 15191 15192 15193 15194 15195 15196 15197 15198 15199 15200 15201 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212 15213 15214 15215 15216 15217 15218 15219 15220 15221 15222 15223 15224 15225 15226 15227 15228 15229 15230 15231 15232 15233 15234 15235 15236 15237 15238 15239 15240 15241 15242 15243 15244 15245 15246 15247 15248 15249 15250 15251 15252 15253 15254 15255 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265 15266 15267 15268 15269 15270 15271 15272 15273 15274 15275 15276 15277 15278 15279 15280 15281 15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 15304 15305 15306 15307 15308 15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 15321 15322 15323 15324 15325 15326 15327 15328 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 15339 15340 15341 15342 15343 15344 15345 15346 15347 15348 15349 15350 15351 15352 15353 15354 15355 15356 15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 15373 15374 15375 15376 15377 15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408 15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 15437 15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 15705 15706 15707 15708 15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 15722 15723 15724 15725 15726 15727 15728 15729 15730 15731 15732 15733 15734 15735 15736 15737 15738 15739 15740 15741 15742 15743 15744 15745 15746 15747 15748 15749 15750 15751 15752 15753 15754 15755 15756 15757 15758 15759 15760 15761 15762 15763 15764 15765 15766 15767 15768 15769 15770 15771 15772 15773 15774 15775 15776 15777 15778 15779 15780 15781 15782 15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 15794 15795 15796 15797 15798 15799 15800 15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821 15822 15823 15824 15825 15826 15827 15828 15829 15830 15831 15832 15833 15834 15835 15836 15837 15838 15839 15840 15841 15842 15843 15844 15845 15846 15847 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 15876 15877 15878 15879 15880 15881 15882 15883 15884 15885 15886 15887 15888 15889 15890 15891 15892 15893 15894 15895 15896 15897 15898 15899 15900 15901 15902 15903 15904 15905 15906 15907 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 15926 15927 15928 15929 15930 15931 15932 15933 15934 15935 15936 15937 15938 15939 15940 15941 15942 15943 15944 15945 15946 15947 15948 15949 15950 15951 15952 15953 15954 15955 15956 15957 15958 15959 15960 15961 15962 15963 15964 15965 15966 15967 15968 15969 15970 15971 15972 15973 15974 15975 15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988 15989 15990 15991 15992 15993 15994 15995 15996 15997 15998 15999 16000 16001 16002 16003 16004 16005 16006 16007 16008 16009 16010 16011 16012 16013 16014 16015 16016 16017 16018 16019 16020 16021 16022 16023 16024 16025 16026 16027 16028 16029 16030 16031 16032 16033 16034 16035 16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046 16047 16048 16049 16050 16051 16052 16053 16054 16055 16056 16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 16074 16075 16076 16077 16078 16079 16080 16081 16082 16083 16084 16085 16086 16087 16088 16089 16090 16091 16092 16093 16094 16095 16096 16097 16098 16099 16100 16101 16102 16103 16104 16105 16106 16107 16108 16109 16110 16111 16112 16113 16114 16115 16116 16117 16118 16119 16120 16121 16122 16123 16124 16125 16126 16127 16128 16129 16130 16131 16132 16133 16134 16135 16136 16137 16138 16139 16140 16141 16142 16143 16144 16145 16146 16147 16148 16149 16150 16151 16152 16153 16154 16155 16156 16157 16158 16159 16160 16161 16162 16163 16164 16165 16166 16167 16168 16169 16170 16171 16172 16173 16174 16175 16176 16177 16178 16179 16180 16181 16182 16183 16184 16185 16186 16187 16188 16189 16190 16191 16192 16193 16194 16195 16196 16197 16198 16199 16200 16201 16202 16203 16204 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214 16215 16216 16217 16218 16219 16220 16221 16222 16223 16224 16225 16226 16227 16228 16229 16230 16231 16232 16233 16234 16235 16236 16237 16238 16239 16240 16241 16242 16243 16244 16245 16246 16247 16248 16249 16250 16251 16252 16253 16254 16255 16256 16257 16258 16259 16260 16261 16262 16263 16264 16265 16266 16267 16268 16269 16270 16271 16272 16273 16274 16275 16276 16277 16278 16279 16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 16297 16298 16299 16300 16301 16302 16303 16304 16305 16306 16307 16308 16309 16310 16311 16312 16313 16314 16315 16316 16317 16318 16319 16320 16321 16322 16323 16324 16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 16336 16337 16338 16339 16340 16341 16342 16343 16344 16345 16346 16347 16348 16349 16350 16351 16352 16353 16354 16355 16356 16357 16358 16359 16360 16361 16362 16363 16364 16365 16366 16367 16368 16369 16370 16371 16372 16373 16374 16375 16376 16377 16378 16379 16380 16381 16382 16383 16384 16385 16386 16387 16388 16389 16390 16391 16392 16393 16394 16395 16396 16397 16398 16399 16400 16401 16402 16403 16404 16405 16406 16407 16408 16409 16410 16411 16412 16413 16414 16415 16416 16417 16418 16419 16420 16421 16422 16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 16436 16437 16438 16439 16440 16441 16442 16443 16444 16445 16446 16447 16448 16449 16450 16451 16452 16453 16454 16455 16456 16457 16458 16459 16460 16461 16462 16463 16464 16465 16466 16467 16468 16469 16470 16471 16472 16473 16474 16475 16476 16477 16478 16479 16480 16481 16482 16483 16484 16485 16486 16487 16488 16489 16490 16491 16492 16493 16494 16495 16496 16497 16498 16499 16500 16501 16502 16503 16504 16505 16506 16507 16508 16509 16510 16511 16512 16513 16514 16515 16516 16517 16518 16519 16520 16521 16522 16523 16524 16525 16526 16527 16528 16529 16530 16531 16532 16533 16534 16535 16536 16537 16538 16539 16540 16541 16542 16543 16544 16545 16546 16547 16548 16549 16550 16551 16552 16553 16554 16555 16556 16557 16558 16559 16560 16561 16562 16563 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574 16575 16576 16577 16578 16579 16580 16581 16582 16583 16584 16585 16586 16587 16588 16589 16590 16591 16592 16593 16594 16595 16596 16597 16598 16599 16600 16601 16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 16668 16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 16719 16720 16721 16722 16723 16724 16725 16726 16727 16728 16729 16730 16731 16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 16743 16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 16756 16757 16758 16759 16760 16761 16762 16763 16764 16765 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 16776 16777 16778 16779 16780 16781 16782 16783 16784 16785 16786 16787 16788 16789 16790 16791 16792 16793 16794 16795 16796 16797 16798 16799 16800 16801 16802 16803 16804 16805 16806 16807 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 16818 16819 16820 16821 16822 16823 16824 16825 16826 16827 16828 16829 16830 16831 16832 16833 16834 16835 16836 16837 16838 16839 16840 16841 16842 16843 16844 16845 16846 16847 16848 16849 16850 16851 16852 16853 16854 16855 16856 16857 16858 16859 16860 16861 16862 16863 16864 16865 16866 16867 16868 16869 16870 16871 16872 16873 16874 16875 16876 16877 16878 16879 16880 16881 16882 16883 16884 16885 16886 16887 16888 16889 16890 16891 16892 16893 16894 16895 16896 16897 16898 16899 16900 16901 16902 16903 16904 16905 16906 16907 16908 16909 16910 16911 16912 16913 16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943 16944 16945 16946 16947 16948 16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 16961 16962 16963 16964 16965 16966 16967 16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 16992 16993 16994 16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 17014 17015 17016 17017 17018 17019 17020 17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089 17090 17091 17092 17093 17094 17095 17096 17097 17098 17099 17100 17101 17102 17103 17104 17105 17106 17107 17108 17109 17110 17111 17112 17113 17114 17115 17116 17117 17118 17119 17120 17121 17122 17123 17124 17125 17126 17127 17128 17129 17130 17131 17132 17133 17134 17135 17136 17137 17138 17139 17140 17141 17142 17143 17144 17145 17146 17147 17148 17149 17150 17151 17152 17153 17154 17155 17156 17157 17158 17159 17160 17161 17162 17163 17164 17165 17166 17167 17168 17169 17170 17171 17172 17173 17174 17175 17176 17177 17178 17179 17180 17181 17182 17183 17184 17185 17186 17187 17188 17189 17190 17191 17192 17193 17194 17195 17196 17197 17198 17199 17200 17201 17202 17203 17204 17205 17206 17207 17208 17209 17210 17211 17212 17213 17214 17215 17216 17217 17218 17219 17220 17221 17222 17223 17224 17225 17226 17227 17228 17229 17230 17231 17232 17233 17234 17235 17236 17237 17238 17239 17240 17241 17242 17243 17244 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 17255 17256 17257 17258 17259 17260 17261 17262 17263 17264 17265 17266 17267 17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 17305 17306 17307 17308 17309 17310 17311 17312 17313 17314 17315 17316 17317 17318 17319 17320 17321 17322 17323 17324 17325 17326 17327 17328 17329 17330 17331 17332 17333 17334 17335 17336 17337 17338 17339 17340 17341 17342 17343 17344 17345 17346 17347 17348 17349 17350 17351 17352 17353 17354 17355 17356 17357 17358 17359 17360 17361 17362 17363 17364 17365 17366 17367 17368 17369 17370 17371 17372 17373 17374 17375 17376 17377 17378 17379 17380 17381 17382 17383 17384 17385 17386 17387 17388 17389 17390 17391 17392 17393 17394 17395 17396 17397 17398 17399 17400 17401 17402 17403 17404 17405 17406 17407 17408 17409 17410 17411 17412 17413 17414 17415 17416 17417 17418 17419 17420 17421 17422 17423 17424 17425 17426 17427 17428 17429 17430 17431 17432 17433 17434 17435 17436 17437 17438 17439 17440 17441 17442 17443 17444 17445 17446 17447 17448 17449 17450 17451 17452 17453 17454 17455 17456 17457 17458 17459 17460 17461 17462 17463 17464 17465 17466 17467 17468 17469 17470 17471 17472 17473 17474 17475 17476 17477 17478 17479 17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 17499 17500 17501 17502 17503 17504 17505 17506 17507 17508 17509 17510 17511 17512 17513 17514 17515 17516 17517 17518 17519 17520 17521 17522 17523 17524 17525 17526 17527 17528 17529 17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 17545 17546 17547 17548 17549 17550 17551 17552 17553 17554 17555 17556 17557 17558 17559 17560 17561 17562 17563 17564 17565 17566 17567 17568 17569 17570 17571 17572 17573 17574 17575 17576 17577 17578 17579 17580 17581 17582 17583 17584 17585 17586 17587 17588 17589 17590 17591 17592 17593 17594 17595 17596 17597 17598 17599 17600 17601 17602 17603 17604 17605 17606 17607 17608 17609 17610 17611 17612 17613 17614 17615 17616 17617 17618 17619 17620 17621 17622 17623 17624 17625 17626 17627 17628 17629 17630 17631 17632 17633 17634 17635 17636 17637 17638 17639 17640 17641 17642 17643 17644 17645 17646 17647 17648 17649 17650 17651 17652 17653 17654 17655 17656 17657 17658 17659 17660 17661 17662 17663 17664 17665 17666 17667 17668 17669 17670 17671 17672 17673 17674 17675 17676 17677 17678 17679 17680 17681 17682 17683 17684 17685 17686 17687 17688 17689 17690 17691 17692 17693 17694 17695 17696 17697 17698 17699 17700 17701 17702 17703 17704 17705 17706 17707 17708 17709 17710 17711 17712 17713 17714 17715 17716 17717 17718 17719 17720 17721 17722 17723 17724 17725 17726 17727 17728 17729 17730 17731 17732 17733 17734 17735 17736 17737 17738 17739 17740 17741 17742 17743 17744 17745 17746 17747 17748 17749 17750 17751 17752 17753 17754 17755 17756 17757 17758 17759 17760 17761 17762 17763 17764 17765 17766 17767 17768 17769 17770 17771 17772 17773 17774 17775 17776 17777 17778 17779 17780 17781 17782 17783 17784 17785 17786 17787 17788 17789 17790 17791 17792 17793 17794 17795 17796 17797 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 17811 17812 17813 17814 17815 17816 17817 17818 17819 17820 17821 17822 17823 17824 17825 17826 17827 17828 17829 17830 17831 17832 17833 17834 17835 17836 17837 17838 17839 17840 17841 17842 17843 17844 17845 17846 17847 17848 17849 17850 17851 17852 17853 17854 17855 17856 17857 17858 17859 17860 17861 17862 17863 17864 17865 17866 17867 17868 17869 17870 17871 17872 17873 17874 17875 17876 17877 17878 17879 17880 17881 17882 17883 17884 17885 17886 17887 17888 17889 17890 17891 17892 17893 17894 17895 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905 17906 17907 17908 17909 17910 17911 17912 17913 17914 17915 17916 17917 17918 17919 17920 17921 17922 17923 17924 17925 17926 17927 17928 17929 17930 17931 17932 17933 17934 17935 17936 17937 17938 17939 17940 17941 17942 17943 17944 17945 17946 17947 17948 17949 17950 17951 17952 17953 17954 17955 17956 17957 17958 17959 17960 17961 17962 17963 17964 17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006 18007 18008 18009 18010 18011 18012 18013 18014 18015 18016 18017 18018 18019 18020 18021 18022 18023 18024 18025 18026 18027 18028 18029 18030 18031 18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 18043 18044 18045 18046 18047 18048 18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18066 18067 18068 18069 18070 18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 18104 18105 18106 18107 18108 18109 18110 18111 18112 18113 18114 18115 18116 18117 18118 18119 18120 18121 18122 18123 18124 18125 18126 18127 18128 18129 18130 18131 18132 18133 18134 18135 18136 18137 18138 18139 18140 18141 18142 18143 18144 18145 18146 18147 18148 18149 18150 18151 18152 18153 18154 18155 18156 18157 18158 18159 18160 18161 18162 18163 18164 18165 18166 18167 18168 18169 18170 18171 18172 18173 18174 18175 18176 18177 18178 18179 18180 18181 18182 18183 18184 18185 18186 18187 18188 18189 18190 18191 18192 18193 18194 18195 18196 18197 18198 18199 18200 18201 18202 18203 18204 18205 18206 18207 18208 18209 18210 18211 18212 18213 18214 18215 18216 18217 18218 18219 18220 18221 18222 18223 18224 18225 18226 18227 18228 18229 18230 18231 18232 18233 18234 18235 18236 18237 18238 18239 18240 18241 18242 18243 18244 18245 18246 18247 18248 18249 18250 18251 18252 18253 18254 18255 18256 18257 18258 18259 18260 18261 18262 18263 18264 18265 18266 18267 18268 18269 18270 18271 18272 18273 18274 18275 18276 18277 18278 18279 18280 18281 18282 18283 18284 18285 18286 18287 18288 18289 18290 18291 18292 18293 18294 18295 18296 18297 18298 18299 18300 18301 18302 18303 18304 18305 18306 18307 18308 18309 18310 18311 18312 18313 18314 18315 18316 18317 18318 18319 18320 18321 18322 18323 18324 18325 18326 18327 18328 18329 18330 18331 18332 18333 18334 18335 18336 18337 18338 18339 18340 18341 18342 18343 18344 18345 18346 18347 18348 18349 18350 18351 18352 18353 18354 18355 18356 18357 18358 18359 18360 18361 18362 18363 18364 18365 18366 18367 18368 18369 18370 18371 18372 18373 18374 18375 18376 18377 18378 18379 18380 18381 18382 18383 18384 18385 18386 18387 18388 18389 18390 18391 18392 18393 18394 18395 18396 18397 18398 18399 18400 18401 18402 18403 18404 18405 18406 18407 18408 18409 18410 18411 18412 18413 18414 18415 18416 18417 18418 18419 18420 18421 18422 18423 18424 18425 18426 18427 18428 18429 18430 18431 18432 18433 18434 18435 18436 18437 18438 18439 18440 18441 18442 18443 18444 18445 18446 18447 18448 18449 18450 18451 18452 18453 18454 18455 18456 18457 18458 18459 18460 18461 18462 18463 18464 18465 18466 18467 18468 18469 18470 18471 18472 18473 18474 18475 18476 18477 18478 18479 18480 18481 18482 18483 18484 18485 18486 18487 18488 18489 18490 18491 18492 18493 18494 18495 18496 18497 18498 18499 18500 18501 18502 18503 18504 18505 18506 18507 18508 18509 18510 18511 18512 18513 18514 18515 18516 18517 18518 18519 18520 18521 18522 18523 18524 18525 18526 18527 18528 18529 18530 18531 18532 18533 18534 18535 18536 18537 18538 18539 18540 18541 18542 18543 18544 18545 18546 18547 18548 18549 18550 18551 18552 18553 18554 18555 18556 18557 18558 18559 18560 18561 18562 18563 18564 18565 18566 18567 18568 18569 18570 18571 18572 18573 18574 18575 18576 18577 18578 18579 18580 18581 18582 18583 18584 18585 18586 18587 18588 18589 18590 18591 18592 18593 18594 18595 18596 18597 18598 18599 18600 18601 18602 18603 18604 18605 18606 18607 18608 18609 18610 18611 18612 18613 18614 18615 18616 18617 18618 18619 18620 18621 18622 18623 18624 18625 18626 18627 18628 18629 18630 18631 18632 18633 18634 18635 18636 18637 18638 18639 18640 18641 18642 18643 18644 18645 18646 18647 18648 18649 18650 18651 18652 18653 18654 18655 18656 18657 18658 18659 18660 18661 18662 18663 18664 18665 18666 18667 18668 18669 18670 18671 18672 18673 18674 18675 18676 18677 18678 18679 18680 18681 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 18692 18693 18694 18695 18696 18697 18698 18699 18700 18701 18702 18703 18704 18705 18706 18707 18708 18709 18710 18711 18712 18713 18714 18715 18716 18717 18718 18719 18720 18721 18722 18723 18724 18725 18726 18727 18728 18729 18730 18731 18732 18733 18734 18735 18736 18737 18738 18739 18740 18741 18742 18743 18744 18745 18746 18747 18748 18749 18750 18751 18752 18753 18754 18755 18756 18757 18758 18759 18760 18761 18762 18763 18764 18765 18766 18767 18768 18769 18770 18771 18772 18773 18774 18775 18776 18777 18778 18779 18780 18781 18782 18783 18784 18785 18786 18787 18788 18789 18790 18791 18792 18793 18794 18795 18796 18797 18798 18799 18800 18801 18802 18803 18804 18805 18806 18807 18808 18809 18810 18811 18812 18813 18814 18815 18816 18817 18818 18819 18820 18821 18822 18823 18824 18825 18826 18827 18828 18829 18830 18831 18832 18833 18834 18835 18836 18837 18838 18839 18840 18841 18842 18843 18844 18845 18846 18847 18848 18849 18850 18851 18852 18853 18854 18855 18856 18857 18858 18859 18860 18861 18862 18863 18864 18865 18866 18867 18868 18869 18870 18871 18872 18873 18874 18875 18876 18877 18878 18879 18880 18881 18882 18883 18884 18885 18886 18887 18888 18889 18890 18891 18892 18893 18894 18895 18896 18897 18898 18899 18900 18901 18902 18903 18904 18905 18906 18907 18908 18909 18910 18911 18912 18913 18914 18915 18916 18917 18918 18919 18920 18921 18922 18923 18924 18925 18926 18927 18928 18929 18930 18931 18932 18933 18934 18935 18936 18937 18938 18939 18940 18941 18942 18943 18944 18945 18946 18947 18948 18949 18950 18951 18952 18953 18954 18955 18956 18957 18958 18959 18960 18961 18962 18963 18964 18965 18966 18967 18968 18969 18970 18971 18972 18973 18974 18975 18976 18977 18978 18979 18980 18981 18982 18983 18984 18985 18986 18987 18988 18989 18990 18991 18992 18993 18994 18995 18996 18997 18998 18999 19000 19001 19002 19003 19004 19005 19006 19007 19008 19009 19010 19011 19012 19013 19014 19015 19016 19017 19018 19019 19020 19021 19022 19023 19024 19025 19026 19027 19028 19029 19030 19031 19032 19033 19034 19035 19036 19037 19038 19039 19040 19041 19042 19043 19044 19045 19046 19047 19048 19049 19050 19051 19052 19053 19054 19055 19056 19057 19058 19059 19060 19061 19062 19063 19064 19065 19066 19067 19068 19069 19070 19071 19072 19073 19074 19075 19076 19077 19078 19079 19080 19081 19082 19083 19084 19085 19086 19087 19088 19089 19090 19091 19092 19093 19094 19095 19096 19097 19098 19099 19100 19101 19102 19103 19104 19105 19106 19107 19108 19109 19110 19111 19112 19113 19114 19115 19116 19117 19118 19119 19120 19121 19122 19123 19124 19125 19126 19127 19128 19129 19130 19131 19132 19133 19134 19135 19136 19137 19138 19139 19140 19141 19142 19143 19144 19145 19146 19147 19148 19149 19150 19151 19152 19153 19154 19155 19156 19157 19158 19159 19160 19161 19162 19163 19164 19165 19166 19167 19168 19169 19170 19171 19172 19173 19174 19175 19176 19177 19178 19179 19180 19181 19182 19183 19184 19185 19186 19187 19188 19189 19190 19191 19192 19193 19194 19195 19196 19197 19198 19199 19200 19201 19202 19203 19204 19205 19206 19207 19208 19209 19210 19211 19212 19213 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 19243 19244 19245 19246 19247 19248 19249 19250 19251 19252 19253 19254 19255 19256 19257 19258 19259 19260 19261 19262 19263 19264 19265 19266 19267 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 19280 19281 19282 19283 19284 19285 19286 19287 19288 19289 19290 19291 19292 19293 19294 19295 19296 19297 19298 19299 19300 19301 19302 19303 19304 19305 19306 19307 19308 19309 19310 19311 19312 19313 19314 19315 19316 19317 19318 19319 19320 19321 19322 19323 19324 19325 19326 19327 19328 19329 19330 19331 19332 19333 19334 19335 19336 19337 19338 19339 19340 19341 19342 19343 19344 19345 19346 19347 19348 19349 19350 19351 19352 19353 19354 19355 19356 19357 19358 19359 19360 19361 19362 19363 19364 19365 19366 19367 19368 19369 19370 19371 19372 19373 19374 19375 19376 19377 19378 19379 19380 19381 19382 19383 19384 19385 19386 19387 19388 19389 19390 19391 19392 19393 19394 19395 19396 19397 19398 19399 19400 19401 19402 19403 19404 19405 19406 19407 19408 19409 19410 19411 19412 19413 19414 19415 19416 19417 19418 19419 19420 19421 19422 19423 19424 19425 19426 19427 19428 19429 19430 19431 19432 19433 19434 19435 19436 19437 19438 19439 19440 19441 19442 19443 19444 19445 19446 19447 19448 19449 19450 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 19472 19473 19474 19475 19476 19477 19478 19479 19480 19481 19482 19483 19484 19485 19486 19487 19488 19489 19490 19491 19492 19493 19494 19495 19496 19497 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 19509 19510 19511 19512 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 19543 19544 19545 19546 19547 19548 19549 19550 19551 19552 19553 19554 19555 19556 19557 19558 19559 19560 19561 19562 19563 19564 19565 19566 19567 19568 19569 19570 19571 19572 19573 19574 19575 19576 19577 19578 19579 19580 19581 19582 19583 19584 19585 19586 19587 19588 19589 19590 19591 19592 19593 19594 19595 19596 19597 19598 19599 19600 19601 19602 19603 19604 19605 19606 19607 19608 19609 19610 19611 19612 19613 19614 19615 19616 19617 19618 19619 19620 19621 19622 19623 19624 19625 19626 19627 19628 19629 19630 19631 19632 19633 19634 19635 19636 19637 19638 19639 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 19650 19651 19652 19653 19654 19655 19656 19657 19658 19659 19660 19661 19662 19663 19664 19665 19666 19667 19668 19669 19670 19671 19672 19673 19674 19675 19676 19677 19678 19679 19680 19681 19682 19683 19684 19685 19686 19687 19688 19689 19690 19691 19692 19693 19694 19695 19696 19697 19698 19699 19700 19701 19702 19703 19704 19705 19706 19707 19708 19709 19710 19711 19712 19713 19714 19715 19716 19717 19718 19719 19720 19721 19722 19723 19724 19725 19726 19727 19728 19729 19730 19731 19732 19733 19734 19735 19736 19737 19738 19739 19740 19741 19742 19743 19744 19745 19746 19747 19748 19749 19750 19751 19752 19753 19754 19755 19756 19757 19758 19759 19760 19761 19762 19763 19764 19765 19766 19767 19768 19769 19770 19771 19772 19773 19774 19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 19788 19789 19790 19791 19792 19793 19794 19795 19796 19797 19798 19799 19800 19801 19802 19803 19804 19805 19806 19807 19808 19809 19810 19811 19812 19813 19814 19815 19816 19817 19818 19819 19820
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ E L A B --
-- --
-- B o d y --
-- --
-- Copyright (C) 1997-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 ALI; use ALI;
with Atree; use Atree;
with Checks; use Checks;
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 Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Cat; use Sem_Cat;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Prag; use Sem_Prag;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Sinput; use Sinput;
with Snames; use Snames;
with Stand; use Stand;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Uname; use Uname;
with Warnsw; use Warnsw;
with GNAT; use GNAT;
with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
with GNAT.Lists; use GNAT.Lists;
with GNAT.Sets; use GNAT.Sets;
package body Sem_Elab is
-----------------------------------------
-- Access-before-elaboration mechanism --
-----------------------------------------
-- The access-before-elaboration (ABE) mechanism implemented in this unit
-- has the following objectives:
--
-- * Diagnose at compile time or install run-time checks to prevent ABE
-- access to data and behavior.
--
-- The high-level idea is to accurately diagnose ABE issues within a
-- single unit because the ABE mechanism can inspect the whole unit.
-- As soon as the elaboration graph extends to an external unit, the
-- diagnostics stop because the body of the unit may not be available.
-- Due to control and data flow, the ABE mechanism cannot accurately
-- determine whether a particular scenario will be elaborated or not.
-- Conditional ABE checks are therefore used to verify the elaboration
-- status of local and external targets at run time.
--
-- * Supply implicit elaboration dependencies for a unit to binde
--
-- The ABE mechanism creates implicit dependencies in the form of with
-- clauses subject to pragma Elaborate[_All] when the elaboration graph
-- reaches into an external unit. The implicit dependencies are encoded
-- in the ALI file of the main unit. GNATbind and binde then use these
-- dependencies to augment the library item graph and determine the
-- elaboration order of all units in the compilation.
--
-- * Supply pieces of the invocation graph for a unit to bindo
--
-- The ABE mechanism captures paths starting from elaboration code or
-- top level constructs that reach into an external unit. The paths are
-- encoded in the ALI file of the main unit in the form of declarations
-- which represent nodes, and relations which represent edges. GNATbind
-- and bindo then build the full invocation graph in order to augment
-- the library item graph and determine the elaboration order of all
-- units in the compilation.
--
-- The ABE mechanism supports three models of elaboration:
--
-- * Dynamic model - This is the most permissive of the three models.
-- When the dynamic model is in effect, the mechanism diagnoses and
-- installs run-time checks to detect ABE issues in the main unit.
-- The behavior of this model is identical to that specified by the
-- Ada RM. This model is enabled with switch -gnatE.
--
-- Static model - This is the middle ground of the three models. When
-- the static model is in effect, the mechanism diagnoses and installs
-- run-time checks to detect ABE issues in the main unit. In addition,
-- the mechanism generates implicit dependencies between units in the
-- form of with clauses subject to pragma Elaborate[_All] to ensure
-- the prior elaboration of withed units. This is the default model.
--
-- * SPARK model - This is the most conservative of the three models and
-- implements the semantics defined in SPARK RM 7.7. The SPARK model
-- is in effect only when a context resides in a SPARK_Mode On region,
-- otherwise the mechanism falls back to one of the previous models.
--
-- The ABE mechanism consists of a "recording" phase and a "processing"
-- phase.
-----------------
-- Terminology --
-----------------
-- * ABE - An attempt to invoke a scenario which has not been elaborated
-- yet.
--
-- * Bridge target - A type of target. A bridge target is a link between
-- scenarios. It is usually a byproduct of expansion and does not have
-- any direct ABE ramifications.
--
-- * Call marker - A special node used to indicate the presence of a call
-- in the tree in case expansion transforms or eliminates the original
-- call. N_Call_Marker nodes do not have static and run-time semantics.
--
-- * Conditional ABE - A type of ABE. A conditional ABE occurs when the
-- invocation of a target by a scenario within the main unit causes an
-- ABE, but does not cause an ABE for another scenarios within the main
-- unit.
--
-- * Declaration level - A type of enclosing level. A scenario or target is
-- at the declaration level when it appears within the declarations of a
-- block statement, entry body, subprogram body, or task body, ignoring
-- enclosing packages.
--
-- * Early call region - A section of code which ends at a subprogram body
-- and starts from the nearest non-preelaborable construct which precedes
-- the subprogram body. The early call region extends from a package body
-- to a package spec when the spec carries pragma Elaborate_Body.
--
-- * Generic library level - A type of enclosing level. A scenario or
-- target is at the generic library level if it appears in a generic
-- package library unit, ignoring enclosing packages.
--
-- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the
-- invocation of a target by all scenarios within the main unit causes
-- an ABE.
--
-- * Instantiation library level - A type of enclosing level. A scenario
-- or target is at the instantiation library level if it appears in an
-- instantiation library unit, ignoring enclosing packages.
--
-- * Invocation - The act of activating a task, calling a subprogram, or
-- instantiating a generic.
--
-- * Invocation construct - An entry declaration, [single] protected type,
-- subprogram declaration, subprogram instantiation, or a [single] task
-- type declared in the visible, private, or body declarations of the
-- main unit.
--
-- * Invocation relation - A flow link between two invocation constructs
--
-- * Invocation signature - A set of attributes that uniquely identify an
-- invocation construct within the namespace of all ALI files.
--
-- * Library level - A type of enclosing level. A scenario or target is at
-- the library level if it appears in a package library unit, ignoring
-- enclosing packages.
--
-- * Non-library-level encapsulator - A construct that cannot be elaborated
-- on its own and requires elaboration by a top-level scenario.
--
-- * Scenario - A construct or context which is invoked by elaboration code
-- or invocation construct. The scenarios recognized by the ABE mechanism
-- are as follows:
--
-- - '[Unrestricted_]Access of entries, operators, and subprograms
--
-- - Assignments to variables
--
-- - Calls to entries, operators, and subprograms
--
-- - Derived type declarations
--
-- - Instantiations
--
-- - Pragma Refined_State
--
-- - Reads of variables
--
-- - Task activation
--
-- * Target - A construct invoked by a scenario. The targets recognized by
-- the ABE mechanism are as follows:
--
-- - For '[Unrestricted_]Access of entries, operators, and subprograms,
-- the target is the entry, operator, or subprogram.
--
-- - For assignments to variables, the target is the variable
--
-- - For calls, the target is the entry, operator, or subprogram
--
-- - For derived type declarations, the target is the derived type
--
-- - For instantiations, the target is the generic template
--
-- - For pragma Refined_State, the targets are the constituents
--
-- - For reads of variables, the target is the variable
--
-- - For task activation, the target is the task body
------------------
-- Architecture --
------------------
-- Analysis/Resolution
-- |
-- +- Build_Call_Marker
-- |
-- +- Build_Variable_Reference_Marker
-- |
-- +- | -------------------- Recording phase ---------------------------+
-- | v |
-- | Record_Elaboration_Scenario |
-- | | |
-- | +--> Check_Preelaborated_Call |
-- | | |
-- | +--> Process_Guaranteed_ABE |
-- | | | |
-- | | +--> Process_Guaranteed_ABE_Activation |
-- | | +--> Process_Guaranteed_ABE_Call |
-- | | +--> Process_Guaranteed_ABE_Instantiation |
-- | | |
-- +- | ----------------------------------------------------------------+
-- |
-- |
-- +--> Internal_Representation
-- |
-- +--> Scenario_Storage
-- |
-- End of Compilation
-- |
-- +- | --------------------- Processing phase -------------------------+
-- | v |
-- | Check_Elaboration_Scenarios |
-- | | |
-- | +--> Check_Conditional_ABE_Scenarios |
-- | | | |
-- | | +--> Process_Conditional_ABE <----------------------+ |
-- | | | | |
-- | | +--> Process_Conditional_ABE_Activation | |
-- | | | | | |
-- | | | +-----------------------------+ | |
-- | | | | | |
-- | | +--> Process_Conditional_ABE_Call +---> Traverse_Body |
-- | | | | | |
-- | | | +-----------------------------+ |
-- | | | |
-- | | +--> Process_Conditional_ABE_Access_Taken |
-- | | +--> Process_Conditional_ABE_Instantiation |
-- | | +--> Process_Conditional_ABE_Variable_Assignment |
-- | | +--> Process_Conditional_ABE_Variable_Reference |
-- | | |
-- | +--> Check_SPARK_Scenario |
-- | | | |
-- | | +--> Process_SPARK_Scenario |
-- | | | |
-- | | +--> Process_SPARK_Derived_Type |
-- | | +--> Process_SPARK_Instantiation |
-- | | +--> Process_SPARK_Refined_State_Pragma |
-- | | |
-- | +--> Record_Invocation_Graph |
-- | | |
-- | +--> Process_Invocation_Body_Scenarios |
-- | +--> Process_Invocation_Spec_Scenarios |
-- | +--> Process_Main_Unit |
-- | | |
-- | +--> Process_Invocation_Scenario <-------------+ |
-- | | | |
-- | +--> Process_Invocation_Activation | |
-- | | | | |
-- | | +------------------------+ | |
-- | | | | |
-- | +--> Process_Invocation_Call +---> Traverse_Body |
-- | | | |
-- | +------------------------+ |
-- | |
-- +--------------------------------------------------------------------+
---------------------
-- Recording phase --
---------------------
-- The Recording phase coincides with the analysis/resolution phase of the
-- compiler. It has the following objectives:
--
-- * Record all suitable scenarios for examination by the Processing
-- phase.
--
-- Saving only a certain number of nodes improves the performance of
-- the ABE mechanism. This eliminates the need to examine the whole
-- tree in a separate pass.
--
-- * Record certain SPARK scenarios which are not necessarily invoked
-- during elaboration, but still require elaboration-related checks.
--
-- Saving only a certain number of nodes improves the performance of
-- the ABE mechanism. This eliminates the need to examine the whole
-- tree in a separate pass.
--
-- * Detect and diagnose calls in preelaborable or pure units, including
-- generic bodies.
--
-- This diagnostic is carried out during the Recording phase because it
-- does not need the heavy recursive traversal done by the Processing
-- phase.
--
-- * Detect and diagnose guaranteed ABEs caused by instantiations, calls,
-- and task activation.
--
-- The issues detected by the ABE mechanism are reported as warnings
-- because they do not violate Ada semantics. Forward instantiations
-- may thus reach gigi, however gigi cannot handle certain kinds of
-- premature instantiations and may crash. To avoid this limitation,
-- the ABE mechanism must identify forward instantiations as early as
-- possible and suppress their bodies. Calls and task activations are
-- included in this category for completeness.
----------------------
-- Processing phase --
----------------------
-- The Processing phase is a separate pass which starts after instantiating
-- and/or inlining of bodies, but before the removal of Ghost code. It has
-- the following objectives:
--
-- * Examine all scenarios saved during the Recording phase, and perform
-- the following actions:
--
-- - Dynamic model
--
-- Diagnose conditional ABEs, and install run-time conditional ABE
-- checks for all scenarios.
--
-- - SPARK model
--
-- Enforce the SPARK elaboration rules
--
-- - Static model
--
-- Diagnose conditional ABEs, install run-time conditional ABE
-- checks only for scenarios are reachable from elaboration code,
-- and guarantee the elaboration of external units by creating
-- implicit with clauses subject to pragma Elaborate[_All].
--
-- * Examine library-level scenarios and invocation constructs, and
-- perform the following actions:
--
-- - Determine whether the flow of execution reaches into an external
-- unit. If this is the case, encode the path in the ALI file of
-- the main unit.
--
-- - Create declarations for invocation constructs in the ALI file of
-- the main unit.
----------------------
-- Important points --
----------------------
-- The Processing phase starts after the analysis, resolution, expansion
-- phase has completed. As a result, no current semantic information is
-- available. The scope stack is empty, global flags such as In_Instance
-- or Inside_A_Generic become useless. To remedy this, the ABE mechanism
-- must either save or recompute semantic information.
--
-- Expansion heavily transforms calls and to some extent instantiations. To
-- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to
-- capture the target and relevant attributes of the original call.
--
-- The diagnostics of the ABE mechanism depend on accurate source locations
-- to determine the spatial relation of nodes.
-----------------------------------------
-- Suppression of elaboration warnings --
-----------------------------------------
-- Elaboration warnings along multiple traversal paths rooted at a scenario
-- are suppressed when the scenario has elaboration warnings suppressed.
--
-- Root scenario
-- |
-- +-- Child scenario 1
-- | |
-- | +-- Grandchild scenario 1
-- | |
-- | +-- Grandchild scenario N
-- |
-- +-- Child scenario N
--
-- If the root scenario has elaboration warnings suppressed, then all its
-- child, grandchild, etc. scenarios will have their elaboration warnings
-- suppressed.
--
-- In addition to switch -gnatwL, pragma Warnings may be used to suppress
-- elaboration-related warnings when used in the following manner:
--
-- pragma Warnings ("L");
-- <scenario-or-target>
--
-- <target>
-- pragma Warnings (Off, target);
--
-- pragma Warnings (Off);
-- <scenario-or-target>
--
-- * To suppress elaboration warnings for '[Unrestricted_]Access of
-- entries, operators, and subprograms, either:
--
-- - Suppress the entry, operator, or subprogram, or
-- - Suppress the attribute, or
-- - Use switch -gnatw.f
--
-- * To suppress elaboration warnings for calls to entries, operators,
-- and subprograms, either:
--
-- - Suppress the entry, operator, or subprogram, or
-- - Suppress the call
--
-- * To suppress elaboration warnings for instantiations, suppress the
-- instantiation.
--
-- * To suppress elaboration warnings for task activations, either:
--
-- - Suppress the task object, or
-- - Suppress the task type, or
-- - Suppress the activation call
--------------
-- Switches --
--------------
-- The following switches may be used to control the behavior of the ABE
-- mechanism.
--
-- -gnatd_a stop elaboration checks on accept or select statement
--
-- The ABE mechanism stops the traversal of a task body when it
-- encounters an accept or a select statement. This behavior is
-- equivalent to restriction No_Entry_Calls_In_Elaboration_Code,
-- but without penalizing actual entry calls during elaboration.
--
-- -gnatd_e ignore entry calls and requeue statements for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- protected or task entry calls as well as requeue statements.
-- As a result, the calls and requeues are not recorded or
-- processed.
--
-- -gnatdE elaboration checks on predefined units
--
-- The ABE mechanism considers scenarios which appear in internal
-- units (Ada, GNAT, Interfaces, System).
--
-- -gnatd_F encode full invocation paths in ALI files
--
-- The ABE mechanism encodes the full path from an elaboration
-- procedure or invocable construct to an external target. The
-- path contains all intermediate activations, instantiations,
-- and calls.
--
-- -gnatd.G ignore calls through generic formal parameters for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls which occur in expanded instances, and invoke generic
-- actual subprograms through generic formal subprograms. As a
-- result, the calls are not recorded or processed.
--
-- -gnatd_i ignore activations and calls to instances for elaboration
--
-- The ABE mechanism ignores calls and task activations when they
-- target a subprogram or task type defined an external instance.
-- As a result, the calls and task activations are not processed.
--
-- -gnatdL ignore external calls from instances for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls which occur in expanded instances, do not invoke generic
-- actual subprograms through formal subprograms, and the target
-- is external to the instance. As a result, the calls are not
-- recorded or processed.
--
-- -gnatd.o conservative elaboration order for indirect calls
--
-- The ABE mechanism treats '[Unrestricted_]Access of an entry,
-- operator, or subprogram as an immediate invocation of the
-- target. As a result, it performs ABE checks and diagnostics on
-- the immediate call.
--
-- -gnatd_p ignore assertion pragmas for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls to subprograms which verify the run-time semantics of
-- the following assertion pragmas:
--
-- Default_Initial_Condition
-- Initial_Condition
-- Invariant
-- Invariant'Class
-- Post
-- Post'Class
-- Postcondition
-- Type_Invariant
-- Type_Invariant_Class
--
-- As a result, the assertion expressions of the pragmas are not
-- processed.
--
-- -gnatd_s stop elaboration checks on synchronous suspension
--
-- The ABE mechanism stops the traversal of a task body when it
-- encounters a call to one of the following routines:
--
-- Ada.Synchronous_Barriers.Wait_For_Release
-- Ada.Synchronous_Task_Control.Suspend_Until_True
--
-- -gnatd_T output trace information on invocation relation construction
--
-- The ABE mechanism outputs text information concerning relation
-- construction to standard output.
--
-- -gnatd.U ignore indirect calls for static elaboration
--
-- The ABE mechanism does not consider '[Unrestricted_]Access of
-- entries, operators, and subprograms. As a result, the scenarios
-- are not recorder or processed.
--
-- -gnatd.v enforce SPARK elaboration rules in SPARK code
--
-- The ABE mechanism applies some of the SPARK elaboration rules
-- defined in the SPARK reference manual, chapter 7.7. Note that
-- certain rules are always enforced, regardless of whether the
-- switch is active.
--
-- -gnatd.y disable implicit pragma Elaborate_All on task bodies
--
-- The ABE mechanism does not generate implicit Elaborate_All when
-- the need for the pragma came from a task body.
--
-- -gnatE dynamic elaboration checking mode enabled
--
-- The ABE mechanism assumes that any scenario is elaborated or
-- invoked by elaboration code. The ABE mechanism performs very
-- little diagnostics and generates condintional ABE checks to
-- detect ABE issues at run-time.
--
-- -gnatel turn on info messages on generated Elaborate[_All] pragmas
--
-- The ABE mechanism produces information messages on generated
-- implicit Elabote[_All] pragmas along with traceback showing
-- why the pragma was generated. In addition, the ABE mechanism
-- produces information messages for each scenario elaborated or
-- invoked by elaboration code.
--
-- -gnateL turn off info messages on generated Elaborate[_All] pragmas
--
-- The complementary switch for -gnatel.
--
-- -gnatH legacy elaboration checking mode enabled
--
-- When this switch is in effect, the pre-18.x ABE model becomes
-- the de facto ABE model. This amounts to cutting off all entry
-- points into the new ABE mechanism, and giving full control to
-- the old ABE mechanism.
--
-- -gnatJ permissive elaboration checking mode enabled
--
-- This switch activates the following switches:
--
-- -gnatd_a
-- -gnatd_e
-- -gnatd.G
-- -gnatd_i
-- -gnatdL
-- -gnatd_p
-- -gnatd_s
-- -gnatd.U
-- -gnatd.y
--
-- IMPORTANT: The behavior of the ABE mechanism becomes more
-- permissive at the cost of accurate diagnostics and runtime
-- ABE checks.
--
-- -gnatw.f turn on warnings for suspicious Subp'Access
--
-- The ABE mechanism treats '[Unrestricted_]Access of an entry,
-- operator, or subprogram as a pseudo invocation of the target.
-- As a result, it performs ABE diagnostics on the pseudo call.
--
-- -gnatw.F turn off warnings for suspicious Subp'Access
--
-- The complementary switch for -gnatw.f.
--
-- -gnatwl turn on warnings for elaboration problems
--
-- The ABE mechanism produces warnings on detected ABEs along with
-- a traceback showing the graph of the ABE.
--
-- -gnatwL turn off warnings for elaboration problems
--
-- The complementary switch for -gnatwl.
--------------------------
-- Debugging ABE issues --
--------------------------
-- * If the issue involves a call, ensure that the call is eligible for ABE
-- processing and receives a corresponding call marker. The routines of
-- interest are
--
-- Build_Call_Marker
-- Record_Elaboration_Scenario
--
-- * If the issue involves an arbitrary scenario, ensure that the scenario
-- is either recorded, or is successfully recognized while traversing a
-- body. The routines of interest are
--
-- Record_Elaboration_Scenario
-- Process_Conditional_ABE
-- Process_Guaranteed_ABE
-- Traverse_Body
--
-- * If the issue involves a circularity in the elaboration order, examine
-- the ALI files and look for the following encodings next to units:
--
-- E indicates a source Elaborate
--
-- EA indicates a source Elaborate_All
--
-- AD indicates an implicit Elaborate_All
--
-- ED indicates an implicit Elaborate
--
-- If possible, compare these encodings with those generated by the old
-- ABE mechanism. The routines of interest are
--
-- Ensure_Prior_Elaboration
-----------
-- Kinds --
-----------
-- The following type enumerates all possible elaboration phase statutes
type Elaboration_Phase_Status is
(Inactive,
-- The elaboration phase of the compiler has not started yet
Active,
-- The elaboration phase of the compiler is currently in progress
Completed);
-- The elaboration phase of the compiler has finished
Elaboration_Phase : Elaboration_Phase_Status := Inactive;
-- The status of the elaboration phase. Use routine Set_Elaboration_Phase
-- to alter its value.
-- The following type enumerates all subprogram body traversal modes
type Body_Traversal_Kind is
(Deep_Traversal,
-- The traversal examines the internals of a subprogram
No_Traversal);
-- The following type enumerates all operation modes
type Processing_Kind is
(Conditional_ABE_Processing,
-- The ABE mechanism detects and diagnoses conditional ABEs for library
-- and declaration-level scenarios.
Dynamic_Model_Processing,
-- The ABE mechanism installs conditional ABE checks for all eligible
-- scenarios when the dynamic model is in effect.
Guaranteed_ABE_Processing,
-- The ABE mechanism detects and diagnoses guaranteed ABEs caused by
-- calls, instantiations, and task activations.
Invocation_Construct_Processing,
-- The ABE mechanism locates all invocation constructs within the main
-- unit and utilizes them as roots of miltiple DFS traversals aimed at
-- detecting transitions from the main unit to an external unit.
Invocation_Body_Processing,
-- The ABE mechanism utilizes all library-level body scenarios as roots
-- of miltiple DFS traversals aimed at detecting transitions from the
-- main unit to an external unit.
Invocation_Spec_Processing,
-- The ABE mechanism utilizes all library-level spec scenarios as roots
-- of miltiple DFS traversals aimed at detecting transitions from the
-- main unit to an external unit.
SPARK_Processing,
-- The ABE mechanism detects and diagnoses violations of the SPARK
-- elaboration rules for SPARK-specific scenarios.
No_Processing);
-- The following type enumerates all possible scenario kinds
type Scenario_Kind is
(Access_Taken_Scenario,
-- An attribute reference which takes 'Access or 'Unrestricted_Access of
-- an entry, operator, or subprogram.
Call_Scenario,
-- A call which invokes an entry, operator, or subprogram
Derived_Type_Scenario,
-- A declaration of a derived type. This is a SPARK-specific scenario.
Instantiation_Scenario,
-- An instantiation which instantiates a generic package or subprogram.
-- This scenario is also subject to SPARK-specific rules.
Refined_State_Pragma_Scenario,
-- A Refined_State pragma. This is a SPARK-specific scenario.
Task_Activation_Scenario,
-- A call which activates objects of various task types
Variable_Assignment_Scenario,
-- An assignment statement which modifies the value of some variable
Variable_Reference_Scenario,
-- A reference to a variable. This is a SPARK-specific scenario.
No_Scenario);
-- The following type enumerates all possible consistency models of target
-- and scenario representations.
type Representation_Kind is
(Inconsistent_Representation,
-- A representation is said to be "inconsistent" when it is created from
-- a partially analyzed tree. In such an environment, certain attributes
-- such as a completing body may not be available yet.
Consistent_Representation,
-- A representation is said to be "consistent" when it is created from a
-- fully analyzed tree, where all attributes are available.
No_Representation);
-- The following type enumerates all possible target kinds
type Target_Kind is
(Generic_Target,
-- A generic unit being instantiated
Package_Target,
-- The package form of an instantiation
Subprogram_Target,
-- An entry, operator, or subprogram being invoked, or aliased through
-- 'Access or 'Unrestricted_Access.
Task_Target,
-- A task being activated by an activation call
Variable_Target,
-- A variable being updated through an assignment statement, or read
-- through a variable reference.
No_Target);
-----------
-- Types --
-----------
procedure Destroy (NE : in out Node_Or_Entity_Id);
pragma Inline (Destroy);
-- Destroy node or entity NE
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type;
pragma Inline (Hash);
-- Obtain the hash value of key NE
-- The following is a general purpose list for nodes and entities
package NE_List is new Doubly_Linked_Lists
(Element_Type => Node_Or_Entity_Id,
"=" => "=",
Destroy_Element => Destroy);
-- The following is a general purpose map which relates nodes and entities
-- to lists of nodes and entities.
package NE_List_Map is new Dynamic_Hash_Tables
(Key_Type => Node_Or_Entity_Id,
Value_Type => NE_List.Doubly_Linked_List,
No_Value => NE_List.Nil,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => NE_List.Destroy,
Hash => Hash);
-- The following is a general purpose membership set for nodes and entities
package NE_Set is new Membership_Sets
(Element_Type => Node_Or_Entity_Id,
"=" => "=",
Hash => Hash);
-- The following type captures relevant attributes which pertain to the
-- in state of the Processing phase.
type Processing_In_State is record
Processing : Processing_Kind := No_Processing;
-- Operation mode of the Processing phase. Once set, this value should
-- not be changed.
Representation : Representation_Kind := No_Representation;
-- Required level of scenario and target representation. Once set, this
-- value should not be changed.
Suppress_Checks : Boolean := False;
-- This flag is set when the Processing phase must not generate any ABE
-- checks.
Suppress_Implicit_Pragmas : Boolean := False;
-- This flag is set when the Processing phase must not generate any
-- implicit Elaborate[_All] pragmas.
Suppress_Info_Messages : Boolean := False;
-- This flag is set when the Processing phase must not emit any info
-- messages.
Suppress_Up_Level_Targets : Boolean := False;
-- This flag is set when the Processing phase must ignore up-level
-- targets.
Suppress_Warnings : Boolean := False;
-- This flag is set when the Processing phase must not emit any warnings
-- on elaboration problems.
Traversal : Body_Traversal_Kind := No_Traversal;
-- The subprogram body traversal mode. Once set, this value should not
-- be changed.
Within_Freezing_Actions : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from the actions of a freeze node.
Within_Generic : Boolean := False;
-- This flag is set when the Processing phase is currently within a
-- generic unit.
Within_Initial_Condition : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from an initial condition procedure.
Within_Partial_Finalization : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from a partial finalization procedure.
Within_Task_Body : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from a task body.
end record;
-- The following constants define the various operational states of the
-- Processing phase.
-- The conditional ABE state is used when processing scenarios that appear
-- at the declaration, instantiation, and library levels to detect errors
-- and install conditional ABE checks.
Conditional_ABE_State : constant Processing_In_State :=
(Processing => Conditional_ABE_Processing,
Representation => Consistent_Representation,
Traversal => Deep_Traversal,
others => False);
-- The dynamic model state is used to install conditional ABE checks when
-- switch -gnatE (dynamic elaboration checking mode enabled) is in effect.
Dynamic_Model_State : constant Processing_In_State :=
(Processing => Dynamic_Model_Processing,
Representation => Consistent_Representation,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => No_Traversal,
others => False);
-- The guaranteed ABE state is used when processing scenarios that appear
-- at the declaration, instantiation, and library levels to detect errors
-- and install guarateed ABE failures.
Guaranteed_ABE_State : constant Processing_In_State :=
(Processing => Guaranteed_ABE_Processing,
Representation => Inconsistent_Representation,
Suppress_Implicit_Pragmas => True,
Traversal => No_Traversal,
others => False);
-- The invocation body state is used when processing scenarios that appear
-- at the body library level to encode paths that start from elaboration
-- code and ultimately reach into external units.
Invocation_Body_State : constant Processing_In_State :=
(Processing => Invocation_Body_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The invocation construct state is used when processing constructs that
-- appear within the spec and body of the main unit and eventually reach
-- into external units.
Invocation_Construct_State : constant Processing_In_State :=
(Processing => Invocation_Construct_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The invocation spec state is used when processing scenarios that appear
-- at the spec library level to encode paths that start from elaboration
-- code and ultimately reach into external units.
Invocation_Spec_State : constant Processing_In_State :=
(Processing => Invocation_Spec_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The SPARK state is used when verying SPARK-specific semantics of certain
-- scenarios.
SPARK_State : constant Processing_In_State :=
(Processing => SPARK_Processing,
Representation => Consistent_Representation,
Traversal => No_Traversal,
others => False);
-- The following type identifies a scenario representation
type Scenario_Rep_Id is new Natural;
No_Scenario_Rep : constant Scenario_Rep_Id := Scenario_Rep_Id'First;
First_Scenario_Rep : constant Scenario_Rep_Id := No_Scenario_Rep + 1;
-- The following type identifies a target representation
type Target_Rep_Id is new Natural;
No_Target_Rep : constant Target_Rep_Id := Target_Rep_Id'First;
First_Target_Rep : constant Target_Rep_Id := No_Target_Rep + 1;
--------------
-- Services --
--------------
-- The following package keeps track of all active scenarios during a DFS
-- traversal.
package Active_Scenarios is
-----------
-- Types --
-----------
-- The following type defines the position within the active scenario
-- stack.
type Active_Scenario_Pos is new Natural;
---------------------
-- Data structures --
---------------------
-- The following table stores all active scenarios in a DFS traversal.
-- This table must be maintained in a FIFO fashion.
package Active_Scenario_Stack is new Table.Table
(Table_Index_Type => Active_Scenario_Pos,
Table_Component_Type => Node_Id,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 200,
Table_Name => "Active_Scenario_Stack");
---------
-- API --
---------
procedure Output_Active_Scenarios
(Error_Nod : Node_Id;
In_State : Processing_In_State);
pragma Inline (Output_Active_Scenarios);
-- Output the contents of the active scenario stack from earliest to
-- latest to supplement an earlier error emitted for node Error_Nod.
-- In_State denotes the current state of the Processing phase.
procedure Pop_Active_Scenario (N : Node_Id);
pragma Inline (Pop_Active_Scenario);
-- Pop the top of the scenario stack. A check is made to ensure that the
-- scenario being removed is the same as N.
procedure Push_Active_Scenario (N : Node_Id);
pragma Inline (Push_Active_Scenario);
-- Push scenario N on top of the scenario stack
function Root_Scenario return Node_Id;
pragma Inline (Root_Scenario);
-- Return the scenario which started a DFS traversal
end Active_Scenarios;
use Active_Scenarios;
-- The following package provides the main entry point for task activation
-- processing.
package Activation_Processor is
-----------
-- Types --
-----------
type Activation_Processor_Ptr is access procedure
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
-- Reference to a procedure that takes all attributes of an activation
-- and performs a desired action. Call is the activation call. Call_Rep
-- is the representation of the call. Obj_Id is the task object being
-- activated. Obj_Rep is the representation of the object. Task_Typ is
-- the task type whose body is being activated. Task_Rep denotes the
-- representation of the task type. In_State is the current state of
-- the Processing phase.
---------
-- API --
---------
procedure Process_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Processor : Activation_Processor_Ptr;
In_State : Processing_In_State);
-- Find all task objects activated by activation call Call and invoke
-- Processor on them. Call_Rep denotes the representation of the call.
-- In_State is the current state of the Processing phase.
end Activation_Processor;
use Activation_Processor;
-- The following package profides functionality for traversing subprogram
-- bodies in DFS manner and processing of eligible scenarios within.
package Body_Processor is
-----------
-- Types --
-----------
type Scenario_Predicate_Ptr is access function
(N : Node_Id) return Boolean;
-- Reference to a function which determines whether arbitrary node N
-- denotes a suitable scenario for processing.
type Scenario_Processor_Ptr is access procedure
(N : Node_Id; In_State : Processing_In_State);
-- Reference to a procedure which processes scenario N. In_State is the
-- current state of the Processing phase.
---------
-- API --
---------
procedure Traverse_Body
(N : Node_Id;
Requires_Processing : Scenario_Predicate_Ptr;
Processor : Scenario_Processor_Ptr;
In_State : Processing_In_State);
pragma Inline (Traverse_Body);
-- Traverse the declarations and handled statements of subprogram body
-- N, looking for scenarios that satisfy predicate Requires_Processing.
-- Routine Processor is invoked for each such scenario.
procedure Reset_Traversed_Bodies;
pragma Inline (Reset_Traversed_Bodies);
-- Reset the visited status of all subprogram bodies that have already
-- been processed by routine Traverse_Body.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Body_Processor;
pragma Inline (Finalize_Body_Processor);
-- Finalize all internal data structures
procedure Initialize_Body_Processor;
pragma Inline (Initialize_Body_Processor);
-- Initialize all internal data structures
end Body_Processor;
use Body_Processor;
-- The following package provides functionality for installing ABE-related
-- checks and failures.
package Check_Installer is
---------
-- API --
---------
function Check_Or_Failure_Generation_OK return Boolean;
pragma Inline (Check_Or_Failure_Generation_OK);
-- Determine whether a conditional ABE check or guaranteed ABE failure
-- can be generated.
procedure Install_Dynamic_ABE_Checks;
pragma Inline (Install_Dynamic_ABE_Checks);
-- Install conditional ABE checks for all saved scenarios when the
-- dynamic model is in effect.
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target. If the check is installed, disable the elaboration checks of
-- scenario Disable.
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target. If the check is installed, disable the elaboration checks of
-- target Disable.
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Scenario_ABE_Failure);
-- Install a guaranteed ABE failure for scenario N with target Targ_Id.
-- Targ_Rep denotes the representation of the target. If the failure is
-- installed, disable the elaboration checks of scenario Disable.
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Failure);
-- Install a guaranteed ABE failure for scenario N with target Targ_Id.
-- Targ_Rep denotes the representation of the target. If the failure is
-- installed, disable the elaboration checks of target Disable.
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Unit_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated. If the check is installed, disable
-- the elaboration checks of scenario Disable.
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Unit_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated. If the check is installed, disable
-- the elaboration checks of target Disable.
end Check_Installer;
use Check_Installer;
-- The following package provides the main entry point for conditional ABE
-- checks and diagnostics.
package Conditional_ABE_Processor is
---------
-- API --
---------
procedure Check_Conditional_ABE_Scenarios
(Iter : in out NE_Set.Iterator);
pragma Inline (Check_Conditional_ABE_Scenarios);
-- Perform conditional ABE checks and diagnostics for all scenarios
-- available through iterator Iter.
procedure Process_Conditional_ABE
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE);
-- Perform conditional ABE checks and diagnostics for scenario N.
-- In_State denotes the current state of the Processing phase.
end Conditional_ABE_Processor;
use Conditional_ABE_Processor;
-- The following package provides functionality to emit errors, information
-- messages, and warnings.
package Diagnostics is
---------
-- API --
---------
procedure Elab_Msg_NE
(Msg : String;
N : Node_Id;
Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Elab_Msg_NE);
-- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary
-- node N and entity. If flag Info_Msg is set, the routine emits an
-- information message, otherwise it emits an error. If flag In_SPARK
-- is set, then string " in SPARK" is added to the end of the message.
procedure Info_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Info_Call);
-- Output information concerning call Call that invokes subprogram
-- Subp_Id. When flag Info_Msg is set, the routine emits an information
-- message, otherwise it emits an error. When flag In_SPARK is set, " in
-- SPARK" is added to the end of the message.
procedure Info_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Info_Instantiation);
-- Output information concerning instantiation Inst which instantiates
-- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an
-- information message, otherwise it emits an error. If flag In_SPARK
-- is set, then string " in SPARK" is added to the end of the message.
procedure Info_Variable_Reference
(Ref : Node_Id;
Var_Id : Entity_Id);
pragma Inline (Info_Variable_Reference);
-- Output information concerning reference Ref which mentions variable
-- Var_Id. The routine emits an error suffixed with " in SPARK".
end Diagnostics;
use Diagnostics;
-- The following package provides functionality to locate the early call
-- region of a subprogram body.
package Early_Call_Region_Processor is
---------
-- API --
---------
function Find_Early_Call_Region
(Body_Decl : Node_Id;
Assume_Elab_Body : Boolean := False;
Skip_Memoization : Boolean := False) return Node_Id;
pragma Inline (Find_Early_Call_Region);
-- Find the start of the early call region that belongs to subprogram
-- body Body_Decl as defined in SPARK RM 7.7. This routine finds the
-- early call region, memoizes it, and returns it, but this behavior
-- can be altered. Flag Assume_Elab_Body should be set when a package
-- spec may lack pragma Elaborate_Body, but the routine must still
-- examine that spec. Flag Skip_Memoization should be set when the
-- routine must avoid memoizing the region.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Early_Call_Region_Processor;
pragma Inline (Finalize_Early_Call_Region_Processor);
-- Finalize all internal data structures
procedure Initialize_Early_Call_Region_Processor;
pragma Inline (Initialize_Early_Call_Region_Processor);
-- Initialize all internal data structures
end Early_Call_Region_Processor;
use Early_Call_Region_Processor;
-- The following package provides access to the elaboration statuses of all
-- units withed by the main unit.
package Elaborated_Units is
---------
-- API --
---------
procedure Collect_Elaborated_Units;
pragma Inline (Collect_Elaborated_Units);
-- Save the elaboration statuses of all units withed by the main unit
procedure Ensure_Prior_Elaboration
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by either suggesting or installing an Elaborate[_All] pragma
-- denoted by Prag_Nam. N denotes the related scenario. In_State is the
-- current state of the Processing phase.
function Has_Prior_Elaboration
(Unit_Id : Entity_Id;
Context_OK : Boolean := False;
Elab_Body_OK : Boolean := False;
Same_Unit_OK : Boolean := False) return Boolean;
pragma Inline (Has_Prior_Elaboration);
-- Determine whether unit Unit_Id is elaborated prior to the main unit.
-- If flag Context_OK is set, the routine considers the following case
-- as valid prior elaboration:
--
-- * Unit_Id is in the elaboration context of the main unit
--
-- If flag Elab_Body_OK is set, the routine considers the following case
-- as valid prior elaboration:
--
-- * Unit_Id has pragma Elaborate_Body and is not the main unit
--
-- If flag Same_Unit_OK is set, the routine considers the following
-- cases as valid prior elaboration:
--
-- * Unit_Id is the main unit
--
-- * Unit_Id denotes the spec of the main unit body
procedure Meet_Elaboration_Requirement
(N : Node_Id;
Targ_Id : Entity_Id;
Req_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Meet_Elaboration_Requirement);
-- Determine whether elaboration requirement Req_Nam for scenario N with
-- target Targ_Id is met by the context of the main unit using the SPARK
-- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an
-- error if this is not the case. In_State denotes the current state of
-- the Processing phase.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Elaborated_Units;
pragma Inline (Finalize_Elaborated_Units);
-- Finalize all internal data structures
procedure Initialize_Elaborated_Units;
pragma Inline (Initialize_Elaborated_Units);
-- Initialize all internal data structures
end Elaborated_Units;
use Elaborated_Units;
-- The following package provides the main entry point for guaranteed ABE
-- checks and diagnostics.
package Guaranteed_ABE_Processor is
---------
-- API --
---------
procedure Process_Guaranteed_ABE
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE);
-- Perform guaranteed ABE checks and diagnostics for scenario N.
-- In_State is the current state of the Processing phase.
end Guaranteed_ABE_Processor;
use Guaranteed_ABE_Processor;
-- The following package provides access to the internal representation of
-- scenarios and targets.
package Internal_Representation is
-----------
-- Types --
-----------
-- The following type enumerates all possible Ghost mode kinds
type Extended_Ghost_Mode is
(Is_Ignored,
Is_Checked_Or_Not_Specified);
-- The following type enumerates all possible SPARK mode kinds
type Extended_SPARK_Mode is
(Is_On,
Is_Off_Or_Not_Specified);
--------------
-- Builders --
--------------
function Scenario_Representation_Of
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Id;
pragma Inline (Scenario_Representation_Of);
-- Obtain the id of elaboration scenario N's representation. The routine
-- constructs the representation if it is not available. In_State is the
-- current state of the Processing phase.
function Target_Representation_Of
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Id;
pragma Inline (Target_Representation_Of);
-- Obtain the id of elaboration target Id's representation. The routine
-- constructs the representation if it is not available. In_State is the
-- current state of the Processing phase.
-------------------------
-- Scenario attributes --
-------------------------
function Activated_Task_Objects
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List;
pragma Inline (Activated_Task_Objects);
-- For Task_Activation_Scenario S_Id, obtain the list of task objects
-- the scenario is activating.
function Activated_Task_Type (S_Id : Scenario_Rep_Id) return Entity_Id;
pragma Inline (Activated_Task_Type);
-- For Task_Activation_Scenario S_Id, obtain the currently activated
-- task type.
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id);
pragma Inline (Disable_Elaboration_Checks);
-- Disable elaboration checks of scenario S_Id
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Elaboration_Checks_OK);
-- Determine whether scenario S_Id may be subjected to elaboration
-- checks.
function Elaboration_Warnings_OK (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Elaboration_Warnings_OK);
-- Determine whether scenario S_Id may be subjected to elaboration
-- warnings.
function Ghost_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of);
-- Obtain the Ghost mode of scenario S_Id
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Is_Dispatching_Call);
-- For Call_Scenario S_Id, determine whether the call is dispatching
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Is_Read_Reference);
-- For Variable_Reference_Scenario S_Id, determine whether the reference
-- is a read.
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind;
pragma Inline (Kind);
-- Obtain the nature of scenario S_Id
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind;
pragma Inline (Level);
-- Obtain the enclosing level of scenario S_Id
procedure Set_Activated_Task_Objects
(S_Id : Scenario_Rep_Id;
Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Set_Activated_Task_Objects);
-- For Task_Activation_Scenario S_Id, set the list of task objects
-- activated by the scenario to Task_Objs.
procedure Set_Activated_Task_Type
(S_Id : Scenario_Rep_Id;
Task_Typ : Entity_Id);
pragma Inline (Set_Activated_Task_Type);
-- For Task_Activation_Scenario S_Id, set the currently activated task
-- type to Task_Typ.
function SPARK_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of);
-- Obtain the SPARK mode of scenario S_Id
function Target (S_Id : Scenario_Rep_Id) return Entity_Id;
pragma Inline (Target);
-- Obtain the target of scenario S_Id
-----------------------
-- Target attributes --
-----------------------
function Barrier_Body_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Barrier_Body_Declaration);
-- For Subprogram_Target T_Id, obtain the declaration of the barrier
-- function's body.
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Body_Declaration);
-- Obtain the declaration of the body which belongs to target T_Id
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id);
pragma Inline (Disable_Elaboration_Checks);
-- Disable elaboration checks of target T_Id
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Elaboration_Checks_OK);
-- Determine whether target T_Id may be subjected to elaboration checks
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Elaboration_Warnings_OK);
-- Determine whether target T_Id may be subjected to elaboration
-- warnings.
function Ghost_Mode_Of (T_Id : Target_Rep_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of);
-- Obtain the Ghost mode of target T_Id
function Kind (T_Id : Target_Rep_Id) return Target_Kind;
pragma Inline (Kind);
-- Obtain the nature of target T_Id
function SPARK_Mode_Of (T_Id : Target_Rep_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of);
-- Obtain the SPARK mode of target T_Id
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Spec_Declaration);
-- Obtain the declaration of the spec which belongs to target T_Id
function Unit (T_Id : Target_Rep_Id) return Entity_Id;
pragma Inline (Unit);
-- Obtain the unit where the target is defined
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Variable_Declaration);
-- For Variable_Target T_Id, obtain the declaration of the variable
-----------------
-- Maintenance --
-----------------
procedure Finalize_Internal_Representation;
pragma Inline (Finalize_Internal_Representation);
-- Finalize all internal data structures
procedure Initialize_Internal_Representation;
pragma Inline (Initialize_Internal_Representation);
-- Initialize all internal data structures
end Internal_Representation;
use Internal_Representation;
-- The following package provides functionality for recording pieces of the
-- invocation graph in the ALI file of the main unit.
package Invocation_Graph is
---------
-- API --
---------
procedure Record_Invocation_Graph;
pragma Inline (Record_Invocation_Graph);
-- Process all declaration, instantiation, and library level scenarios,
-- along with invocation construct within the spec and body of the main
-- unit to determine whether any of these reach into an external unit.
-- If such a path exists, encode in the ALI file of the main unit.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Invocation_Graph;
pragma Inline (Finalize_Invocation_Graph);
-- Finalize all internal data structures
procedure Initialize_Invocation_Graph;
pragma Inline (Initialize_Invocation_Graph);
-- Initialize all internal data structures
end Invocation_Graph;
use Invocation_Graph;
-- The following package stores scenarios
package Scenario_Storage is
---------
-- API --
---------
procedure Add_Declaration_Scenario (N : Node_Id);
pragma Inline (Add_Declaration_Scenario);
-- Save declaration level scenario N
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id);
pragma Inline (Add_Dynamic_ABE_Check_Scenario);
-- Save scenario N for conditional ABE check installation purposes when
-- the dynamic model is in effect.
procedure Add_Library_Body_Scenario (N : Node_Id);
pragma Inline (Add_Library_Body_Scenario);
-- Save library-level body scenario N
procedure Add_Library_Spec_Scenario (N : Node_Id);
pragma Inline (Add_Library_Spec_Scenario);
-- Save library-level spec scenario N
procedure Add_SPARK_Scenario (N : Node_Id);
pragma Inline (Add_SPARK_Scenario);
-- Save SPARK scenario N
procedure Delete_Scenario (N : Node_Id);
pragma Inline (Delete_Scenario);
-- Delete arbitrary scenario N
function Iterate_Declaration_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Declaration_Scenarios);
-- Obtain an iterator over all declaration level scenarios
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Dynamic_ABE_Check_Scenarios);
-- Obtain an iterator over all scenarios that require a conditional ABE
-- check when the dynamic model is in effect.
function Iterate_Library_Body_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Library_Body_Scenarios);
-- Obtain an iterator over all library level body scenarios
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Library_Spec_Scenarios);
-- Obtain an iterator over all library level spec scenarios
function Iterate_SPARK_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_SPARK_Scenarios);
-- Obtain an iterator over all SPARK scenarios
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id);
pragma Inline (Replace_Scenario);
-- Replace scenario Old_N with scenario New_N
-----------------
-- Maintenance --
-----------------
procedure Finalize_Scenario_Storage;
pragma Inline (Finalize_Scenario_Storage);
-- Finalize all internal data structures
procedure Initialize_Scenario_Storage;
pragma Inline (Initialize_Scenario_Storage);
-- Initialize all internal data structures
end Scenario_Storage;
use Scenario_Storage;
-- The following package provides various semantic predicates
package Semantics is
---------
-- API --
---------
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Accept_Alternative_Proc);
-- Determine whether arbitrary entity Id denotes an internally generated
-- procedure which encapsulates the statements of an accept alternative.
function Is_Activation_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Activation_Proc);
-- Determine whether arbitrary entity Id denotes a runtime procedure in
-- charge with activating tasks.
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Ada_Semantic_Target);
-- Determine whether arbitrary entity Id denotes a source or internally
-- generated subprogram which emulates Ada semantics.
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Assertion_Pragma_Target);
-- Determine whether arbitrary entity Id denotes a procedure which
-- verifies the run-time semantics of an assertion pragma.
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Bodiless_Subprogram);
-- Determine whether subprogram Subp_Id will never have a body
function Is_Bridge_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Bridge_Target);
-- Determine whether arbitrary entity Id denotes a bridge target
function Is_Controlled_Proc
(Subp_Id : Entity_Id;
Subp_Nam : Name_Id) return Boolean;
pragma Inline (Is_Controlled_Proc);
-- Determine whether subprogram Subp_Id denotes controlled type
-- primitives Adjust, Finalize, or Initialize as denoted by name
-- Subp_Nam.
function Is_Default_Initial_Condition_Proc
(Id : Entity_Id) return Boolean;
pragma Inline (Is_Default_Initial_Condition_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine Default_Initial_Condition.
function Is_Finalizer_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Finalizer_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine _Finalizer.
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Initial_Condition_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine Initial_Condition.
function Is_Initialized (Obj_Decl : Node_Id) return Boolean;
pragma Inline (Is_Initialized);
-- Determine whether object declaration Obj_Decl is initialized
function Is_Invariant_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Invariant_Proc);
-- Determine whether arbitrary entity Id denotes an invariant procedure
function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean;
pragma Inline (Is_Non_Library_Level_Encapsulator);
-- Determine whether arbitrary node N is a non-library encapsulator
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Partial_Invariant_Proc);
-- Determine whether arbitrary entity Id denotes a partial invariant
-- procedure.
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean;
pragma Inline (Is_Preelaborated_Unit);
-- Determine whether arbitrary entity Id denotes a unit which is subject
-- to one of the following pragmas:
--
-- * Preelaborable
-- * Pure
-- * Remote_Call_Interface
-- * Remote_Types
-- * Shared_Passive
function Is_Protected_Entry (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Entry);
-- Determine whether arbitrary entity Id denotes a protected entry
function Is_Protected_Subp (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Subp);
-- Determine whether entity Id denotes a protected subprogram
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Body_Subp);
-- Determine whether entity Id denotes the protected or unprotected
-- version of a protected subprogram.
function Is_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Scenario);
-- Determine whether attribute node N denotes a scenario. The scenario
-- may not necessarily be eligible for ABE processing.
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_SPARK_Semantic_Target);
-- Determine whether arbitrary entity Id denotes a source or internally
-- generated subprogram which emulates SPARK semantics.
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean;
pragma Inline (Is_Subprogram_Inst);
-- Determine whether arbitrary entity Id denotes a subprogram instance
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Access_Taken);
-- Determine whether arbitrary node N denotes a suitable attribute for
-- ABE processing.
function Is_Suitable_Call (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Call);
-- Determine whether arbitrary node N denotes a suitable call for ABE
-- processing.
function Is_Suitable_Instantiation (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Instantiation);
-- Determine whether arbitrary node N is a suitable instantiation for
-- ABE processing.
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Derived_Type);
-- Determine whether arbitrary node N denotes a suitable derived type
-- declaration for ABE processing using the SPARK rules.
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Instantiation);
-- Determine whether arbitrary node N denotes a suitable instantiation
-- for ABE processing using the SPARK rules.
function Is_Suitable_SPARK_Refined_State_Pragma
(N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Refined_State_Pragma);
-- Determine whether arbitrary node N denotes a suitable Refined_State
-- pragma for ABE processing using the SPARK rules.
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Variable_Assignment);
-- Determine whether arbitrary node N denotes a suitable assignment for
-- ABE processing.
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Variable_Reference);
-- Determine whether arbitrary node N is a suitable variable reference
-- for ABE processing.
function Is_Task_Entry (Id : Entity_Id) return Boolean;
pragma Inline (Is_Task_Entry);
-- Determine whether arbitrary entity Id denotes a task entry
function Is_Up_Level_Target
(Targ_Decl : Node_Id;
In_State : Processing_In_State) return Boolean;
pragma Inline (Is_Up_Level_Target);
-- Determine whether the current root resides at the declaration level.
-- If this is the case, determine whether a target with by declaration
-- Target_Decl is within a context which encloses the current root or is
-- in a different unit. In_State is the current state of the Processing
-- phase.
end Semantics;
use Semantics;
-- The following package provides the main entry point for SPARK-related
-- checks and diagnostics.
package SPARK_Processor is
---------
-- API --
---------
procedure Check_SPARK_Model_In_Effect;
pragma Inline (Check_SPARK_Model_In_Effect);
-- Determine whether a suitable elaboration model is currently in effect
-- for verifying SPARK rules. Emit a warning if this is not the case.
procedure Check_SPARK_Scenarios;
pragma Inline (Check_SPARK_Scenarios);
-- Examine SPARK scenarios which are not necessarily executable during
-- elaboration, but still requires elaboration-related checks.
end SPARK_Processor;
use SPARK_Processor;
-----------------------
-- Local subprograms --
-----------------------
function Assignment_Target (Asmt : Node_Id) return Node_Id;
pragma Inline (Assignment_Target);
-- Obtain the target of assignment statement Asmt
function Call_Name (Call : Node_Id) return Node_Id;
pragma Inline (Call_Name);
-- Obtain the name of an entry, operator, or subprogram call Call
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id;
pragma Inline (Canonical_Subprogram);
-- Obtain the uniform canonical entity of subprogram Subp_Id
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id;
pragma Inline (Compilation_Unit);
-- Return the N_Compilation_Unit node of unit Unit_Id
function Elaboration_Phase_Active return Boolean;
pragma Inline (Elaboration_Phase_Active);
-- Determine whether the elaboration phase of the compilation has started
procedure Error_Preelaborated_Call (N : Node_Id);
-- Give an error or warning for a non-static/non-preelaborable call in a
-- preelaborated unit.
procedure Finalize_All_Data_Structures;
pragma Inline (Finalize_All_Data_Structures);
-- Destroy all internal data structures
function Find_Enclosing_Instance (N : Node_Id) return Node_Id;
pragma Inline (Find_Enclosing_Instance);
-- Find the declaration or body of the nearest expanded instance which
-- encloses arbitrary node N. Return Empty if no such instance exists.
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id;
pragma Inline (Find_Top_Unit);
-- Return the top unit which contains arbitrary node or entity N. The unit
-- is obtained by logically unwinding instantiations and subunits when N
-- resides within one.
function Find_Unit_Entity (N : Node_Id) return Entity_Id;
pragma Inline (Find_Unit_Entity);
-- Return the entity of unit N
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id;
pragma Inline (First_Formal_Type);
-- Return the type of subprogram Subp_Id's first formal parameter. If the
-- subprogram lacks formal parameters, return Empty.
function Has_Body (Pack_Decl : Node_Id) return Boolean;
pragma Inline (Has_Body);
-- Determine whether package declaration Pack_Decl has a corresponding body
-- or would eventually have one.
function In_External_Instance
(N : Node_Id;
Target_Decl : Node_Id) return Boolean;
pragma Inline (In_External_Instance);
-- Determine whether a target desctibed by its declaration Target_Decl
-- resides in a package instance which is external to scenario N.
function In_Main_Context (N : Node_Id) return Boolean;
pragma Inline (In_Main_Context);
-- Determine whether arbitrary node N appears within the main compilation
-- unit.
function In_Same_Context
(N1 : Node_Id;
N2 : Node_Id;
Nested_OK : Boolean := False) return Boolean;
pragma Inline (In_Same_Context);
-- Determine whether two arbitrary nodes N1 and N2 appear within the same
-- context ignoring enclosing library levels. Nested_OK should be set when
-- the context of N1 can enclose that of N2.
procedure Initialize_All_Data_Structures;
pragma Inline (Initialize_All_Data_Structures);
-- Create all internal data structures
function Instantiated_Generic (Inst : Node_Id) return Entity_Id;
pragma Inline (Instantiated_Generic);
-- Obtain the generic instantiated by instance Inst
function Is_Safe_Activation
(Call : Node_Id;
Task_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Activation);
-- Determine whether activation call Call which activates an object of a
-- task type described by representation Task_Rep is always ABE-safe.
function Is_Safe_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Call);
-- Determine whether call Call which invokes entry, operator, or subprogram
-- Subp_Id is always ABE-safe. Subp_Rep is the representation of the entry,
-- operator, or subprogram.
function Is_Safe_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Instantiation);
-- Determine whether instantiation Inst which instantiates generic Gen_Id
-- is always ABE-safe. Gen_Rep is the representation of the generic.
function Is_Same_Unit
(Unit_1 : Entity_Id;
Unit_2 : Entity_Id) return Boolean;
pragma Inline (Is_Same_Unit);
-- Determine whether entities Unit_1 and Unit_2 denote the same unit
function Main_Unit_Entity return Entity_Id;
pragma Inline (Main_Unit_Entity);
-- Return the entity of the main unit
function Non_Private_View (Typ : Entity_Id) return Entity_Id;
pragma Inline (Non_Private_View);
-- Return the full view of private type Typ if available, otherwise return
-- type Typ.
function Scenario (N : Node_Id) return Node_Id;
pragma Inline (Scenario);
-- Return the appropriate scenario node for scenario N
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status);
pragma Inline (Set_Elaboration_Phase);
-- Change the status of the elaboration phase of the compiler to Status
procedure Spec_And_Body_From_Entity
(Id : Entity_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id);
pragma Inline (Spec_And_Body_From_Entity);
-- Given arbitrary entity Id representing a construct with a spec and body,
-- retrieve declaration of the spec in Spec_Decl and the declaration of the
-- body in Body_Decl.
procedure Spec_And_Body_From_Node
(N : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id);
pragma Inline (Spec_And_Body_From_Node);
-- Given arbitrary node N representing a construct with a spec and body,
-- retrieve declaration of the spec in Spec_Decl and the declaration of
-- the body in Body_Decl.
function Static_Elaboration_Checks return Boolean;
pragma Inline (Static_Elaboration_Checks);
-- Determine whether the static model is in effect
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id;
pragma Inline (Unit_Entity);
-- Return the entity of the initial declaration for unit Unit_Id
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id);
pragma Inline (Update_Elaboration_Scenario);
-- Update all relevant internal data structures when scenario Old_N is
-- transformed into scenario New_N by Atree.Rewrite.
----------------------
-- Active_Scenarios --
----------------------
package body Active_Scenarios is
-----------------------
-- Local subprograms --
-----------------------
procedure Output_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Access_Taken);
-- Emit a specific diagnostic message for 'Access attribute reference
-- Attr with representation Attr_Rep. The message is associated with
-- node Error_Nod.
procedure Output_Active_Scenario
(N : Node_Id;
Error_Nod : Node_Id;
In_State : Processing_In_State);
pragma Inline (Output_Active_Scenario);
-- Top level dispatcher for outputting a scenario. Emit a specific
-- diagnostic message for scenario N. The message is associated with
-- node Error_Nod. In_State is the current state of the Processing
-- phase.
procedure Output_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Call);
-- Emit a diagnostic message for call Call with representation Call_Rep.
-- The message is associated with node Error_Nod.
procedure Output_Header (Error_Nod : Node_Id);
pragma Inline (Output_Header);
-- Emit a specific diagnostic message for the unit of the root scenario.
-- The message is associated with node Error_Nod.
procedure Output_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Instantiation);
-- Emit a specific diagnostic message for instantiation Inst with
-- representation Inst_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Refined_State_Pragma);
-- Emit a specific diagnostic message for Refined_State pragma Prag
-- with representation Prag_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Task_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Task_Activation);
-- Emit a specific diagnostic message for activation call Call
-- with representation Call_Rep. The message is associated with
-- node Error_Nod.
procedure Output_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Variable_Assignment);
-- Emit a specific diagnostic message for assignment statement Asmt
-- with representation Asmt_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Variable_Reference);
-- Emit a specific diagnostic message for read reference Ref with
-- representation Ref_Rep. The message is associated with node
-- Error_Nod.
-------------------
-- Output_Access --
-------------------
procedure Output_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Subp_Id : constant Entity_Id := Target (Attr_Rep);
begin
Error_Msg_Name_1 := Attribute_Name (Attr);
Error_Msg_Sloc := Sloc (Attr);
Error_Msg_NE ("\\ % of & taken #", Error_Nod, Subp_Id);
end Output_Access_Taken;
----------------------------
-- Output_Active_Scenario --
----------------------------
procedure Output_Active_Scenario
(N : Node_Id;
Error_Nod : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- 'Access
if Is_Suitable_Access_Taken (Scen) then
Output_Access_Taken
(Attr => Scen,
Attr_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Output_Call
(Call => Scen,
Call_Rep => Scen_Rep,
Error_Nod => Error_Nod);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Output_Task_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Error_Nod => Error_Nod);
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Output_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Pragma Refined_State
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Output_Refined_State_Pragma
(Prag => Scen,
Prag_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Variable assignment
elsif Is_Suitable_Variable_Assignment (Scen) then
Output_Variable_Assignment
(Asmt => Scen,
Asmt_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Variable reference
elsif Is_Suitable_Variable_Reference (Scen) then
Output_Variable_Reference
(Ref => Scen,
Ref_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
end if;
end Output_Active_Scenario;
-----------------------------
-- Output_Active_Scenarios --
-----------------------------
procedure Output_Active_Scenarios
(Error_Nod : Node_Id;
In_State : Processing_In_State)
is
package Scenarios renames Active_Scenario_Stack;
Header_Posted : Boolean := False;
begin
-- Output the contents of the active scenario stack starting from the
-- bottom, or the least recent scenario.
for Index in Scenarios.First .. Scenarios.Last loop
if not Header_Posted then
Output_Header (Error_Nod);
Header_Posted := True;
end if;
Output_Active_Scenario
(N => Scenarios.Table (Index),
Error_Nod => Error_Nod,
In_State => In_State);
end loop;
end Output_Active_Scenarios;
-----------------
-- Output_Call --
-----------------
procedure Output_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
procedure Output_Accept_Alternative (Alt_Id : Entity_Id);
pragma Inline (Output_Accept_Alternative);
-- Emit a specific diagnostic message concerning accept alternative
-- with entity Alt_Id.
procedure Output_Call (Subp_Id : Entity_Id; Kind : String);
pragma Inline (Output_Call);
-- Emit a specific diagnostic message concerning a call of kind Kind
-- which invokes subprogram Subp_Id.
procedure Output_Type_Actions (Subp_Id : Entity_Id; Action : String);
pragma Inline (Output_Type_Actions);
-- Emit a specific diagnostic message concerning action Action of a
-- type performed by subprogram Subp_Id.
procedure Output_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String);
pragma Inline (Output_Verification_Call);
-- Emit a specific diagnostic message concerning the verification of
-- predicate Pred applied to related entity Id with kind Id_Kind.
-------------------------------
-- Output_Accept_Alternative --
-------------------------------
procedure Output_Accept_Alternative (Alt_Id : Entity_Id) is
Entry_Id : constant Entity_Id := Receiving_Entry (Alt_Id);
begin
pragma Assert (Present (Entry_Id));
Error_Msg_NE ("\\ entry & selected #", Error_Nod, Entry_Id);
end Output_Accept_Alternative;
-----------------
-- Output_Call --
-----------------
procedure Output_Call (Subp_Id : Entity_Id; Kind : String) is
begin
Error_Msg_NE ("\\ " & Kind & " & called #", Error_Nod, Subp_Id);
end Output_Call;
-------------------------
-- Output_Type_Actions --
-------------------------
procedure Output_Type_Actions
(Subp_Id : Entity_Id;
Action : String)
is
Typ : constant Entity_Id := First_Formal_Type (Subp_Id);
begin
pragma Assert (Present (Typ));
Error_Msg_NE
("\\ " & Action & " actions for type & #", Error_Nod, Typ);
end Output_Type_Actions;
------------------------------
-- Output_Verification_Call --
------------------------------
procedure Output_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String)
is
begin
pragma Assert (Present (Id));
Error_Msg_NE
("\\ " & Pred & " of " & Id_Kind & " & verified #",
Error_Nod, Id);
end Output_Verification_Call;
-- Local variables
Subp_Id : constant Entity_Id := Target (Call_Rep);
-- Start of processing for Output_Call
begin
Error_Msg_Sloc := Sloc (Call);
-- Accept alternative
if Is_Accept_Alternative_Proc (Subp_Id) then
Output_Accept_Alternative (Subp_Id);
-- Adjustment
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then
Output_Type_Actions (Subp_Id, "adjustment");
-- Default_Initial_Condition
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then
-- Only do output for a normal DIC procedure, since partial DIC
-- procedures are subsidiary to those.
if not Is_Partial_DIC_Procedure (Subp_Id) then
Output_Verification_Call
(Pred => "Default_Initial_Condition",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
end if;
-- Entries
elsif Is_Protected_Entry (Subp_Id) then
Output_Call (Subp_Id, "entry");
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select. A
-- task entry call appears in the stack of active scenarios for the
-- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and
-- nothing more.
elsif Is_Task_Entry (Subp_Id) then
null;
-- Finalization
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then
Output_Type_Actions (Subp_Id, "finalization");
-- Calls to _Finalizer procedures must not appear in the output
-- because this creates confusing noise.
elsif Is_Finalizer_Proc (Subp_Id) then
null;
-- Initial_Condition
elsif Is_Initial_Condition_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "Initial_Condition",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "package");
-- Initialization
elsif Is_Init_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Initialize)
then
Output_Type_Actions (Subp_Id, "initialization");
-- Invariant
elsif Is_Invariant_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "invariants",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Partial invariant calls must not appear in the output because this
-- creates confusing noise. Note that a partial invariant is always
-- invoked by the "full" invariant which is already placed on the
-- stack.
elsif Is_Partial_Invariant_Proc (Subp_Id) then
null;
-- Subprograms must come last because some of the previous cases fall
-- under this category.
elsif Ekind (Subp_Id) = E_Function then
Output_Call (Subp_Id, "function");
elsif Ekind (Subp_Id) = E_Procedure then
Output_Call (Subp_Id, "procedure");
else
pragma Assert (False);
return;
end if;
end Output_Call;
-------------------
-- Output_Header --
-------------------
procedure Output_Header (Error_Nod : Node_Id) is
Unit_Id : constant Entity_Id := Find_Top_Unit (Root_Scenario);
begin
if Ekind (Unit_Id) = E_Package then
Error_Msg_NE ("\\ spec of unit & elaborated", Error_Nod, Unit_Id);
elsif Ekind (Unit_Id) = E_Package_Body then
Error_Msg_NE ("\\ body of unit & elaborated", Error_Nod, Unit_Id);
else
Error_Msg_NE ("\\ in body of unit &", Error_Nod, Unit_Id);
end if;
end Output_Header;
--------------------------
-- Output_Instantiation --
--------------------------
procedure Output_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String);
pragma Inline (Output_Instantiation);
-- Emit a specific diagnostic message concerning an instantiation of
-- generic unit Gen_Id. Kind denotes the kind of the instantiation.
--------------------------
-- Output_Instantiation --
--------------------------
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String) is
begin
Error_Msg_NE
("\\ " & Kind & " & instantiated as & #", Error_Nod, Gen_Id);
end Output_Instantiation;
-- Local variables
Gen_Id : constant Entity_Id := Target (Inst_Rep);
-- Start of processing for Output_Instantiation
begin
Error_Msg_Node_2 := Defining_Entity (Inst);
Error_Msg_Sloc := Sloc (Inst);
if Nkind (Inst) = N_Function_Instantiation then
Output_Instantiation (Gen_Id, "function");
elsif Nkind (Inst) = N_Package_Instantiation then
Output_Instantiation (Gen_Id, "package");
elsif Nkind (Inst) = N_Procedure_Instantiation then
Output_Instantiation (Gen_Id, "procedure");
else
pragma Assert (False);
return;
end if;
end Output_Instantiation;
---------------------------------
-- Output_Refined_State_Pragma --
---------------------------------
procedure Output_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
pragma Unreferenced (Prag_Rep);
begin
Error_Msg_Sloc := Sloc (Prag);
Error_Msg_N ("\\ refinement constituents read #", Error_Nod);
end Output_Refined_State_Pragma;
----------------------------
-- Output_Task_Activation --
----------------------------
procedure Output_Task_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
pragma Unreferenced (Call_Rep);
function Find_Activator return Entity_Id;
-- Find the nearest enclosing construct which houses call Call
--------------------
-- Find_Activator --
--------------------
function Find_Activator return Entity_Id is
Par : Node_Id;
begin
-- Climb the parent chain looking for a package [body] or a
-- construct with a statement sequence.
Par := Parent (Call);
while Present (Par) loop
if Nkind (Par) in N_Package_Body | N_Package_Declaration then
return Defining_Entity (Par);
elsif Nkind (Par) = N_Handled_Sequence_Of_Statements then
return Defining_Entity (Parent (Par));
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Activator;
-- Local variables
Activator : constant Entity_Id := Find_Activator;
-- Start of processing for Output_Task_Activation
begin
pragma Assert (Present (Activator));
Error_Msg_NE ("\\ local tasks of & activated", Error_Nod, Activator);
end Output_Task_Activation;
--------------------------------
-- Output_Variable_Assignment --
--------------------------------
procedure Output_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Var_Id : constant Entity_Id := Target (Asmt_Rep);
begin
Error_Msg_Sloc := Sloc (Asmt);
Error_Msg_NE ("\\ variable & assigned #", Error_Nod, Var_Id);
end Output_Variable_Assignment;
-------------------------------
-- Output_Variable_Reference --
-------------------------------
procedure Output_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Var_Id : constant Entity_Id := Target (Ref_Rep);
begin
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_NE ("\\ variable & read #", Error_Nod, Var_Id);
end Output_Variable_Reference;
-------------------------
-- Pop_Active_Scenario --
-------------------------
procedure Pop_Active_Scenario (N : Node_Id) is
package Scenarios renames Active_Scenario_Stack;
Top : Node_Id renames Scenarios.Table (Scenarios.Last);
begin
pragma Assert (Top = N);
Scenarios.Decrement_Last;
end Pop_Active_Scenario;
--------------------------
-- Push_Active_Scenario --
--------------------------
procedure Push_Active_Scenario (N : Node_Id) is
begin
Active_Scenario_Stack.Append (N);
end Push_Active_Scenario;
-------------------
-- Root_Scenario --
-------------------
function Root_Scenario return Node_Id is
package Scenarios renames Active_Scenario_Stack;
begin
-- Ensure that the scenario stack has at least one active scenario in
-- it. The one at the bottom (index First) is the root scenario.
pragma Assert (Scenarios.Last >= Scenarios.First);
return Scenarios.Table (Scenarios.First);
end Root_Scenario;
end Active_Scenarios;
--------------------------
-- Activation_Processor --
--------------------------
package body Activation_Processor is
------------------------
-- Process_Activation --
------------------------
procedure Process_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Processor : Activation_Processor_Ptr;
In_State : Processing_In_State)
is
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id);
pragma Inline (Process_Task_Object);
-- Invoke Processor for task object Obj_Id of type Typ
procedure Process_Task_Objects
(Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Process_Task_Objects);
-- Invoke Processor for all task objects found in list Task_Objs
procedure Traverse_List
(List : List_Id;
Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Traverse_List);
-- Traverse declarative or statement list List while searching for
-- objects of a task type, or containing task components. If such an
-- object is found, first save it in list Task_Objs and then invoke
-- Processor on it.
-------------------------
-- Process_Task_Object --
-------------------------
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id) is
Root_Typ : constant Entity_Id :=
Non_Private_View (Root_Type (Typ));
Comp_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Root_Rep : Target_Rep_Id;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
if Is_Task_Type (Typ) then
Obj_Rep := Target_Representation_Of (Obj_Id, New_In_State);
Root_Rep := Target_Representation_Of (Root_Typ, New_In_State);
-- Warnings are suppressed when a prior scenario is already in
-- that mode, or when the object, activation call, or task type
-- have warnings suppressed. Update the state of the Processing
-- phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Call_Rep)
or else not Elaboration_Warnings_OK (Obj_Rep)
or else not Elaboration_Warnings_OK (Root_Rep);
-- Update the state of the Processing phase to indicate that
-- any further traversal is now within a task body.
New_In_State.Within_Task_Body := True;
-- Associate the current task type with the activation call
Set_Activated_Task_Type (Call_Rep, Root_Typ);
-- Process the activation of the current task object by calling
-- the supplied processor.
Processor.all
(Call => Call,
Call_Rep => Call_Rep,
Obj_Id => Obj_Id,
Obj_Rep => Obj_Rep,
Task_Typ => Root_Typ,
Task_Rep => Root_Rep,
In_State => New_In_State);
-- Reset the association between the current task and the
-- activtion call.
Set_Activated_Task_Type (Call_Rep, Empty);
-- Examine the component type when the object is an array
elsif Is_Array_Type (Typ) and then Has_Task (Root_Typ) then
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Component_Type (Typ));
-- Examine individual component types when the object is a record
elsif Is_Record_Type (Typ) and then Has_Task (Root_Typ) then
Comp_Id := First_Component (Typ);
while Present (Comp_Id) loop
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Etype (Comp_Id));
Next_Component (Comp_Id);
end loop;
end if;
end Process_Task_Object;
--------------------------
-- Process_Task_Objects --
--------------------------
procedure Process_Task_Objects
(Task_Objs : NE_List.Doubly_Linked_List)
is
Iter : NE_List.Iterator;
Obj_Id : Entity_Id;
begin
Iter := NE_List.Iterate (Task_Objs);
while NE_List.Has_Next (Iter) loop
NE_List.Next (Iter, Obj_Id);
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Etype (Obj_Id));
end loop;
end Process_Task_Objects;
-------------------
-- Traverse_List --
-------------------
procedure Traverse_List
(List : List_Id;
Task_Objs : NE_List.Doubly_Linked_List)
is
Item : Node_Id;
Item_Id : Entity_Id;
Item_Typ : Entity_Id;
begin
-- Examine the contents of the list looking for an object
-- declaration of a task type or one that contains a task
-- within.
Item := First (List);
while Present (Item) loop
if Nkind (Item) = N_Object_Declaration then
Item_Id := Defining_Entity (Item);
Item_Typ := Etype (Item_Id);
if Has_Task (Item_Typ) then
-- The object is either of a task type, or contains a
-- task component. Save it in the list of task objects
-- associated with the activation call.
NE_List.Append (Task_Objs, Item_Id);
Process_Task_Object
(Obj_Id => Item_Id,
Typ => Item_Typ);
end if;
end if;
Next (Item);
end loop;
end Traverse_List;
-- Local variables
Context : Node_Id;
Spec : Node_Id;
Task_Objs : NE_List.Doubly_Linked_List;
-- Start of processing for Process_Activation
begin
-- Nothing to do when the activation is a guaranteed ABE
if Is_Known_Guaranteed_ABE (Call) then
return;
end if;
Task_Objs := Activated_Task_Objects (Call_Rep);
-- The activation call has been processed at least once, and all
-- task objects have already been collected. Directly process the
-- objects without having to reexamine the context of the call.
if NE_List.Present (Task_Objs) then
Process_Task_Objects (Task_Objs);
-- Otherwise the activation call is being processed for the first
-- time. Collect all task objects in case the call is reprocessed
-- multiple times.
else
Task_Objs := NE_List.Create;
Set_Activated_Task_Objects (Call_Rep, Task_Objs);
-- Find the context of the activation call where all task objects
-- being activated are declared. This is usually the parent of the
-- call.
Context := Parent (Call);
-- Handle the case where the activation call appears within the
-- handled statements of a block or a body.
if Nkind (Context) = N_Handled_Sequence_Of_Statements then
Context := Parent (Context);
end if;
-- Process all task objects in both the spec and body when the
-- activation call appears in a package body.
if Nkind (Context) = N_Package_Body then
Spec :=
Specification
(Unit_Declaration_Node (Corresponding_Spec (Context)));
Traverse_List
(List => Visible_Declarations (Spec),
Task_Objs => Task_Objs);
Traverse_List
(List => Private_Declarations (Spec),
Task_Objs => Task_Objs);
Traverse_List
(List => Declarations (Context),
Task_Objs => Task_Objs);
-- Process all task objects in the spec when the activation call
-- appears in a package spec.
elsif Nkind (Context) = N_Package_Specification then
Traverse_List
(List => Visible_Declarations (Context),
Task_Objs => Task_Objs);
Traverse_List
(List => Private_Declarations (Context),
Task_Objs => Task_Objs);
-- Otherwise the context must be a block or a body. Process all
-- task objects found in the declarations.
else
pragma Assert
(Nkind (Context) in
N_Block_Statement | N_Entry_Body | N_Protected_Body |
N_Subprogram_Body | N_Task_Body);
Traverse_List
(List => Declarations (Context),
Task_Objs => Task_Objs);
end if;
end if;
end Process_Activation;
end Activation_Processor;
-----------------------
-- Assignment_Target --
-----------------------
function Assignment_Target (Asmt : Node_Id) return Node_Id is
Nam : Node_Id;
begin
Nam := Name (Asmt);
-- When the name denotes an array or record component, find the whole
-- object.
while Nkind (Nam) in
N_Explicit_Dereference | N_Indexed_Component |
N_Selected_Component | N_Slice
loop
Nam := Prefix (Nam);
end loop;
return Nam;
end Assignment_Target;
--------------------
-- Body_Processor --
--------------------
package body Body_Processor is
---------------------
-- Data structures --
---------------------
-- The following map relates scenario lists to subprogram bodies
Nested_Scenarios_Map : NE_List_Map.Dynamic_Hash_Table := NE_List_Map.Nil;
-- The following set contains all subprogram bodies that have been
-- processed by routine Traverse_Body.
Traversed_Bodies_Set : NE_Set.Membership_Set := NE_Set.Nil;
-----------------------
-- Local subprograms --
-----------------------
function Is_Traversed_Body (N : Node_Id) return Boolean;
pragma Inline (Is_Traversed_Body);
-- Determine whether subprogram body N has already been traversed
function Nested_Scenarios
(N : Node_Id) return NE_List.Doubly_Linked_List;
pragma Inline (Nested_Scenarios);
-- Obtain the list of scenarios associated with subprogram body N
procedure Set_Is_Traversed_Body (N : Node_Id);
pragma Inline (Set_Is_Traversed_Body);
-- Mark subprogram body N as traversed
procedure Set_Nested_Scenarios
(N : Node_Id;
Scenarios : NE_List.Doubly_Linked_List);
pragma Inline (Set_Nested_Scenarios);
-- Associate scenario list Scenarios with subprogram body N
-----------------------------
-- Finalize_Body_Processor --
-----------------------------
procedure Finalize_Body_Processor is
begin
NE_List_Map.Destroy (Nested_Scenarios_Map);
NE_Set.Destroy (Traversed_Bodies_Set);
end Finalize_Body_Processor;
-------------------------------
-- Initialize_Body_Processor --
-------------------------------
procedure Initialize_Body_Processor is
begin
Nested_Scenarios_Map := NE_List_Map.Create (250);
Traversed_Bodies_Set := NE_Set.Create (250);
end Initialize_Body_Processor;
-----------------------
-- Is_Traversed_Body --
-----------------------
function Is_Traversed_Body (N : Node_Id) return Boolean is
pragma Assert (Present (N));
begin
return NE_Set.Contains (Traversed_Bodies_Set, N);
end Is_Traversed_Body;
----------------------
-- Nested_Scenarios --
----------------------
function Nested_Scenarios
(N : Node_Id) return NE_List.Doubly_Linked_List
is
pragma Assert (Present (N));
pragma Assert (Nkind (N) = N_Subprogram_Body);
begin
return NE_List_Map.Get (Nested_Scenarios_Map, N);
end Nested_Scenarios;
----------------------------
-- Reset_Traversed_Bodies --
----------------------------
procedure Reset_Traversed_Bodies is
begin
NE_Set.Reset (Traversed_Bodies_Set);
end Reset_Traversed_Bodies;
---------------------------
-- Set_Is_Traversed_Body --
---------------------------
procedure Set_Is_Traversed_Body (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Traversed_Bodies_Set, N);
end Set_Is_Traversed_Body;
--------------------------
-- Set_Nested_Scenarios --
--------------------------
procedure Set_Nested_Scenarios
(N : Node_Id;
Scenarios : NE_List.Doubly_Linked_List)
is
pragma Assert (Present (N));
begin
NE_List_Map.Put (Nested_Scenarios_Map, N, Scenarios);
end Set_Nested_Scenarios;
-------------------
-- Traverse_Body --
-------------------
procedure Traverse_Body
(N : Node_Id;
Requires_Processing : Scenario_Predicate_Ptr;
Processor : Scenario_Processor_Ptr;
In_State : Processing_In_State)
is
Scenarios : NE_List.Doubly_Linked_List := NE_List.Nil;
-- The list of scenarios that appear within the declarations and
-- statement of subprogram body N. The variable is intentionally
-- global because Is_Potential_Scenario needs to populate it.
function In_Task_Body (Nod : Node_Id) return Boolean;
pragma Inline (In_Task_Body);
-- Determine whether arbitrary node Nod appears within a task body
function Is_Synchronous_Suspension_Call
(Nod : Node_Id) return Boolean;
pragma Inline (Is_Synchronous_Suspension_Call);
-- Determine whether arbitrary node Nod denotes a call to one of
-- these routines:
--
-- Ada.Synchronous_Barriers.Wait_For_Release
-- Ada.Synchronous_Task_Control.Suspend_Until_True
procedure Traverse_Collected_Scenarios;
pragma Inline (Traverse_Collected_Scenarios);
-- Traverse the already collected scenarios in list Scenarios by
-- invoking Processor on each individual one.
procedure Traverse_List (List : List_Id);
pragma Inline (Traverse_List);
-- Invoke Traverse_Potential_Scenarios on each node in list List
function Traverse_Potential_Scenario
(Scen : Node_Id) return Traverse_Result;
pragma Inline (Traverse_Potential_Scenario);
-- Determine whether arbitrary node Scen is a suitable scenario using
-- predicate Is_Scenario and traverse it by invoking Processor on it.
procedure Traverse_Potential_Scenarios is
new Traverse_Proc (Traverse_Potential_Scenario);
------------------
-- In_Task_Body --
------------------
function In_Task_Body (Nod : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a task body [procedure]
Par := Nod;
while Present (Par) loop
if Nkind (Par) = N_Task_Body then
return True;
elsif Nkind (Par) = N_Subprogram_Body
and then Is_Task_Body_Procedure (Par)
then
return True;
-- Prevent the search from going too far. Note that this test
-- shares nodes with the two cases above, and must come last.
elsif Is_Body_Or_Package_Declaration (Par) then
return False;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Task_Body;
------------------------------------
-- Is_Synchronous_Suspension_Call --
------------------------------------
function Is_Synchronous_Suspension_Call
(Nod : Node_Id) return Boolean
is
Subp_Id : Entity_Id;
begin
-- To qualify, the call must invoke one of the runtime routines
-- which perform synchronous suspension.
if Is_Suitable_Call (Nod) then
Subp_Id := Target (Nod);
return
Is_RTE (Subp_Id, RE_Suspend_Until_True)
or else
Is_RTE (Subp_Id, RE_Wait_For_Release);
end if;
return False;
end Is_Synchronous_Suspension_Call;
----------------------------------
-- Traverse_Collected_Scenarios --
----------------------------------
procedure Traverse_Collected_Scenarios is
Iter : NE_List.Iterator;
Scen : Node_Id;
begin
Iter := NE_List.Iterate (Scenarios);
while NE_List.Has_Next (Iter) loop
NE_List.Next (Iter, Scen);
-- The current scenario satisfies the input predicate, process
-- it.
if Requires_Processing.all (Scen) then
Processor.all (Scen, In_State);
end if;
end loop;
end Traverse_Collected_Scenarios;
-------------------
-- Traverse_List --
-------------------
procedure Traverse_List (List : List_Id) is
Scen : Node_Id;
begin
Scen := First (List);
while Present (Scen) loop
Traverse_Potential_Scenarios (Scen);
Next (Scen);
end loop;
end Traverse_List;
---------------------------------
-- Traverse_Potential_Scenario --
---------------------------------
function Traverse_Potential_Scenario
(Scen : Node_Id) return Traverse_Result
is
begin
-- Special cases
-- Skip constructs which do not have elaboration of their own and
-- need to be elaborated by other means such as invocation, task
-- activation, etc.
if Is_Non_Library_Level_Encapsulator (Scen) then
return Skip;
-- Terminate the traversal of a task body when encountering an
-- accept or select statement, and
--
-- * Entry calls during elaboration are not allowed. In this
-- case the accept or select statement will cause the task
-- to block at elaboration time because there are no entry
-- calls to unblock it.
--
-- or
--
-- * Switch -gnatd_a (stop elaboration checks on accept or
-- select statement) is in effect.
elsif (Debug_Flag_Underscore_A
or else Restriction_Active
(No_Entry_Calls_In_Elaboration_Code))
and then Nkind (Original_Node (Scen)) in
N_Accept_Statement | N_Selective_Accept
then
return Abandon;
-- Terminate the traversal of a task body when encountering a
-- suspension call, and
--
-- * Entry calls during elaboration are not allowed. In this
-- case the suspension call emulates an entry call and will
-- cause the task to block at elaboration time.
--
-- or
--
-- * Switch -gnatd_s (stop elaboration checks on synchronous
-- suspension) is in effect.
--
-- Note that the guard should not be checking the state of flag
-- Within_Task_Body because only suspension calls which appear
-- immediately within the statements of the task are supported.
-- Flag Within_Task_Body carries over to deeper levels of the
-- traversal.
elsif (Debug_Flag_Underscore_S
or else Restriction_Active
(No_Entry_Calls_In_Elaboration_Code))
and then Is_Synchronous_Suspension_Call (Scen)
and then In_Task_Body (Scen)
then
return Abandon;
-- Certain nodes carry semantic lists which act as repositories
-- until expansion transforms the node and relocates the contents.
-- Examine these lists in case expansion is disabled.
elsif Nkind (Scen) in N_And_Then | N_Or_Else then
Traverse_List (Actions (Scen));
elsif Nkind (Scen) in N_Elsif_Part | N_Iteration_Scheme then
Traverse_List (Condition_Actions (Scen));
elsif Nkind (Scen) = N_If_Expression then
Traverse_List (Then_Actions (Scen));
Traverse_List (Else_Actions (Scen));
elsif Nkind (Scen) in
N_Component_Association
| N_Iterated_Component_Association
| N_Iterated_Element_Association
then
Traverse_List (Loop_Actions (Scen));
-- General case
-- The current node satisfies the input predicate, process it
elsif Requires_Processing.all (Scen) then
Processor.all (Scen, In_State);
end if;
-- Save a general scenario regardless of whether it satisfies the
-- input predicate. This allows for quick subsequent traversals of
-- general scenarios, even with different predicates.
if Is_Suitable_Access_Taken (Scen)
or else Is_Suitable_Call (Scen)
or else Is_Suitable_Instantiation (Scen)
or else Is_Suitable_Variable_Assignment (Scen)
or else Is_Suitable_Variable_Reference (Scen)
then
NE_List.Append (Scenarios, Scen);
end if;
return OK;
end Traverse_Potential_Scenario;
-- Start of processing for Traverse_Body
begin
-- Nothing to do when the traversal is suppressed
if In_State.Traversal = No_Traversal then
return;
-- Nothing to do when there is no input
elsif No (N) then
return;
-- Nothing to do when the input is not a subprogram body
elsif Nkind (N) /= N_Subprogram_Body then
return;
-- Nothing to do if the subprogram body was already traversed
elsif Is_Traversed_Body (N) then
return;
end if;
-- Mark the subprogram body as traversed
Set_Is_Traversed_Body (N);
Scenarios := Nested_Scenarios (N);
-- The subprogram body has been traversed at least once, and all
-- scenarios that appear within its declarations and statements
-- have already been collected. Directly retraverse the scenarios
-- without having to retraverse the subprogram body subtree.
if NE_List.Present (Scenarios) then
Traverse_Collected_Scenarios;
-- Otherwise the subprogram body is being traversed for the first
-- time. Collect all scenarios that appear within its declarations
-- and statements in case the subprogram body has to be retraversed
-- multiple times.
else
Scenarios := NE_List.Create;
Set_Nested_Scenarios (N, Scenarios);
Traverse_List (Declarations (N));
Traverse_Potential_Scenarios (Handled_Statement_Sequence (N));
end if;
end Traverse_Body;
end Body_Processor;
-----------------------
-- Build_Call_Marker --
-----------------------
procedure Build_Call_Marker (N : Node_Id) is
function In_External_Context
(Call : Node_Id;
Subp_Id : Entity_Id) return Boolean;
pragma Inline (In_External_Context);
-- Determine whether entry, operator, or subprogram Subp_Id is external
-- to call Call which must reside within an instance.
function In_Premature_Context (Call : Node_Id) return Boolean;
pragma Inline (In_Premature_Context);
-- Determine whether call Call appears within a premature context
function Is_Default_Expression (Call : Node_Id) return Boolean;
pragma Inline (Is_Default_Expression);
-- Determine whether call Call acts as the expression of a defaulted
-- parameter within a source call.
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Generic_Formal_Subp);
-- Determine whether subprogram Subp_Id denotes a generic formal
-- subprogram which appears in the "prologue" of an instantiation.
-------------------------
-- In_External_Context --
-------------------------
function In_External_Context
(Call : Node_Id;
Subp_Id : Entity_Id) return Boolean
is
Spec_Decl : constant Entity_Id := Unit_Declaration_Node (Subp_Id);
Inst : Node_Id;
Inst_Body : Node_Id;
Inst_Spec : Node_Id;
begin
Inst := Find_Enclosing_Instance (Call);
-- The call appears within an instance
if Present (Inst) then
-- The call comes from the main unit and the target does not
if In_Extended_Main_Code_Unit (Call)
and then not In_Extended_Main_Code_Unit (Spec_Decl)
then
return True;
-- Otherwise the target declaration must not appear within the
-- instance spec or body.
else
Spec_And_Body_From_Node
(N => Inst,
Spec_Decl => Inst_Spec,
Body_Decl => Inst_Body);
return not In_Subtree
(N => Spec_Decl,
Root1 => Inst_Spec,
Root2 => Inst_Body);
end if;
end if;
return False;
end In_External_Context;
--------------------------
-- In_Premature_Context --
--------------------------
function In_Premature_Context (Call : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for premature contexts
Par := Parent (Call);
while Present (Par) loop
-- Aspect specifications and generic associations are premature
-- contexts because nested calls has not been relocated to their
-- final context.
if Nkind (Par) in N_Aspect_Specification | N_Generic_Association
then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Premature_Context;
---------------------------
-- Is_Default_Expression --
---------------------------
function Is_Default_Expression (Call : Node_Id) return Boolean is
Outer_Call : constant Node_Id := Parent (Call);
Outer_Nam : Node_Id;
begin
-- To qualify, the node must appear immediately within a source call
-- which invokes a source target.
if Nkind (Outer_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement
and then Comes_From_Source (Outer_Call)
then
Outer_Nam := Call_Name (Outer_Call);
return
Is_Entity_Name (Outer_Nam)
and then Present (Entity (Outer_Nam))
and then Is_Subprogram_Or_Entry (Entity (Outer_Nam))
and then Comes_From_Source (Entity (Outer_Nam));
end if;
return False;
end Is_Default_Expression;
----------------------------
-- Is_Generic_Formal_Subp --
----------------------------
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean is
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
Context : constant Node_Id := Parent (Subp_Decl);
begin
-- To qualify, the subprogram must rename a generic actual subprogram
-- where the enclosing context is an instantiation.
return
Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
and then not Comes_From_Source (Subp_Decl)
and then Nkind (Context) in N_Function_Specification
| N_Package_Specification
| N_Procedure_Specification
and then Present (Generic_Parent (Context));
end Is_Generic_Formal_Subp;
-- Local variables
Call_Nam : Node_Id;
Marker : Node_Id;
Subp_Id : Entity_Id;
-- Start of processing for Build_Call_Marker
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the call is being preanalyzed as the marker will
-- be inserted in the wrong place.
elsif Preanalysis_Active then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
-- Nothing to do when the input does not denote a call or a requeue
elsif Nkind (N) not in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement
| N_Requeue_Statement
then
return;
-- Nothing to do when the input denotes entry call or requeue statement,
-- and switch -gnatd_e (ignore entry calls and requeue statements for
-- elaboration) is in effect.
elsif Debug_Flag_Underscore_E
and then Nkind (N) in N_Entry_Call_Statement | N_Requeue_Statement
then
return;
-- Nothing to do when the call is analyzed/resolved too early within an
-- intermediate context. This check is saved for last because it incurs
-- a performance penalty.
elsif In_Premature_Context (N) then
return;
end if;
Call_Nam := Call_Name (N);
-- Nothing to do when the call is erroneous or left in a bad state
if not (Is_Entity_Name (Call_Nam)
and then Present (Entity (Call_Nam))
and then Is_Subprogram_Or_Entry (Entity (Call_Nam)))
then
return;
end if;
Subp_Id := Canonical_Subprogram (Entity (Call_Nam));
-- Nothing to do when the call invokes a generic formal subprogram and
-- switch -gnatd.G (ignore calls through generic formal parameters for
-- elaboration) is in effect. This check must be performed with the
-- direct target of the call to avoid the side effects of mapping
-- actuals to formals using renamings.
if Debug_Flag_Dot_GG
and then Is_Generic_Formal_Subp (Entity (Call_Nam))
then
return;
-- Nothing to do when the call appears within the expanded spec or
-- body of an instantiated generic, the call does not invoke a generic
-- formal subprogram, the target is external to the instance, and switch
-- -gnatdL (ignore external calls from instances for elaboration) is in
-- effect. This check must be performed with the direct target of the
-- call to avoid the side effects of mapping actuals to formals using
-- renamings.
elsif Debug_Flag_LL
and then not Is_Generic_Formal_Subp (Entity (Call_Nam))
and then In_External_Context
(Call => N,
Subp_Id => Subp_Id)
then
return;
-- Nothing to do when the call invokes an assertion pragma procedure
-- and switch -gnatd_p (ignore assertion pragmas for elaboration) is
-- in effect.
elsif Debug_Flag_Underscore_P
and then Is_Assertion_Pragma_Target (Subp_Id)
then
return;
-- Static expression functions require no ABE processing
elsif Is_Static_Function (Subp_Id) then
return;
-- Source calls to source targets are always considered because they
-- reflect the original call graph.
elsif Comes_From_Source (N) and then Comes_From_Source (Subp_Id) then
null;
-- A call to a source function which acts as the default expression in
-- another call requires special detection.
elsif Comes_From_Source (Subp_Id)
and then Nkind (N) = N_Function_Call
and then Is_Default_Expression (N)
then
null;
-- The target emulates Ada semantics
elsif Is_Ada_Semantic_Target (Subp_Id) then
null;
-- The target acts as a link between scenarios
elsif Is_Bridge_Target (Subp_Id) then
null;
-- The target emulates SPARK semantics
elsif Is_SPARK_Semantic_Target (Subp_Id) then
null;
-- Otherwise the call is not suitable for ABE processing. This prevents
-- the generation of call markers which will never play a role in ABE
-- diagnostics.
else
return;
end if;
-- At this point it is known that the call will play some role in ABE
-- checks and diagnostics. Create a corresponding call marker in case
-- the original call is heavily transformed by expansion later on.
Marker := Make_Call_Marker (Sloc (N));
-- Inherit the attributes of the original call
Set_Is_Declaration_Level_Node
(Marker, Find_Enclosing_Level (N) = Declaration_Level);
Set_Is_Dispatching_Call
(Marker,
Nkind (N) in N_Subprogram_Call
and then Present (Controlling_Argument (N)));
Set_Is_Elaboration_Checks_OK_Node
(Marker, Is_Elaboration_Checks_OK_Node (N));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Is_Elaboration_Warnings_OK_Node (N));
Set_Is_Ignored_Ghost_Node (Marker, Is_Ignored_Ghost_Node (N));
Set_Is_Source_Call (Marker, Comes_From_Source (N));
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N));
Set_Target (Marker, Subp_Id);
-- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
-- unchecked conversions are preelaborable.
if Ada_Version >= Ada_2022 then
Set_Is_Preelaborable_Call (Marker, Is_Preelaborable_Construct (N));
else
Set_Is_Preelaborable_Call (Marker, False);
end if;
-- The marker is inserted prior to the original call. This placement has
-- several desirable effects:
-- 1) The marker appears in the same context, in close proximity to
-- the call.
-- <marker>
-- <call>
-- 2) Inserting the marker prior to the call ensures that an ABE check
-- will take effect prior to the call.
-- <ABE check>
-- <marker>
-- <call>
-- 3) The above two properties are preserved even when the call is a
-- function which is subsequently relocated in order to capture its
-- result. Note that if the call is relocated to a new context, the
-- relocated call will receive a marker of its own.
-- <ABE check>
-- <maker>
-- Temp : ... := Func_Call ...;
-- ... Temp ...
-- The insertion must take place even when the call does not occur in
-- the main unit to keep the tree symmetric. This ensures that internal
-- name serialization is consistent in case the call marker causes the
-- tree to transform in some way.
Insert_Action (N, Marker);
-- The marker becomes the "corresponding" scenario for the call. Save
-- the marker for later processing by the ABE phase.
Record_Elaboration_Scenario (Marker);
end Build_Call_Marker;
-------------------------------------
-- Build_Variable_Reference_Marker --
-------------------------------------
procedure Build_Variable_Reference_Marker
(N : Node_Id;
Read : Boolean;
Write : Boolean)
is
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id;
pragma Inline (Ultimate_Variable);
-- Obtain the ultimate renamed variable of variable Var_Id
-----------------------
-- Ultimate_Variable --
-----------------------
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id is
pragma Assert (Ekind (Var_Id) = E_Variable);
Ren_Id : Entity_Id;
begin
Ren_Id := Var_Id;
while Present (Renamed_Object (Ren_Id))
and then Nkind (Renamed_Object (Ren_Id)) in N_Entity
loop
Ren_Id := Renamed_Object (Ren_Id);
end loop;
return Ren_Id;
end Ultimate_Variable;
-- Local variables
Var_Id : constant Entity_Id := Ultimate_Variable (Entity (N));
Marker : Node_Id;
-- Start of processing for Build_Variable_Reference_Marker
begin
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
if not Elaboration_Phase_Active then
return;
end if;
Marker := Make_Variable_Reference_Marker (Sloc (N));
-- Inherit the attributes of the original variable reference
Set_Is_Elaboration_Checks_OK_Node
(Marker, Is_Elaboration_Checks_OK_Node (N));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Is_Elaboration_Warnings_OK_Node (N));
Set_Is_Read (Marker, Read);
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N));
Set_Is_Write (Marker, Write);
Set_Target (Marker, Var_Id);
-- The marker is inserted prior to the original variable reference. The
-- insertion must take place even when the reference does not occur in
-- the main unit to keep the tree symmetric. This ensures that internal
-- name serialization is consistent in case the variable marker causes
-- the tree to transform in some way.
Insert_Action (N, Marker);
-- The marker becomes the "corresponding" scenario for the reference.
-- Save the marker for later processing for the ABE phase.
Record_Elaboration_Scenario (Marker);
end Build_Variable_Reference_Marker;
---------------
-- Call_Name --
---------------
function Call_Name (Call : Node_Id) return Node_Id is
Nam : Node_Id;
begin
Nam := Name (Call);
-- When the call invokes an entry family, the name appears as an indexed
-- component.
if Nkind (Nam) = N_Indexed_Component then
Nam := Prefix (Nam);
end if;
-- When the call employs the object.operation form, the name appears as
-- a selected component.
if Nkind (Nam) = N_Selected_Component then
Nam := Selector_Name (Nam);
end if;
return Nam;
end Call_Name;
--------------------------
-- Canonical_Subprogram --
--------------------------
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id is
Canon_Id : Entity_Id;
begin
Canon_Id := Subp_Id;
-- Use the original protected subprogram when dealing with one of the
-- specialized lock-manipulating versions.
if Is_Protected_Body_Subp (Canon_Id) then
Canon_Id := Protected_Subprogram (Canon_Id);
end if;
-- Obtain the original subprogram except when the subprogram is also
-- an instantiation. In this case the alias is the internally generated
-- subprogram which appears within the anonymous package created for the
-- instantiation, making it unuitable.
if not Is_Generic_Instance (Canon_Id) then
Canon_Id := Get_Renamed_Entity (Canon_Id);
end if;
return Canon_Id;
end Canonical_Subprogram;
---------------------------------
-- Check_Elaboration_Scenarios --
---------------------------------
procedure Check_Elaboration_Scenarios is
Iter : NE_Set.Iterator;
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
Finalize_All_Data_Structures;
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
Finalize_All_Data_Structures;
return;
end if;
-- Restore the original elaboration model which was in effect when the
-- scenarios were first recorded. The model may be specified by pragma
-- Elaboration_Checks which appears on the initial declaration of the
-- main unit.
Install_Elaboration_Model (Unit_Entity (Main_Unit_Entity));
-- Examine the context of the main unit and record all units with prior
-- elaboration with respect to it.
Collect_Elaborated_Units;
-- Examine all scenarios saved during the Recording phase applying the
-- Ada or SPARK elaboration rules in order to detect and diagnose ABE
-- issues, install conditional ABE checks, and ensure the elaboration
-- of units.
Iter := Iterate_Declaration_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
Iter := Iterate_Library_Body_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
Iter := Iterate_Library_Spec_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
-- Examine each SPARK scenario saved during the Recording phase which
-- is not necessarily executable during elaboration, but still requires
-- elaboration-related checks.
Check_SPARK_Scenarios;
-- Add conditional ABE checks for all scenarios that require one when
-- the dynamic model is in effect.
Install_Dynamic_ABE_Checks;
-- Examine all scenarios saved during the Recording phase along with
-- invocation constructs within the spec and body of the main unit.
-- Record the declarations and paths that reach into an external unit
-- in the ALI file of the main unit.
Record_Invocation_Graph;
-- Destroy all internal data structures and complete the elaboration
-- phase of the compiler.
Finalize_All_Data_Structures;
Set_Elaboration_Phase (Completed);
end Check_Elaboration_Scenarios;
---------------------
-- Check_Installer --
---------------------
package body Check_Installer is
-----------------------
-- Local subprograms --
-----------------------
function ABE_Check_Or_Failure_OK
(N : Node_Id;
Targ_Id : Entity_Id;
Unit_Id : Entity_Id) return Boolean;
pragma Inline (ABE_Check_Or_Failure_OK);
-- Determine whether a conditional ABE check or guaranteed ABE failure
-- can be installed for scenario N with target Targ_Id which resides in
-- unit Unit_Id.
function Insertion_Node (N : Node_Id) return Node_Id;
pragma Inline (Insertion_Node);
-- Obtain the proper insertion node of an ABE check or failure for
-- scenario N.
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id);
pragma Inline (Insert_ABE_Check_Or_Failure);
-- Insert conditional ABE check or guaranteed ABE failure Check prior to
-- scenario N.
procedure Install_Scenario_ABE_Check_Common
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check_Common);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target.
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id);
pragma Inline (Install_Scenario_ABE_Failure_Common);
-- Install a guaranteed ABE failure for scenario N
procedure Install_Unit_ABE_Check_Common
(N : Node_Id;
Unit_Id : Entity_Id);
pragma Inline (Install_Unit_ABE_Check_Common);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated.
-----------------------------
-- ABE_Check_Or_Failure_OK --
-----------------------------
function ABE_Check_Or_Failure_OK
(N : Node_Id;
Targ_Id : Entity_Id;
Unit_Id : Entity_Id) return Boolean
is
pragma Unreferenced (Targ_Id);
Ins_Node : constant Node_Id := Insertion_Node (N);
begin
if not Check_Or_Failure_Generation_OK then
return False;
-- Nothing to do when the scenario denots a compilation unit because
-- there is no executable environment at that level.
elsif Nkind (Parent (Ins_Node)) = N_Compilation_Unit then
return False;
-- An ABE check or failure is not needed when the target is defined
-- in a unit which is elaborated prior to the main unit. This check
-- must also consider the following cases:
--
-- * The unit of the target appears in the context of the main unit
--
-- * The unit of the target is subject to pragma Elaborate_Body. An
-- ABE check MUST NOT be generated because the unit is always
-- elaborated prior to the main unit.
--
-- * The unit of the target is the main unit. An ABE check MUST be
-- added in this case because a conditional ABE may be raised
-- depending on the flow of execution within the main unit (flag
-- Same_Unit_OK is False).
elsif Has_Prior_Elaboration
(Unit_Id => Unit_Id,
Context_OK => True,
Elab_Body_OK => True)
then
return False;
end if;
return True;
end ABE_Check_Or_Failure_OK;
------------------------------------
-- Check_Or_Failure_Generation_OK --
------------------------------------
function Check_Or_Failure_Generation_OK return Boolean is
begin
-- An ABE check or failure is not needed when the compilation will
-- not produce an executable.
if Serious_Errors_Detected > 0 then
return False;
-- An ABE check or failure must not be installed when compiling for
-- GNATprove because raise statements are not supported.
elsif GNATprove_Mode then
return False;
end if;
return True;
end Check_Or_Failure_Generation_OK;
--------------------
-- Insertion_Node --
--------------------
function Insertion_Node (N : Node_Id) return Node_Id is
begin
-- When the scenario denotes an instantiation, the proper insertion
-- node is the instance spec. This ensures that the generic actuals
-- will not be evaluated prior to a potential ABE.
if Nkind (N) in N_Generic_Instantiation
and then Present (Instance_Spec (N))
then
return Instance_Spec (N);
-- Otherwise the proper insertion node is the scenario itself
else
return N;
end if;
end Insertion_Node;
---------------------------------
-- Insert_ABE_Check_Or_Failure --
---------------------------------
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id) is
Ins_Nod : constant Node_Id := Insertion_Node (N);
Scop_Id : constant Entity_Id := Find_Enclosing_Scope (Ins_Nod);
begin
-- Install the nearest enclosing scope of the scenario as there must
-- be something on the scope stack.
Push_Scope (Scop_Id);
Insert_Action (Ins_Nod, Check);
Pop_Scope;
end Insert_ABE_Check_Or_Failure;
--------------------------------
-- Install_Dynamic_ABE_Checks --
--------------------------------
procedure Install_Dynamic_ABE_Checks is
Iter : NE_Set.Iterator;
N : Node_Id;
begin
if not Check_Or_Failure_Generation_OK then
return;
-- Nothing to do if the dynamic model is not in effect
elsif not Dynamic_Elaboration_Checks then
return;
end if;
-- Install a conditional ABE check for each saved scenario
Iter := Iterate_Dynamic_ABE_Check_Scenarios;
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
Process_Conditional_ABE
(N => N,
In_State => Dynamic_Model_State);
end loop;
end Install_Dynamic_ABE_Checks;
--------------------------------
-- Install_Scenario_ABE_Check --
--------------------------------
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id)
is
begin
-- Nothing to do when the scenario does not need an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Check_Common
(N => N,
Targ_Id => Targ_Id,
Targ_Rep => Targ_Rep);
end Install_Scenario_ABE_Check;
--------------------------------
-- Install_Scenario_ABE_Check --
--------------------------------
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id)
is
begin
-- Nothing to do when the scenario does not need an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Check_Common
(N => N,
Targ_Id => Targ_Id,
Targ_Rep => Targ_Rep);
end Install_Scenario_ABE_Check;
---------------------------------------
-- Install_Scenario_ABE_Check_Common --
---------------------------------------
procedure Install_Scenario_ABE_Check_Common
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id)
is
Targ_Body : constant Node_Id := Body_Declaration (Targ_Rep);
Targ_Decl : constant Node_Id := Spec_Declaration (Targ_Rep);
pragma Assert (Present (Targ_Body));
pragma Assert (Present (Targ_Decl));
procedure Build_Elaboration_Entity;
pragma Inline (Build_Elaboration_Entity);
-- Create a new elaboration flag for Targ_Id, insert it prior to
-- Targ_Decl, and set it after Targ_Body.
------------------------------
-- Build_Elaboration_Entity --
------------------------------
procedure Build_Elaboration_Entity is
Loc : constant Source_Ptr := Sloc (Targ_Id);
Flag_Id : Entity_Id;
begin
-- Nothing to do if the target has an elaboration flag
if Present (Elaboration_Entity (Targ_Id)) then
return;
end if;
-- Create the declaration of the elaboration flag. The name
-- carries a unique counter in case the name is overloaded.
Flag_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Targ_Id), 'E', -1));
Set_Elaboration_Entity (Targ_Id, Flag_Id);
Set_Elaboration_Entity_Required (Targ_Id);
Push_Scope (Scope (Targ_Id));
-- Generate:
-- Enn : Short_Integer := 0;
Insert_Action (Targ_Decl,
Make_Object_Declaration (Loc,
Defining_Identifier => Flag_Id,
Object_Definition =>
New_Occurrence_Of (Standard_Short_Integer, Loc),
Expression => Make_Integer_Literal (Loc, Uint_0)));
-- Generate:
-- Enn := 1;
Set_Elaboration_Flag (Targ_Body, Targ_Id);
Pop_Scope;
end Build_Elaboration_Entity;
-- Local variables
Loc : constant Source_Ptr := Sloc (N);
-- Start for processing for Install_Scenario_ABE_Check_Common
begin
-- Create an elaboration flag for the target when it does not have
-- one.
Build_Elaboration_Entity;
-- Generate:
-- if not Targ_Id'Elaborated then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Targ_Id, Loc),
Attribute_Name => Name_Elaborated)),
Reason => PE_Access_Before_Elaboration));
end Install_Scenario_ABE_Check_Common;
----------------------------------
-- Install_Scenario_ABE_Failure --
----------------------------------
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id)
is
begin
-- Nothing to do when the scenario does not require an ABE failure
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Failure_Common (N);
end Install_Scenario_ABE_Failure;
----------------------------------
-- Install_Scenario_ABE_Failure --
----------------------------------
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id)
is
begin
-- Nothing to do when the scenario does not require an ABE failure
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Failure_Common (N);
end Install_Scenario_ABE_Failure;
-----------------------------------------
-- Install_Scenario_ABE_Failure_Common --
-----------------------------------------
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
begin
-- Generate:
-- raise Program_Error with "access before elaboration";
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Reason => PE_Access_Before_Elaboration));
end Install_Scenario_ABE_Failure_Common;
----------------------------
-- Install_Unit_ABE_Check --
----------------------------
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Scenario_Rep_Id)
is
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Nothing to do when the scenario does not require an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Empty,
Unit_Id => Spec_Id)
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Unit_ABE_Check_Common
(N => N,
Unit_Id => Unit_Id);
end Install_Unit_ABE_Check;
----------------------------
-- Install_Unit_ABE_Check --
----------------------------
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Target_Rep_Id)
is
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Nothing to do when the scenario does not require an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Empty,
Unit_Id => Spec_Id)
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Unit_ABE_Check_Common
(N => N,
Unit_Id => Unit_Id);
end Install_Unit_ABE_Check;
-----------------------------------
-- Install_Unit_ABE_Check_Common --
-----------------------------------
procedure Install_Unit_ABE_Check_Common
(N : Node_Id;
Unit_Id : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Generate:
-- if not Spec_Id'Elaborated then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Spec_Id, Loc),
Attribute_Name => Name_Elaborated)),
Reason => PE_Access_Before_Elaboration));
end Install_Unit_ABE_Check_Common;
end Check_Installer;
----------------------
-- Compilation_Unit --
----------------------
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id is
Comp_Unit : Node_Id;
begin
Comp_Unit := Parent (Unit_Id);
-- Handle the case where a concurrent subunit is rewritten as a null
-- statement due to expansion activities.
if Nkind (Comp_Unit) = N_Null_Statement
and then Nkind (Original_Node (Comp_Unit)) in
N_Protected_Body | N_Task_Body
then
Comp_Unit := Parent (Comp_Unit);
pragma Assert (Nkind (Comp_Unit) = N_Subunit);
-- Otherwise use the declaration node of the unit
else
Comp_Unit := Parent (Unit_Declaration_Node (Unit_Id));
end if;
-- Handle the case where a subprogram instantiation which acts as a
-- compilation unit is expanded into an anonymous package that wraps
-- the instantiated subprogram.
if Nkind (Comp_Unit) = N_Package_Specification
and then Nkind (Original_Node (Parent (Comp_Unit))) in
N_Function_Instantiation | N_Procedure_Instantiation
then
Comp_Unit := Parent (Parent (Comp_Unit));
-- Handle the case where the compilation unit is a subunit
elsif Nkind (Comp_Unit) = N_Subunit then
Comp_Unit := Parent (Comp_Unit);
end if;
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
return Comp_Unit;
end Compilation_Unit;
-------------------------------
-- Conditional_ABE_Processor --
-------------------------------
package body Conditional_ABE_Processor is
-----------------------
-- Local subprograms --
-----------------------
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Conditional_ABE_Scenario);
-- Determine whether node N is a suitable scenario for conditional ABE
-- checks and diagnostics.
procedure Process_Conditional_ABE_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Access_Taken);
-- Perform ABE checks and diagnostics for attribute reference Attr with
-- representation Attr_Rep which takes 'Access of an entry, operator, or
-- subprogram. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Activation);
-- Perform common conditional ABE checks and diagnostics for activation
-- call Call which activates object Obj_Id of task type Task_Typ. Formal
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep denotes the representation of
-- the task type. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call);
-- Top-level dispatcher for processing of calls. Perform ABE checks and
-- diagnostics for call Call with representation Call_Rep. In_State is
-- the current state of the Processing phase.
procedure Process_Conditional_ABE_Call_Ada
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call_Ada);
-- Perform ABE checks and diagnostics for call Call which invokes entry,
-- operator, or subprogram Subp_Id using the Ada rules. Call_Rep denotes
-- the representation of the call. Subp_Rep denotes the representation
-- of the subprogram. In_State is the current state of the Processing
-- phase.
procedure Process_Conditional_ABE_Call_SPARK
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call_SPARK);
-- Perform ABE checks and diagnostics for call Call which invokes entry,
-- operator, or subprogram Subp_Id using the SPARK rules. Call_Rep is
-- the representation of the call. Subp_Rep denotes the representation
-- of the subprogram. In_State is the current state of the Processing
-- phase.
procedure Process_Conditional_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation);
-- Top-level dispatcher for processing of instantiations. Perform ABE
-- checks and diagnostics for instantiation Inst with representation
-- Inst_Rep. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Instantiation_Ada
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation_Ada);
-- Perform ABE checks and diagnostics for instantiation Inst of generic
-- Gen_Id using the Ada rules. Inst_Rep denotes the representation of
-- the instnace. Gen_Rep is the representation of the generic. In_State
-- is the current state of the Processing phase.
procedure Process_Conditional_ABE_Instantiation_SPARK
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation_SPARK);
-- Perform ABE checks and diagnostics for instantiation Inst of generic
-- Gen_Id using the SPARK rules. Inst_Rep denotes the representation of
-- the instnace. Gen_Rep is the representation of the generic. In_State
-- is the current state of the Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment);
-- Top-level dispatcher for processing of variable assignments. Perform
-- ABE checks and diagnostics for assignment Asmt with representation
-- Asmt_Rep. In_State denotes the current state of the Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment_Ada);
-- Perform ABE checks and diagnostics for assignment statement Asmt that
-- modifies the value of variable Var_Id using the Ada rules. Asmt_Rep
-- denotes the representation of the assignment. Var_Rep denotes the
-- representation of the variable. In_State is the current state of the
-- Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment_SPARK);
-- Perform ABE checks and diagnostics for assignment statement Asmt that
-- modifies the value of variable Var_Id using the SPARK rules. Asmt_Rep
-- denotes the representation of the assignment. Var_Rep denotes the
-- representation of the variable. In_State is the current state of the
-- Processing phase.
procedure Process_Conditional_ABE_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Reference);
-- Perform ABE checks and diagnostics for variable reference Ref with
-- representation Ref_Rep. In_State denotes the current state of the
-- Processing phase.
procedure Traverse_Conditional_ABE_Body
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Traverse_Conditional_ABE_Body);
-- Traverse subprogram body N looking for suitable scenarios that need
-- to be processed for conditional ABE checks and diagnostics. In_State
-- is the current state of the Processing phase.
-------------------------------------
-- Check_Conditional_ABE_Scenarios --
-------------------------------------
procedure Check_Conditional_ABE_Scenarios
(Iter : in out NE_Set.Iterator)
is
N : Node_Id;
begin
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
-- Reset the traversed status of all subprogram bodies because the
-- current conditional scenario acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Conditional_ABE
(N => N,
In_State => Conditional_ABE_State);
end loop;
end Check_Conditional_ABE_Scenarios;
---------------------------------
-- Is_Conditional_ABE_Scenario --
---------------------------------
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean is
begin
return
Is_Suitable_Access_Taken (N)
or else Is_Suitable_Call (N)
or else Is_Suitable_Instantiation (N)
or else Is_Suitable_Variable_Assignment (N)
or else Is_Suitable_Variable_Reference (N);
end Is_Conditional_ABE_Scenario;
-----------------------------
-- Process_Conditional_ABE --
-----------------------------
procedure Process_Conditional_ABE
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- 'Access
if Is_Suitable_Access_Taken (Scen) then
Process_Conditional_ABE_Access_Taken
(Attr => Scen,
Attr_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
-- Routine Build_Call_Marker creates call markers regardless of
-- whether the call occurs within the main unit or not. This way
-- the serialization of internal names is kept consistent. Only
-- call markers found within the main unit must be processed.
if In_Main_Context (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Conditional_ABE_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Processor => Process_Conditional_ABE_Activation'Access,
In_State => In_State);
end if;
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Conditional_ABE_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Variable assignments
elsif Is_Suitable_Variable_Assignment (Scen) then
Process_Conditional_ABE_Variable_Assignment
(Asmt => Scen,
Asmt_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Variable references
elsif Is_Suitable_Variable_Reference (Scen) then
-- Routine Build_Variable_Reference_Marker makes variable markers
-- regardless of whether the reference occurs within the main unit
-- or not. This way the serialization of internal names is kept
-- consistent. Only variable markers within the main unit must be
-- processed.
if In_Main_Context (Scen) then
Process_Conditional_ABE_Variable_Reference
(Ref => Scen,
Ref_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_Conditional_ABE;
------------------------------------------
-- Process_Conditional_ABE_Access_Taken --
------------------------------------------
procedure Process_Conditional_ABE_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id;
pragma Inline (Build_Access_Marker);
-- Create a suitable call marker which invokes subprogram Subp_Id
-------------------------
-- Build_Access_Marker --
-------------------------
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id is
Marker : Node_Id;
begin
Marker := Make_Call_Marker (Sloc (Attr));
-- Inherit relevant attributes from the attribute
Set_Target (Marker, Subp_Id);
Set_Is_Declaration_Level_Node
(Marker, Level (Attr_Rep) = Declaration_Level);
Set_Is_Dispatching_Call
(Marker, False);
Set_Is_Elaboration_Checks_OK_Node
(Marker, Elaboration_Checks_OK (Attr_Rep));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Elaboration_Warnings_OK (Attr_Rep));
Set_Is_Preelaborable_Call
(Marker, False);
Set_Is_Source_Call
(Marker, Comes_From_Source (Attr));
Set_Is_SPARK_Mode_On_Node
(Marker, SPARK_Mode_Of (Attr_Rep) = Is_On);
-- Partially insert the call marker into the tree by setting its
-- parent pointer.
Set_Parent (Marker, Attr);
return Marker;
end Build_Access_Marker;
-- Local variables
Root : constant Node_Id := Root_Scenario;
Subp_Id : constant Entity_Id := Target (Attr_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
-- Start of processing for Process_Conditional_ABE_Access
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Error_Msg_NE
("info: access to & during elaboration", Attr, Subp_Id);
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode or when the attribute or the target have warnings suppressed.
-- Update the state of the Processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Attr_Rep)
or else not Elaboration_Warnings_OK (Subp_Rep);
-- Do not emit any ABE diagnostics when the current or previous
-- scenario in this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Both the attribute and the corresponding subprogram body are in
-- the same unit. The body must appear prior to the root scenario
-- which started the recursive search. If this is not the case, then
-- there is a potential ABE if the access value is used to call the
-- subprogram. Emit a warning only when switch -gnatw.f (warnings on
-- suspicious 'Access) is in effect.
elsif Warn_On_Elab_Access
and then Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
and then Earlier_In_Extended_Unit (Root, Body_Decl)
then
Error_Msg_Name_1 := Attribute_Name (Attr);
Error_Msg_NE
("?.f?% attribute of & before body seen", Attr, Subp_Id);
Error_Msg_N ("\possible Program_Error on later references", Attr);
Output_Active_Scenarios (Attr, New_In_State);
end if;
-- Treat the attribute an immediate invocation of the target when
-- switch -gnatd.o (conservative elaboration order for indirect
-- calls) is in effect. This has the following desirable effects:
--
-- * Ensure that the unit with the corresponding body is elaborated
-- prior to the main unit.
--
-- * Perform conditional ABE checks and diagnostics
--
-- * Traverse the body of the target (if available)
if Debug_Flag_Dot_O then
Process_Conditional_ABE
(N => Build_Access_Marker (Subp_Id),
In_State => New_In_State);
-- Otherwise ensure that the unit with the corresponding body is
-- elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Attr,
Unit_Id => Unit (Subp_Rep),
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Access_Taken;
----------------------------------------
-- Process_Conditional_ABE_Activation --
----------------------------------------
procedure Process_Conditional_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Task_Typ);
Body_Decl : constant Node_Id := Body_Declaration (Task_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Node_Id := Unit (Task_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Obj_Rep)
and then Elaboration_Checks_OK (Task_Rep);
-- A run-time ABE check may be installed only when the object and the
-- task type have active elaboration checks, and both are not ignored
-- Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Error_Msg_NE
("info: activation of & during elaboration", Call, Obj_Id);
end if;
-- Nothing to do when the call activates a task whose type is defined
-- within an instance and switch -gnatd_i (ignore activations and
-- calls to instances for elaboration) is in effect.
if Debug_Flag_Underscore_I
and then In_External_Instance
(N => Call,
Target_Decl => Spec_Decl)
then
return;
-- Nothing to do when the activation is a guaranteed ABE
elsif Is_Known_Guaranteed_ABE (Call) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the task is in the same unit, but outside this context.
--
-- task type Task_Typ; -- task declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- T : Task_Typ;
-- begin
-- <activation call> -- activation site
-- end;
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
--
-- In the example above, the context of X is the declarative list of
-- Proc. The "elaboration" of X may reach the activation of T whose
-- body is defined outside of X's context. The task body is relevant
-- only when Proc is invoked, but this happens only during "normal"
-- elaboration, therefore the task body must not be considered if
-- this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => New_In_State)
then
return;
-- Nothing to do when the activation is ABE-safe
--
-- generic
-- package Gen is
-- task type Task_Typ;
-- end Gen;
--
-- package body Gen is
-- task body Task_Typ is
-- begin
-- ...
-- end Task_Typ;
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Nested is
-- package Inst is new Gen;
-- T : Inst.Task_Typ;
-- <activation call> -- safe activation
-- end Nested;
-- ...
elsif Is_Safe_Activation (Call, Task_Rep) then
-- Note that the task body must still be examined for any nested
-- scenarios.
null;
-- The activation call and the task body are both in the main unit
--
-- If the root scenario appears prior to the task body, then this is
-- a possible ABE with respect to the root scenario.
--
-- task type Task_Typ;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Pack is
-- T : Task_Typ;
-- end Pack; -- activation of T
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- task body Task_Typ is -- task body
-- ...
-- end Task_Typ;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The activation of T is a possible ABE for X, but
-- not for Y. Intalling an unconditional ABE raise prior to the
-- activation call would be wrong as it will fail for Y as well
-- but in Y's case the activation of T is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the activation occurs
-- in a partial finalization context because this action leads
-- to confusing noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise emit the ABE disgnostic
else
Error_Msg_Sloc := Sloc (Call);
Error_Msg_N
("??task & will be activated # before elaboration of its "
& "body", Obj_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Obj_Id);
Output_Active_Scenarios (Obj_Id, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- task body has been elaborated prior to the activation call.
if Check_OK then
Install_Scenario_ABE_Check
(N => Call,
Targ_Id => Defining_Entity (Spec_Decl),
Targ_Rep => Task_Rep,
Disable => Obj_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- task type Task_Typ;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Pack is
-- <ABE check>
-- T : Task_Typ;
-- end Pack; -- activation of T
-- ...
-- end A;
--
-- X : ... := A;
--
-- task body Task_Typ is
-- begin
-- External.Subp; -- imparts Elaborate_All
-- end Task_Typ;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the task body is not available in this compilation or
-- it resides in an external unit. Install a run-time ABE check to
-- verify that the task body has been elaborated prior to the
-- activation call when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Call,
Unit_Id => Unit_Id,
Disable => Obj_Rep);
end if;
-- Both the activation call and task type are subject to SPARK_Mode
-- On, this triggers the SPARK rules for task activation. Compared
-- to calls and instantiations, task activation in SPARK does not
-- require the presence of Elaborate[_All] pragmas in case the task
-- type is defined outside the main unit. This is because SPARK uses
-- a special policy which activates all tasks after the main unit has
-- finished its elaboration.
if SPARK_Mode_Of (Call_Rep) = Is_On
and then SPARK_Mode_Of (Task_Rep) = Is_On
then
null;
-- Otherwise the Ada rules are in effect. Ensure that the unit with
-- the task body is elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
Traverse_Conditional_ABE_Body
(N => Body_Decl,
In_State => New_In_State);
end Process_Conditional_ABE_Activation;
----------------------------------
-- Process_Conditional_ABE_Call --
----------------------------------
procedure Process_Conditional_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
function In_Initialization_Context (N : Node_Id) return Boolean;
pragma Inline (In_Initialization_Context);
-- Determine whether arbitrary node N appears within a type init
-- proc, primitive [Deep_]Initialize, or a block created for
-- initialization purposes.
function Is_Partial_Finalization_Proc
(Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Partial_Finalization_Proc);
-- Determine whether subprogram Subp_Id is a partial finalization
-- procedure.
-------------------------------
-- In_Initialization_Context --
-------------------------------
function In_Initialization_Context (N : Node_Id) return Boolean is
Par : Node_Id;
Spec_Id : Entity_Id;
begin
-- Climb the parent chain looking for initialization actions
Par := Parent (N);
while Present (Par) loop
-- A block may be part of the initialization actions of a
-- default initialized object.
if Nkind (Par) = N_Block_Statement
and then Is_Initialization_Block (Par)
then
return True;
-- A subprogram body may denote an initialization routine
elsif Nkind (Par) = N_Subprogram_Body then
Spec_Id := Unique_Defining_Entity (Par);
-- The current subprogram body denotes a type init proc or
-- primitive [Deep_]Initialize.
if Is_Init_Proc (Spec_Id)
or else Is_Controlled_Proc (Spec_Id, Name_Initialize)
or else Is_TSS (Spec_Id, TSS_Deep_Initialize)
then
return True;
end if;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Initialization_Context;
----------------------------------
-- Is_Partial_Finalization_Proc --
----------------------------------
function Is_Partial_Finalization_Proc
(Subp_Id : Entity_Id) return Boolean
is
begin
-- To qualify, the subprogram must denote a finalizer procedure
-- or primitive [Deep_]Finalize, and the call must appear within
-- an initialization context.
return
(Is_Controlled_Proc (Subp_Id, Name_Finalize)
or else Is_Finalizer_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Finalize))
and then In_Initialization_Context (Call);
end Is_Partial_Finalization_Proc;
-- Local variables
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Subp_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Call_Rep) = Is_On
and then SPARK_Mode_Of (Subp_Rep) = Is_On;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
-- Start of processing for Process_Conditional_ABE_Call
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Info_Call
(Call => Call,
Subp_Id => Subp_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- Check whether the invocation of an entry clashes with an existing
-- restriction. This check is relevant only when the processing was
-- started from some library-level scenario.
if Is_Protected_Entry (Subp_Id) then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
elsif Is_Task_Entry (Subp_Id) then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select.
return;
end if;
-- Nothing to do when the call invokes a target defined within an
-- instance and switch -gnatd_i (ignore activations and calls to
-- instances for elaboration) is in effect.
if Debug_Flag_Underscore_I
and then In_External_Instance
(N => Call,
Target_Decl => Subp_Decl)
then
return;
-- Nothing to do when the call is a guaranteed ABE
elsif Is_Known_Guaranteed_ABE (Call) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the target is in the same unit but outside this context.
--
-- function B ...; -- target declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- function B ... is
-- ...
-- end B;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach B which is
-- defined outside of X's context. B is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore B must not be considered if this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Subp_Decl,
In_State => New_In_State)
then
return;
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode, or the call or target have warnings suppressed. Update the
-- state of the Processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Call_Rep)
or else not Elaboration_Warnings_OK (Subp_Rep);
-- The call occurs in freezing actions context when a prior scenario
-- is already in that mode, or when the target is a subprogram whose
-- body has been generated as a freezing action. Update the state of
-- the Processing phase to reflect this.
New_In_State.Within_Freezing_Actions :=
New_In_State.Within_Freezing_Actions
or else (Present (Body_Decl)
and then Nkind (Parent (Body_Decl)) = N_Freeze_Entity);
-- The call occurs in an initial condition context when a prior
-- scenario is already in that mode, or when the target is an
-- Initial_Condition procedure. Update the state of the Processing
-- phase to reflect this.
New_In_State.Within_Initial_Condition :=
New_In_State.Within_Initial_Condition
or else Is_Initial_Condition_Proc (Subp_Id);
-- The call occurs in a partial finalization context when a prior
-- scenario is already in that mode, or when the target denotes a
-- [Deep_]Finalize primitive or a finalizer within an initialization
-- context. Update the state of the Processing phase to reflect this.
New_In_State.Within_Partial_Finalization :=
New_In_State.Within_Partial_Finalization
or else Is_Partial_Finalization_Proc (Subp_Id);
-- The SPARK rules are in effect. Note that -gnatd.v (enforce SPARK
-- elaboration rules in SPARK code) is intentionally not taken into
-- account here because Process_Conditional_ABE_Call_SPARK has two
-- separate modes of operation.
if SPARK_Rules_On then
Process_Conditional_ABE_Call_SPARK
(Call => Call,
Call_Rep => Call_Rep,
Subp_Id => Subp_Id,
Subp_Rep => Subp_Rep,
In_State => New_In_State);
-- Otherwise the Ada rules are in effect
else
Process_Conditional_ABE_Call_Ada
(Call => Call,
Call_Rep => Call_Rep,
Subp_Id => Subp_Id,
Subp_Rep => Subp_Rep,
In_State => New_In_State);
end if;
-- Inspect the target body (and barried function) for other suitable
-- elaboration scenarios.
Traverse_Conditional_ABE_Body
(N => Barrier_Body_Declaration (Subp_Rep),
In_State => New_In_State);
Traverse_Conditional_ABE_Body
(N => Body_Decl,
In_State => New_In_State);
end Process_Conditional_ABE_Call;
--------------------------------------
-- Process_Conditional_ABE_Call_Ada --
--------------------------------------
procedure Process_Conditional_ABE_Call_Ada
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Node_Id := Unit (Subp_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Call_Rep)
and then Elaboration_Checks_OK (Subp_Rep);
-- A run-time ABE check may be installed only when both the call
-- and the target have active elaboration checks, and both are not
-- ignored Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Nothing to do for an Ada dispatching call because there are no
-- ABE diagnostics for either models. ABE checks for the dynamic
-- model are handled by Install_Primitive_Elaboration_Check.
if Is_Dispatching_Call (Call_Rep) then
return;
-- Nothing to do when the call is ABE-safe
--
-- generic
-- function Gen ...;
--
-- function Gen ... is
-- begin
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- function Inst is new Gen;
-- X : ... := Inst; -- safe call
-- ...
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then
return;
-- The call and the target body are both in the main unit
--
-- If the root scenario appears prior to the target body, then this
-- is a possible ABE with respect to the root scenario.
--
-- function B ...;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- function B ... is -- target body
-- ...
-- end B;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The call to B from A is a possible ABE for X, but
-- not for Y. Installing an unconditional ABE raise prior to the
-- call to B would be wrong as it will fail for Y as well, but in
-- Y's case the call to B is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the call occurs in a
-- partial finalization context because this leads to confusing
-- noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise emit the ABE diagnostic
else
Error_Msg_NE
("??cannot call & before body seen", Call, Subp_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Call);
Output_Active_Scenarios (Call, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- target body has been elaborated prior to the call.
if Check_OK then
Install_Scenario_ABE_Check
(N => Call,
Targ_Id => Subp_Id,
Targ_Rep => Subp_Rep,
Disable => Call_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- function B ...;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- <ABE check>
-- return B;
-- ...
-- end A;
--
-- X : ... := A;
--
-- function B ... is
-- External.Subp; -- imparts Elaborate_All
-- end B;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the target body is not available in this compilation or
-- it resides in an external unit. Install a run-time ABE check to
-- verify that the target body has been elaborated prior to the call
-- site when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Call,
Unit_Id => Unit_Id,
Disable => Call_Rep);
end if;
-- Ensure that the unit with the target body is elaborated prior to
-- the main unit. The implicit Elaborate[_All] is generated only when
-- the call has elaboration checks enabled. This behavior parallels
-- that of the old ABE mechanism.
if Elaboration_Checks_OK (Call_Rep) then
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Call_Ada;
----------------------------------------
-- Process_Conditional_ABE_Call_SPARK --
----------------------------------------
procedure Process_Conditional_ABE_Call_SPARK
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call_Rep);
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Region : Node_Id;
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- The call and the target body are both in the main unit
if Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
and then Earlier_In_Extended_Unit (Call, Body_Decl)
then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the call occurs in a
-- freezing actions context because this leads to incorrect
-- diagnostics.
elsif In_State.Within_Freezing_Actions then
null;
-- Do not emit any ABE diagnostics when the call occurs in an
-- initial condition context because this leads to incorrect
-- diagnostics.
elsif In_State.Within_Initial_Condition then
null;
-- Do not emit any ABE diagnostics when the call occurs in a
-- partial finalization context because this leads to confusing
-- noise.
elsif In_State.Within_Partial_Finalization then
null;
-- Ensure that a call that textually precedes the subprogram body
-- it invokes appears within the early call region of the body.
--
-- IMPORTANT: This check must always be performed even when switch
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the static model cannot guarantee the absence
-- of elaboration issues when dispatching calls are involved.
else
Region := Find_Early_Call_Region (Body_Decl);
if Earlier_In_Extended_Unit (Call, Region) then
Error_Msg_NE
("call must appear within early call region of subprogram "
& "body & (SPARK RM 7.7(3))",
Call, Subp_Id);
Error_Msg_Sloc := Sloc (Region);
Error_Msg_N ("\region starts #", Call);
Error_Msg_Sloc := Sloc (Body_Decl);
Error_Msg_N ("\region ends #", Call);
Output_Active_Scenarios (Call, In_State);
end if;
end if;
end if;
-- A call to a source target or to a target which emulates Ada
-- or SPARK semantics imposes an Elaborate_All requirement on the
-- context of the main unit. Determine whether the context has a
-- pragma strong enough to meet the requirement.
--
-- IMPORTANT: This check must be performed only when switch -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is active because
-- the static model can ensure the prior elaboration of the unit
-- which contains a body by installing an implicit Elaborate[_All]
-- pragma.
if Debug_Flag_Dot_V then
if Comes_From_Source (Subp_Id)
or else Is_Ada_Semantic_Target (Subp_Id)
or else Is_SPARK_Semantic_Target (Subp_Id)
then
Meet_Elaboration_Requirement
(N => Call,
Targ_Id => Subp_Id,
Req_Nam => Name_Elaborate_All,
In_State => In_State);
end if;
-- Otherwise ensure that the unit with the target body is elaborated
-- prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit (Subp_Rep),
Prag_Nam => Name_Elaborate_All,
In_State => In_State);
end if;
end Process_Conditional_ABE_Call_SPARK;
-------------------------------------------
-- Process_Conditional_ABE_Instantiation --
-------------------------------------------
procedure Process_Conditional_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Inst_Rep) = Is_On
and then SPARK_Mode_Of (Gen_Rep) = Is_On;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Info_Instantiation
(Inst => Inst,
Gen_Id => Gen_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- Nothing to do when the instantiation is a guaranteed ABE
if Is_Known_Guaranteed_ABE (Inst) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the generic is in the same unit, but outside this
-- context.
--
-- generic
-- procedure Gen is ...; -- generic declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- procedure I is new Gen; -- instantiation site
-- ...
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- procedure Gen is
-- ...
-- end Gen;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach Gen which
-- appears outside of X's context. Gen is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore Gen must not be considered if this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Spec_Declaration (Gen_Rep),
In_State => New_In_State)
then
return;
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode, or when the instantiation has warnings suppressed. Update
-- the state of the processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Inst_Rep);
-- The SPARK rules are in effect
if SPARK_Rules_On then
Process_Conditional_ABE_Instantiation_SPARK
(Inst => Inst,
Inst_Rep => Inst_Rep,
Gen_Id => Gen_Id,
Gen_Rep => Gen_Rep,
In_State => New_In_State);
-- Otherwise the Ada rules are in effect, or SPARK code is allowed to
-- violate the SPARK rules.
else
Process_Conditional_ABE_Instantiation_Ada
(Inst => Inst,
Inst_Rep => Inst_Rep,
Gen_Id => Gen_Id,
Gen_Rep => Gen_Rep,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Instantiation;
-----------------------------------------------
-- Process_Conditional_ABE_Instantiation_Ada --
-----------------------------------------------
procedure Process_Conditional_ABE_Instantiation_Ada
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Entity_Id := Unit (Gen_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Inst_Rep)
and then Elaboration_Checks_OK (Gen_Rep);
-- A run-time ABE check may be installed only when both the instance
-- and the generic have active elaboration checks and both are not
-- ignored Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Nothing to do when the instantiation is ABE-safe
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- package body Gen is
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Inst is new Gen (ABE); -- safe instantiation
-- ...
if Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then
return;
-- The instantiation and the generic body are both in the main unit
--
-- If the root scenario appears prior to the generic body, then this
-- is a possible ABE with respect to the root scenario.
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Inst is new Gen; -- instantiation site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- package body Gen is -- generic body
-- ...
-- end Gen;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The instantiation of Gen is a possible ABE for X,
-- but not for Y. Installing an unconditional ABE raise prior to
-- the instance site would be wrong as it will fail for Y as well,
-- but in Y's case the instantiation of Gen is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the instantiation
-- occurs in partial finalization context because this leads
-- to unwanted noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise output the diagnostic
else
Error_Msg_NE
("??cannot instantiate & before body seen", Inst, Gen_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Inst);
Output_Active_Scenarios (Inst, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- generic body has been elaborated prior to the instantiation.
if Check_OK then
Install_Scenario_ABE_Check
(N => Inst,
Targ_Id => Gen_Id,
Targ_Rep => Gen_Rep,
Disable => Inst_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- <ABE check>
-- declare Inst is new Gen;
-- ...
-- end A;
--
-- X : ... := A;
--
-- package body Gen is
-- begin
-- External.Subp; -- imparts Elaborate_All
-- end Gen;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the generic body is not available in this compilation
-- or it resides in an external unit. Install a run-time ABE check
-- to verify that the generic body has been elaborated prior to the
-- instantiation when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Inst,
Unit_Id => Unit_Id,
Disable => Inst_Rep);
end if;
-- Ensure that the unit with the generic body is elaborated prior
-- to the main unit. No implicit pragma has to be generated if the
-- instantiation has elaboration checks suppressed. This behavior
-- parallels that of the old ABE mechanism.
if Elaboration_Checks_OK (Inst_Rep) then
Ensure_Prior_Elaboration
(N => Inst,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Instantiation_Ada;
-------------------------------------------------
-- Process_Conditional_ABE_Instantiation_SPARK --
-------------------------------------------------
procedure Process_Conditional_ABE_Instantiation_SPARK
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Inst_Rep);
Req_Nam : Name_Id;
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- A source instantiation imposes an Elaborate[_All] requirement
-- on the context of the main unit. Determine whether the context
-- has a pragma strong enough to meet the requirement. The check
-- is orthogonal to the ABE ramifications of the instantiation.
--
-- IMPORTANT: This check must be performed only when switch -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is active because
-- the static model can ensure the prior elaboration of the unit
-- which contains a body by installing an implicit Elaborate[_All]
-- pragma.
if Debug_Flag_Dot_V then
if Nkind (Inst) = N_Package_Instantiation then
Req_Nam := Name_Elaborate_All;
else
Req_Nam := Name_Elaborate;
end if;
Meet_Elaboration_Requirement
(N => Inst,
Targ_Id => Gen_Id,
Req_Nam => Req_Nam,
In_State => In_State);
-- Otherwise ensure that the unit with the target body is elaborated
-- prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Inst,
Unit_Id => Unit (Gen_Rep),
Prag_Nam => Name_Elaborate,
In_State => In_State);
end if;
end Process_Conditional_ABE_Instantiation_SPARK;
-------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment --
-------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Var_Id : constant Entity_Id := Target (Asmt_Rep);
Var_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Var_Id, In_State);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Asmt_Rep) = Is_On
and then SPARK_Mode_Of (Var_Rep) = Is_On;
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Elab_Msg_NE
(Msg => "assignment to & during elaboration",
N => Asmt,
Id => Var_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- The SPARK rules are in effect. These rules are applied regardless
-- of whether switch -gnatd.v (enforce SPARK elaboration rules in
-- SPARK code) is in effect because the static model cannot ensure
-- safe assignment of variables.
if SPARK_Rules_On then
Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt => Asmt,
Asmt_Rep => Asmt_Rep,
Var_Id => Var_Id,
Var_Rep => Var_Rep,
In_State => In_State);
-- Otherwise the Ada rules are in effect
else
Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt => Asmt,
Asmt_Rep => Asmt_Rep,
Var_Id => Var_Id,
Var_Rep => Var_Rep,
In_State => In_State);
end if;
end Process_Conditional_ABE_Variable_Assignment;
-----------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment_Ada --
-----------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Asmt_Rep);
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep);
Unit_Id : constant Entity_Id := Unit (Var_Rep);
begin
-- Emit a warning when an uninitialized variable declared in a
-- package spec without a pragma Elaborate_Body is initialized
-- by elaboration code within the corresponding body.
if Is_Elaboration_Warnings_OK_Id (Var_Id)
and then not Is_Initialized (Var_Decl)
and then not Has_Pragma_Elaborate_Body (Unit_Id)
then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if not In_State.Suppress_Warnings then
Error_Msg_NE
("??variable & can be accessed by clients before this "
& "initialization", Asmt, Var_Id);
Error_Msg_NE
("\add pragma ""Elaborate_Body"" to spec & to ensure proper "
& "initialization", Asmt, Unit_Id);
Output_Active_Scenarios (Asmt, In_State);
end if;
-- Generate an implicit Elaborate_Body in the spec
Set_Elaborate_Body_Desirable (Unit_Id);
end if;
end Process_Conditional_ABE_Variable_Assignment_Ada;
-------------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment_SPARK --
-------------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Asmt_Rep);
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep);
Unit_Id : constant Entity_Id := Unit (Var_Rep);
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- Do not emit any ABE diagnostics when a previous scenario in this
-- traversal has suppressed elaboration warnings.
if In_State.Suppress_Warnings then
null;
-- Emit an error when an initialized variable declared in a package
-- spec that is missing pragma Elaborate_Body is further modified by
-- elaboration code within the corresponding body.
elsif Is_Elaboration_Warnings_OK_Id (Var_Id)
and then Is_Initialized (Var_Decl)
and then not Has_Pragma_Elaborate_Body (Unit_Id)
then
Error_Msg_NE
("variable & modified by elaboration code in package body",
Asmt, Var_Id);
Error_Msg_NE
("\add pragma ""Elaborate_Body"" to spec & to ensure full "
& "initialization", Asmt, Unit_Id);
Output_Active_Scenarios (Asmt, In_State);
end if;
end Process_Conditional_ABE_Variable_Assignment_SPARK;
------------------------------------------------
-- Process_Conditional_ABE_Variable_Reference --
------------------------------------------------
procedure Process_Conditional_ABE_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Var_Id : constant Entity_Id := Target (Ref);
Var_Rep : Target_Rep_Id;
Unit_Id : Entity_Id;
begin
-- Nothing to do when the variable reference is not a read
if not Is_Read_Reference (Ref_Rep) then
return;
end if;
Var_Rep := Target_Representation_Of (Var_Id, In_State);
Unit_Id := Unit (Var_Rep);
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Elab_Msg_NE
(Msg => "read of variable & during elaboration",
N => Ref,
Id => Var_Id,
Info_Msg => True,
In_SPARK => True);
end if;
-- Nothing to do when the variable appears within the main unit
-- because diagnostics on reads are relevant only for external
-- variables.
if Is_Same_Unit (Unit_Id, Main_Unit_Entity) then
null;
-- Nothing to do when the variable is already initialized. Note that
-- the variable may be further modified by the external unit.
elsif Is_Initialized (Variable_Declaration (Var_Rep)) then
null;
-- Nothing to do when the external unit guarantees the initialization
-- of the variable by means of pragma Elaborate_Body.
elsif Has_Pragma_Elaborate_Body (Unit_Id) then
null;
-- A variable read imposes an Elaborate requirement on the context of
-- the main unit. Determine whether the context has a pragma strong
-- enough to meet the requirement.
else
Meet_Elaboration_Requirement
(N => Ref,
Targ_Id => Var_Id,
Req_Nam => Name_Elaborate,
In_State => In_State);
end if;
end Process_Conditional_ABE_Variable_Reference;
-----------------------------------
-- Traverse_Conditional_ABE_Body --
-----------------------------------
procedure Traverse_Conditional_ABE_Body
(N : Node_Id;
In_State : Processing_In_State)
is
begin
Traverse_Body
(N => N,
Requires_Processing => Is_Conditional_ABE_Scenario'Access,
Processor => Process_Conditional_ABE'Access,
In_State => In_State);
end Traverse_Conditional_ABE_Body;
end Conditional_ABE_Processor;
-------------
-- Destroy --
-------------
procedure Destroy (NE : in out Node_Or_Entity_Id) is
pragma Unreferenced (NE);
begin
null;
end Destroy;
-----------------
-- Diagnostics --
-----------------
package body Diagnostics is
-----------------
-- Elab_Msg_NE --
-----------------
procedure Elab_Msg_NE
(Msg : String;
N : Node_Id;
Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
function Prefix return String;
pragma Inline (Prefix);
-- Obtain the prefix of the message
function Suffix return String;
pragma Inline (Suffix);
-- Obtain the suffix of the message
------------
-- Prefix --
------------
function Prefix return String is
begin
if Info_Msg then
return "info: ";
else
return "";
end if;
end Prefix;
------------
-- Suffix --
------------
function Suffix return String is
begin
if In_SPARK then
return " in SPARK";
else
return "";
end if;
end Suffix;
-- Start of processing for Elab_Msg_NE
begin
Error_Msg_NE (Prefix & Msg & Suffix, N, Id);
end Elab_Msg_NE;
---------------
-- Info_Call --
---------------
procedure Info_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
procedure Info_Accept_Alternative;
pragma Inline (Info_Accept_Alternative);
-- Output information concerning an accept alternative
procedure Info_Simple_Call;
pragma Inline (Info_Simple_Call);
-- Output information concerning the call
procedure Info_Type_Actions (Action : String);
pragma Inline (Info_Type_Actions);
-- Output information concerning action Action of a type
procedure Info_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String);
pragma Inline (Info_Verification_Call);
-- Output information concerning the verification of predicate Pred
-- applied to related entity Id with kind Id_Kind.
-----------------------------
-- Info_Accept_Alternative --
-----------------------------
procedure Info_Accept_Alternative is
Entry_Id : constant Entity_Id := Receiving_Entry (Subp_Id);
pragma Assert (Present (Entry_Id));
begin
Elab_Msg_NE
(Msg => "accept for entry & during elaboration",
N => Call,
Id => Entry_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Accept_Alternative;
----------------------
-- Info_Simple_Call --
----------------------
procedure Info_Simple_Call is
begin
Elab_Msg_NE
(Msg => "call to & during elaboration",
N => Call,
Id => Subp_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Simple_Call;
-----------------------
-- Info_Type_Actions --
-----------------------
procedure Info_Type_Actions (Action : String) is
Typ : constant Entity_Id := First_Formal_Type (Subp_Id);
pragma Assert (Present (Typ));
begin
Elab_Msg_NE
(Msg => Action & " actions for type & during elaboration",
N => Call,
Id => Typ,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Type_Actions;
----------------------------
-- Info_Verification_Call --
----------------------------
procedure Info_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String)
is
pragma Assert (Present (Id));
begin
Elab_Msg_NE
(Msg =>
"verification of " & Pred & " of " & Id_Kind & " & during "
& "elaboration",
N => Call,
Id => Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Verification_Call;
-- Start of processing for Info_Call
begin
-- Do not output anything for targets defined in internal units
-- because this creates noise.
if not In_Internal_Unit (Subp_Id) then
-- Accept alternative
if Is_Accept_Alternative_Proc (Subp_Id) then
Info_Accept_Alternative;
-- Adjustment
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then
Info_Type_Actions ("adjustment");
-- Default_Initial_Condition
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "Default_Initial_Condition",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Entries
elsif Is_Protected_Entry (Subp_Id) then
Info_Simple_Call;
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select.
elsif Is_Task_Entry (Subp_Id) then
null;
-- Finalization
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then
Info_Type_Actions ("finalization");
-- Calls to _Finalizer procedures must not appear in the output
-- because this creates confusing noise.
elsif Is_Finalizer_Proc (Subp_Id) then
null;
-- Initial_Condition
elsif Is_Initial_Condition_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "Initial_Condition",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "package");
-- Initialization
elsif Is_Init_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Initialize)
then
Info_Type_Actions ("initialization");
-- Invariant
elsif Is_Invariant_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "invariants",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Partial invariant calls must not appear in the output because
-- this creates confusing noise.
elsif Is_Partial_Invariant_Proc (Subp_Id) then
null;
-- Subprograms must come last because some of the previous cases
-- fall under this category.
elsif Ekind (Subp_Id) = E_Function then
Info_Simple_Call;
elsif Ekind (Subp_Id) = E_Procedure then
Info_Simple_Call;
else
pragma Assert (False);
return;
end if;
end if;
end Info_Call;
------------------------
-- Info_Instantiation --
------------------------
procedure Info_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
begin
Elab_Msg_NE
(Msg => "instantiation of & during elaboration",
N => Inst,
Id => Gen_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Instantiation;
-----------------------------
-- Info_Variable_Reference --
-----------------------------
procedure Info_Variable_Reference
(Ref : Node_Id;
Var_Id : Entity_Id)
is
begin
if Is_Read (Ref) then
Elab_Msg_NE
(Msg => "read of variable & during elaboration",
N => Ref,
Id => Var_Id,
Info_Msg => False,
In_SPARK => True);
end if;
end Info_Variable_Reference;
end Diagnostics;
---------------------------------
-- Early_Call_Region_Processor --
---------------------------------
package body Early_Call_Region_Processor is
---------------------
-- Data structures --
---------------------
-- The following map relates early call regions to subprogram bodies
procedure Destroy (N : in out Node_Id);
-- Destroy node N
package ECR_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Node_Id,
No_Value => Empty,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
Early_Call_Regions_Map : ECR_Map.Dynamic_Hash_Table := ECR_Map.Nil;
-----------------------
-- Local subprograms --
-----------------------
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id;
pragma Inline (Early_Call_Region);
-- Obtain the early call region associated with entry or subprogram body
-- Body_Id.
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id);
pragma Inline (Set_Early_Call_Region);
-- Associate an early call region with begins at construct Start with
-- entry or subprogram body Body_Id.
-------------
-- Destroy --
-------------
procedure Destroy (N : in out Node_Id) is
pragma Unreferenced (N);
begin
null;
end Destroy;
-----------------------
-- Early_Call_Region --
-----------------------
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id is
pragma Assert (Present (Body_Id));
begin
return ECR_Map.Get (Early_Call_Regions_Map, Body_Id);
end Early_Call_Region;
------------------------------------------
-- Finalize_Early_Call_Region_Processor --
------------------------------------------
procedure Finalize_Early_Call_Region_Processor is
begin
ECR_Map.Destroy (Early_Call_Regions_Map);
end Finalize_Early_Call_Region_Processor;
----------------------------
-- Find_Early_Call_Region --
----------------------------
function Find_Early_Call_Region
(Body_Decl : Node_Id;
Assume_Elab_Body : Boolean := False;
Skip_Memoization : Boolean := False) return Node_Id
is
-- NOTE: The routines within Find_Early_Call_Region are intentionally
-- unnested to avoid deep indentation of code.
ECR_Found : exception;
-- This exception is raised when the early call region has been found
Start : Node_Id := Empty;
-- The start of the early call region. This variable is updated by
-- the various nested routines. Due to the use of exceptions, the
-- variable must be global to the nested routines.
-- The algorithm implemented in this routine attempts to find the
-- early call region of a subprogram body by inspecting constructs
-- in reverse declarative order, while navigating the tree. The
-- algorithm consists of an Inspection phase and Advancement phase.
-- The pseudocode is as follows:
--
-- loop
-- inspection phase
-- advancement phase
-- end loop
--
-- The infinite loop is terminated by raising exception ECR_Found.
-- The algorithm utilizes two pointers, Curr and Start, to represent
-- the current construct to inspect and the start of the early call
-- region.
--
-- IMPORTANT: The algorithm must maintain the following invariant at
-- all time for it to function properly:
--
-- A nested construct is entered only when it contains suitable
-- constructs.
--
-- This guarantees that leaving a nested or encapsulating construct
-- functions properly.
--
-- The Inspection phase determines whether the current construct is
-- non-preelaborable, and if it is, the algorithm terminates.
--
-- The Advancement phase walks the tree in reverse declarative order,
-- while entering and leaving nested and encapsulating constructs. It
-- may also terminate the elaborithm. There are several special cases
-- of advancement.
--
-- 1) General case:
--
-- <construct 1>
-- ...
-- <construct N-1> <- Curr
-- <construct N> <- Start
-- <subprogram body>
--
-- In the general case, a declarative or statement list is traversed
-- in reverse order where Curr is the lead pointer, and Start is the
-- last preelaborable construct.
--
-- 2) Entering handled bodies
--
-- package body Nested is <- Curr (2.3)
-- <declarations> <- Curr (2.2)
-- begin
-- <statements> <- Curr (2.1)
-- end Nested;
-- <construct> <- Start
--
-- In this case, the algorithm enters a handled body by starting from
-- the last statement (2.1), or the last declaration (2.2), or the
-- body is consumed (2.3) because it is empty and thus preelaborable.
--
-- 3) Entering package declarations
--
-- package Nested is <- Curr (2.3)
-- <visible declarations> <- Curr (2.2)
-- private
-- <private declarations> <- Curr (2.1)
-- end Nested;
-- <construct> <- Start
--
-- In this case, the algorithm enters a package declaration by
-- starting from the last private declaration (2.1), the last visible
-- declaration (2.2), or the package is consumed (2.3) because it is
-- empty and thus preelaborable.
--
-- 4) Transitioning from list to list of the same construct
--
-- Certain constructs have two eligible lists. The algorithm must
-- thus transition from the second to the first list when the second
-- list is exhausted.
--
-- declare <- Curr (4.2)
-- <declarations> <- Curr (4.1)
-- begin
-- <statements> <- Start
-- end;
--
-- In this case, the algorithm has exhausted the second list (the
-- statements in the example above), and continues with the last
-- declaration (4.1) or the construct is consumed (4.2) because it
-- contains only preelaborable code.
--
-- 5) Transitioning from list to construct
--
-- tack body Task is <- Curr (5.1)
-- <- Curr (Empty)
-- <construct 1> <- Start
--
-- In this case, the algorithm has exhausted a list, Curr is Empty,
-- and the owner of the list is consumed (5.1).
--
-- 6) Transitioning from unit to unit
--
-- A package body with a spec subject to pragma Elaborate_Body
-- extends the possible range of the early call region to the package
-- spec.
--
-- package Pack is <- Curr (6.3)
-- pragma Elaborate_Body; <- Curr (6.2)
-- <visible declarations> <- Curr (6.2)
-- private
-- <private declarations> <- Curr (6.1)
-- end Pack;
--
-- package body Pack is <- Curr, Start
--
-- In this case, the algorithm has reached a package body compilation
-- unit whose spec is subject to pragma Elaborate_Body, or the caller
-- of the algorithm has specified this behavior. This transition is
-- equivalent to 3).
--
-- 7) Transitioning from unit to termination
--
-- Reaching a compilation unit always terminates the algorithm as
-- there are no more lists to examine. This must take case 6) into
-- account.
--
-- 8) Transitioning from subunit to stub
--
-- package body Pack is separate; <- Curr (8.1)
--
-- separate (...)
-- package body Pack is <- Curr, Start
--
-- Reaching a subunit continues the search from the corresponding
-- stub (8.1).
procedure Advance (Curr : in out Node_Id);
pragma Inline (Advance);
-- Update the Curr and Start pointers depending on their location
-- in the tree to the next eligible construct. This routine raises
-- ECR_Found.
procedure Enter_Handled_Body (Curr : in out Node_Id);
pragma Inline (Enter_Handled_Body);
-- Update the Curr and Start pointers to enter a nested handled body
-- if applicable. This routine raises ECR_Found.
procedure Enter_Package_Declaration (Curr : in out Node_Id);
pragma Inline (Enter_Package_Declaration);
-- Update the Curr and Start pointers to enter a nested package spec
-- if applicable. This routine raises ECR_Found.
function Find_ECR (N : Node_Id) return Node_Id;
pragma Inline (Find_ECR);
-- Find an early call region starting from arbitrary node N
function Has_Suitable_Construct (List : List_Id) return Boolean;
pragma Inline (Has_Suitable_Construct);
-- Determine whether list List contains a suitable construct for
-- inclusion into an early call region.
procedure Include (N : Node_Id; Curr : out Node_Id);
pragma Inline (Include);
-- Update the Curr and Start pointers to include arbitrary construct
-- N in the early call region. This routine raises ECR_Found.
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean;
pragma Inline (Is_OK_Preelaborable_Construct);
-- Determine whether arbitrary node N denotes a preelaboration-safe
-- construct.
function Is_Suitable_Construct (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Construct);
-- Determine whether arbitrary node N denotes a suitable construct
-- for inclusion into the early call region.
function Previous_Suitable_Construct (N : Node_Id) return Node_Id;
pragma Inline (Previous_Suitable_Construct);
-- Return the previous node suitable for inclusion into the early
-- call region.
procedure Transition_Body_Declarations
(Bod : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Body_Declarations);
-- Update the Curr and Start pointers when construct Bod denotes a
-- block statement or a suitable body. This routine raises ECR_Found.
procedure Transition_Handled_Statements
(HSS : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Handled_Statements);
-- Update the Curr and Start pointers when node HSS denotes a handled
-- sequence of statements. This routine raises ECR_Found.
procedure Transition_Spec_Declarations
(Spec : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Spec_Declarations);
-- Update the Curr and Start pointers when construct Spec denotes
-- a concurrent definition or a package spec. This routine raises
-- ECR_Found.
procedure Transition_Unit (Unit : Node_Id; Curr : out Node_Id);
pragma Inline (Transition_Unit);
-- Update the Curr and Start pointers when node Unit denotes a
-- potential compilation unit. This routine raises ECR_Found.
-------------
-- Advance --
-------------
procedure Advance (Curr : in out Node_Id) is
Context : Node_Id;
begin
-- Curr denotes one of the following cases upon entry into this
-- routine:
--
-- * Empty - There is no current construct when a declarative or
-- a statement list has been exhausted. This does not indicate
-- that the early call region has been computed as it is still
-- possible to transition to another list.
--
-- * Encapsulator - The current construct wraps declarations
-- and/or statements. This indicates that the early call
-- region may extend within the nested construct.
--
-- * Preelaborable - The current construct is preelaborable
-- because Find_ECR would not invoke Advance if this was not
-- the case.
-- The current construct is an encapsulator or is preelaborable
if Present (Curr) then
-- Enter encapsulators by inspecting their declarations and/or
-- statements.
if Nkind (Curr) in N_Block_Statement | N_Package_Body then
Enter_Handled_Body (Curr);
elsif Nkind (Curr) = N_Package_Declaration then
Enter_Package_Declaration (Curr);
-- Early call regions have a property which can be exploited to
-- optimize the algorithm.
--
-- <preceding subprogram body>
-- <preelaborable construct 1>
-- ...
-- <preelaborable construct N>
-- <initiating subprogram body>
--
-- If a traversal initiated from a subprogram body reaches a
-- preceding subprogram body, then both bodies share the same
-- early call region.
--
-- The property results in the following desirable effects:
--
-- * If the preceding body already has an early call region,
-- then the initiating body can reuse it. This minimizes the
-- amount of processing performed by the algorithm.
--
-- * If the preceding body lack an early call region, then the
-- algorithm can compute the early call region, and reuse it
-- for the initiating body. This processing performs the same
-- amount of work, but has the beneficial effect of computing
-- the early call regions of all preceding bodies.
elsif Nkind (Curr) in N_Entry_Body | N_Subprogram_Body then
Start :=
Find_Early_Call_Region
(Body_Decl => Curr,
Assume_Elab_Body => Assume_Elab_Body,
Skip_Memoization => Skip_Memoization);
raise ECR_Found;
-- Otherwise current construct is preelaborable. Unpdate the
-- early call region to include it.
else
Include (Curr, Curr);
end if;
-- Otherwise the current construct is missing, indicating that the
-- current list has been exhausted. Depending on the context of
-- the list, several transitions are possible.
else
-- The invariant of the algorithm ensures that Curr and Start
-- are at the same level of nesting at the point of transition.
-- The algorithm can determine which list the traversal came
-- from by examining Start.
Context := Parent (Start);
-- Attempt the following transitions:
--
-- private declarations -> visible declarations
-- private declarations -> upper level
-- private declarations -> terminate
-- visible declarations -> upper level
-- visible declarations -> terminate
if Nkind (Context) in N_Package_Specification
| N_Protected_Definition
| N_Task_Definition
then
Transition_Spec_Declarations (Context, Curr);
-- Attempt the following transitions:
--
-- statements -> declarations
-- statements -> upper level
-- statements -> corresponding package spec (Elab_Body)
-- statements -> terminate
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
Transition_Handled_Statements (Context, Curr);
-- Attempt the following transitions:
--
-- declarations -> upper level
-- declarations -> corresponding package spec (Elab_Body)
-- declarations -> terminate
elsif Nkind (Context) in N_Block_Statement
| N_Entry_Body
| N_Package_Body
| N_Protected_Body
| N_Subprogram_Body
| N_Task_Body
then
Transition_Body_Declarations (Context, Curr);
-- Otherwise it is not possible to transition. Stop the search
-- because there are no more declarations or statements to
-- check.
else
raise ECR_Found;
end if;
end if;
end Advance;
--------------------------
-- Enter_Handled_Body --
--------------------------
procedure Enter_Handled_Body (Curr : in out Node_Id) is
Decls : constant List_Id := Declarations (Curr);
HSS : constant Node_Id := Handled_Statement_Sequence (Curr);
Stmts : List_Id := No_List;
begin
if Present (HSS) then
Stmts := Statements (HSS);
end if;
-- The handled body has a non-empty statement sequence. The
-- construct to inspect is the last statement.
if Has_Suitable_Construct (Stmts) then
Curr := Last (Stmts);
-- The handled body lacks statements, but has non-empty
-- declarations. The construct to inspect is the last declaration.
elsif Has_Suitable_Construct (Decls) then
Curr := Last (Decls);
-- Otherwise the handled body lacks both declarations and
-- statements. The construct to inspect is the node which precedes
-- the handled body. Update the early call region to include the
-- handled body.
else
Include (Curr, Curr);
end if;
end Enter_Handled_Body;
-------------------------------
-- Enter_Package_Declaration --
-------------------------------
procedure Enter_Package_Declaration (Curr : in out Node_Id) is
Pack_Spec : constant Node_Id := Specification (Curr);
Prv_Decls : constant List_Id := Private_Declarations (Pack_Spec);
Vis_Decls : constant List_Id := Visible_Declarations (Pack_Spec);
begin
-- The package has a non-empty private declarations. The construct
-- to inspect is the last private declaration.
if Has_Suitable_Construct (Prv_Decls) then
Curr := Last (Prv_Decls);
-- The package lacks private declarations, but has non-empty
-- visible declarations. In this case the construct to inspect
-- is the last visible declaration.
elsif Has_Suitable_Construct (Vis_Decls) then
Curr := Last (Vis_Decls);
-- Otherwise the package lacks any declarations. The construct
-- to inspect is the node which precedes the package. Update the
-- early call region to include the package declaration.
else
Include (Curr, Curr);
end if;
end Enter_Package_Declaration;
--------------
-- Find_ECR --
--------------
function Find_ECR (N : Node_Id) return Node_Id is
Curr : Node_Id;
begin
-- The early call region starts at N
Curr := Previous_Suitable_Construct (N);
Start := N;
-- Inspect each node in reverse declarative order while going in
-- and out of nested and enclosing constructs. Note that the only
-- way to terminate this infinite loop is to raise ECR_Found.
loop
-- The current construct is not preelaboration-safe. Terminate
-- the traversal.
if Present (Curr)
and then not Is_OK_Preelaborable_Construct (Curr)
then
raise ECR_Found;
end if;
-- Advance to the next suitable construct. This may terminate
-- the traversal by raising ECR_Found.
Advance (Curr);
end loop;
exception
when ECR_Found =>
return Start;
end Find_ECR;
----------------------------
-- Has_Suitable_Construct --
----------------------------
function Has_Suitable_Construct (List : List_Id) return Boolean is
Item : Node_Id;
begin
-- Examine the list in reverse declarative order, looking for a
-- suitable construct.
if Present (List) then
Item := Last (List);
while Present (Item) loop
if Is_Suitable_Construct (Item) then
return True;
end if;
Prev (Item);
end loop;
end if;
return False;
end Has_Suitable_Construct;
-------------
-- Include --
-------------
procedure Include (N : Node_Id; Curr : out Node_Id) is
begin
Start := N;
-- The input node is a compilation unit. This terminates the
-- search because there are no more lists to inspect and there are
-- no more enclosing constructs to climb up to. The transitions
-- are:
--
-- private declarations -> terminate
-- visible declarations -> terminate
-- statements -> terminate
-- declarations -> terminate
if Nkind (Parent (Start)) = N_Compilation_Unit then
raise ECR_Found;
-- Otherwise the input node is still within some list
else
Curr := Previous_Suitable_Construct (Start);
end if;
end Include;
-----------------------------------
-- Is_OK_Preelaborable_Construct --
-----------------------------------
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean is
begin
-- Assignment statements are acceptable as long as they were
-- produced by the ABE mechanism to update elaboration flags.
if Nkind (N) = N_Assignment_Statement then
return Is_Elaboration_Code (N);
-- Block statements are acceptable even though they directly
-- violate preelaborability. The intention is not to penalize
-- the early call region when a block contains only preelaborable
-- constructs.
--
-- declare
-- Val : constant Integer := 1;
-- begin
-- pragma Assert (Val = 1);
-- null;
-- end;
--
-- Note that the Advancement phase does enter blocks, and will
-- detect any non-preelaborable declarations or statements within.
elsif Nkind (N) = N_Block_Statement then
return True;
end if;
-- Otherwise the construct must be preelaborable. The check must
-- take the syntactic and semantic structure of the construct. DO
-- NOT use Is_Preelaborable_Construct here.
return not Is_Non_Preelaborable_Construct (N);
end Is_OK_Preelaborable_Construct;
---------------------------
-- Is_Suitable_Construct --
---------------------------
function Is_Suitable_Construct (N : Node_Id) return Boolean is
Context : constant Node_Id := Parent (N);
begin
-- An internally-generated statement sequence which contains only
-- a single null statement is not a suitable construct because it
-- is a byproduct of the parser. Such a null statement should be
-- excluded from the early call region because it carries the
-- source location of the "end" keyword, and may lead to confusing
-- diagnostics.
if Nkind (N) = N_Null_Statement
and then not Comes_From_Source (N)
and then Present (Context)
and then Nkind (Context) = N_Handled_Sequence_Of_Statements
then
return False;
-- Similarly, internally-generated objects and types may have
-- out-of-order source locations that confuse diagnostics, e.g.
-- source locations in the body for objects/types generated in
-- the spec.
elsif Nkind (N) in N_Full_Type_Declaration | N_Object_Declaration
and then not Comes_From_Source (N)
then
return False;
end if;
-- Otherwise only constructs which correspond to pure Ada
-- constructs are considered suitable.
case Nkind (N) is
when N_Call_Marker
| N_Freeze_Entity
| N_Freeze_Generic_Entity
| N_Implicit_Label_Declaration
| N_Itype_Reference
| N_Pop_Constraint_Error_Label
| N_Pop_Program_Error_Label
| N_Pop_Storage_Error_Label
| N_Push_Constraint_Error_Label
| N_Push_Program_Error_Label
| N_Push_Storage_Error_Label
| N_SCIL_Dispatch_Table_Tag_Init
| N_SCIL_Dispatching_Call
| N_SCIL_Membership_Test
| N_Variable_Reference_Marker
=>
return False;
when others =>
return True;
end case;
end Is_Suitable_Construct;
---------------------------------
-- Previous_Suitable_Construct --
---------------------------------
function Previous_Suitable_Construct (N : Node_Id) return Node_Id is
P : Node_Id;
begin
P := Prev (N);
while Present (P) and then not Is_Suitable_Construct (P) loop
Prev (P);
end loop;
return P;
end Previous_Suitable_Construct;
----------------------------------
-- Transition_Body_Declarations --
----------------------------------
procedure Transition_Body_Declarations
(Bod : Node_Id;
Curr : out Node_Id)
is
Decls : constant List_Id := Declarations (Bod);
begin
-- The search must come from the declarations of the body
pragma Assert
(Is_Non_Empty_List (Decls)
and then List_Containing (Start) = Decls);
-- The search finished inspecting the declarations. The construct
-- to inspect is the node which precedes the handled body, unless
-- the body is a compilation unit. The transitions are:
--
-- declarations -> upper level
-- declarations -> corresponding package spec (Elab_Body)
-- declarations -> terminate
Transition_Unit (Bod, Curr);
end Transition_Body_Declarations;
-----------------------------------
-- Transition_Handled_Statements --
-----------------------------------
procedure Transition_Handled_Statements
(HSS : Node_Id;
Curr : out Node_Id)
is
Bod : constant Node_Id := Parent (HSS);
Decls : constant List_Id := Declarations (Bod);
Stmts : constant List_Id := Statements (HSS);
begin
-- The search must come from the statements of certain bodies or
-- statements.
pragma Assert
(Nkind (Bod) in
N_Block_Statement |
N_Entry_Body |
N_Package_Body |
N_Protected_Body |
N_Subprogram_Body |
N_Task_Body);
-- The search must come from the statements of the handled
-- sequence.
pragma Assert
(Is_Non_Empty_List (Stmts)
and then List_Containing (Start) = Stmts);
-- The search finished inspecting the statements. The handled body
-- has non-empty declarations. The construct to inspect is the
-- last declaration. The transitions are:
--
-- statements -> declarations
if Has_Suitable_Construct (Decls) then
Curr := Last (Decls);
-- Otherwise the handled body lacks declarations. The construct to
-- inspect is the node which precedes the handled body, unless the
-- body is a compilation unit. The transitions are:
--
-- statements -> upper level
-- statements -> corresponding package spec (Elab_Body)
-- statements -> terminate
else
Transition_Unit (Bod, Curr);
end if;
end Transition_Handled_Statements;
----------------------------------
-- Transition_Spec_Declarations --
----------------------------------
procedure Transition_Spec_Declarations
(Spec : Node_Id;
Curr : out Node_Id)
is
Prv_Decls : constant List_Id := Private_Declarations (Spec);
Vis_Decls : constant List_Id := Visible_Declarations (Spec);
begin
pragma Assert (Present (Start) and then Is_List_Member (Start));
-- The search came from the private declarations and finished
-- their inspection.
if Has_Suitable_Construct (Prv_Decls)
and then List_Containing (Start) = Prv_Decls
then
-- The context has non-empty visible declarations. The node to
-- inspect is the last visible declaration. The transitions
-- are:
--
-- private declarations -> visible declarations
if Has_Suitable_Construct (Vis_Decls) then
Curr := Last (Vis_Decls);
-- Otherwise the context lacks visible declarations. The
-- construct to inspect is the node which precedes the context
-- unless the context is a compilation unit. The transitions
-- are:
--
-- private declarations -> upper level
-- private declarations -> terminate
else
Transition_Unit (Parent (Spec), Curr);
end if;
-- The search came from the visible declarations and finished
-- their inspections. The construct to inspect is the node which
-- precedes the context, unless the context is a compilaton unit.
-- The transitions are:
--
-- visible declarations -> upper level
-- visible declarations -> terminate
elsif Has_Suitable_Construct (Vis_Decls)
and then List_Containing (Start) = Vis_Decls
then
Transition_Unit (Parent (Spec), Curr);
-- At this point both declarative lists are empty, but the
-- traversal still came from within the spec. This indicates
-- that the invariant of the algorithm has been violated.
else
pragma Assert (False);
raise ECR_Found;
end if;
end Transition_Spec_Declarations;
---------------------
-- Transition_Unit --
---------------------
procedure Transition_Unit
(Unit : Node_Id;
Curr : out Node_Id)
is
Context : constant Node_Id := Parent (Unit);
begin
-- The unit is a compilation unit. This terminates the search
-- because there are no more lists to inspect and there are no
-- more enclosing constructs to climb up to.
if Nkind (Context) = N_Compilation_Unit then
-- A package body with a corresponding spec subject to pragma
-- Elaborate_Body is an exception to the above. The annotation
-- allows the search to continue into the package declaration.
-- The transitions are:
--
-- statements -> corresponding package spec (Elab_Body)
-- declarations -> corresponding package spec (Elab_Body)
if Nkind (Unit) = N_Package_Body
and then (Assume_Elab_Body
or else Has_Pragma_Elaborate_Body
(Corresponding_Spec (Unit)))
then
Curr := Unit_Declaration_Node (Corresponding_Spec (Unit));
Enter_Package_Declaration (Curr);
-- Otherwise terminate the search. The transitions are:
--
-- private declarations -> terminate
-- visible declarations -> terminate
-- statements -> terminate
-- declarations -> terminate
else
raise ECR_Found;
end if;
-- The unit is a subunit. The construct to inspect is the node
-- which precedes the corresponding stub. Update the early call
-- region to include the unit.
elsif Nkind (Context) = N_Subunit then
Start := Unit;
Curr := Corresponding_Stub (Context);
-- Otherwise the unit is nested. The construct to inspect is the
-- node which precedes the unit. Update the early call region to
-- include the unit.
else
Include (Unit, Curr);
end if;
end Transition_Unit;
-- Local variables
Body_Id : constant Entity_Id := Unique_Defining_Entity (Body_Decl);
Region : Node_Id;
-- Start of processing for Find_Early_Call_Region
begin
-- The caller demands the start of the early call region without
-- saving or retrieving it to/from internal data structures.
if Skip_Memoization then
Region := Find_ECR (Body_Decl);
-- Default behavior
else
-- Check whether the early call region of the subprogram body is
-- available.
Region := Early_Call_Region (Body_Id);
if No (Region) then
Region := Find_ECR (Body_Decl);
-- Associate the early call region with the subprogram body in
-- case other scenarios need it.
Set_Early_Call_Region (Body_Id, Region);
end if;
end if;
-- A subprogram body must always have an early call region
pragma Assert (Present (Region));
return Region;
end Find_Early_Call_Region;
--------------------------------------------
-- Initialize_Early_Call_Region_Processor --
--------------------------------------------
procedure Initialize_Early_Call_Region_Processor is
begin
Early_Call_Regions_Map := ECR_Map.Create (100);
end Initialize_Early_Call_Region_Processor;
---------------------------
-- Set_Early_Call_Region --
---------------------------
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id) is
pragma Assert (Present (Body_Id));
pragma Assert (Present (Start));
begin
ECR_Map.Put (Early_Call_Regions_Map, Body_Id, Start);
end Set_Early_Call_Region;
end Early_Call_Region_Processor;
----------------------
-- Elaborated_Units --
----------------------
package body Elaborated_Units is
-----------
-- Types --
-----------
-- The following type idenfities the elaboration attributes of a unit
type Elaboration_Attributes_Id is new Natural;
No_Elaboration_Attributes : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Id'First;
First_Elaboration_Attributes : constant Elaboration_Attributes_Id :=
No_Elaboration_Attributes + 1;
-- The following type represents the elaboration attributes of a unit
type Elaboration_Attributes_Record is record
Elab_Pragma : Node_Id := Empty;
-- This attribute denotes a source Elaborate or Elaborate_All pragma
-- which guarantees the prior elaboration of some unit with respect
-- to the main unit. The pragma may come from the following contexts:
--
-- * The main unit
-- * The spec of the main unit (if applicable)
-- * Any parent spec of the main unit (if applicable)
-- * Any parent subunit of the main unit (if applicable)
--
-- The attribute remains Empty if no such pragma is available. Source
-- pragmas play a role in satisfying SPARK elaboration requirements.
With_Clause : Node_Id := Empty;
-- This attribute denotes an internally-generated or a source with
-- clause for some unit withed by the main unit. With clauses carry
-- flags which represent implicit Elaborate or Elaborate_All pragmas.
-- These clauses play a role in supplying elaboration dependencies to
-- binde.
end record;
---------------------
-- Data structures --
---------------------
-- The following table stores all elaboration attributes
package Elaboration_Attributes is new Table.Table
(Table_Index_Type => Elaboration_Attributes_Id,
Table_Component_Type => Elaboration_Attributes_Record,
Table_Low_Bound => First_Elaboration_Attributes,
Table_Initial => 250,
Table_Increment => 200,
Table_Name => "Elaboration_Attributes");
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id);
-- Destroy elaboration attributes EA_Id
package UA_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Elaboration_Attributes_Id,
No_Value => No_Elaboration_Attributes,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates an elaboration attributes of a unit to the
-- unit.
Unit_To_Attributes_Map : UA_Map.Dynamic_Hash_Table := UA_Map.Nil;
------------------
-- Constructors --
------------------
function Elaboration_Attributes_Of
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id;
pragma Inline (Elaboration_Attributes_Of);
-- Obtain the elaboration attributes of unit Unit_Id
-----------------------
-- Local subprograms --
-----------------------
function Elab_Pragma (EA_Id : Elaboration_Attributes_Id) return Node_Id;
pragma Inline (Elab_Pragma);
-- Obtain the Elaborate[_All] pragma of elaboration attributes EA_Id
procedure Ensure_Prior_Elaboration_Dynamic
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration_Dynamic);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by suggesting the use of Elaborate[_All] with name Prag_Nam. N
-- denotes the related scenario. In_State is the current state of the
-- Processing phase.
procedure Ensure_Prior_Elaboration_Static
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration_Static);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by installing an implicit Elaborate[_All] pragma with name
-- Prag_Nam. N denotes the related scenario. In_State is the current
-- state of the Processing phase.
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean;
pragma Inline (Present);
-- Determine whether elaboration attributes UA_Id exist
procedure Set_Elab_Pragma
(EA_Id : Elaboration_Attributes_Id;
Prag : Node_Id);
pragma Inline (Set_Elab_Pragma);
-- Set the Elaborate[_All] pragma of elaboration attributes EA_Id to
-- Prag.
procedure Set_With_Clause
(EA_Id : Elaboration_Attributes_Id;
Clause : Node_Id);
pragma Inline (Set_With_Clause);
-- Set the with clause of elaboration attributes EA_Id to Clause
function With_Clause (EA_Id : Elaboration_Attributes_Id) return Node_Id;
pragma Inline (With_Clause);
-- Obtain the implicit or source with clause of elaboration attributes
-- EA_Id.
------------------------------
-- Collect_Elaborated_Units --
------------------------------
procedure Collect_Elaborated_Units is
procedure Add_Pragma (Prag : Node_Id);
pragma Inline (Add_Pragma);
-- Determine whether pragma Prag denotes a legal Elaborate[_All]
-- pragma. If this is the case, add the related unit to the context.
-- For pragma Elaborate_All, include recursively all units withed by
-- the related unit.
procedure Add_Unit
(Unit_Id : Entity_Id;
Prag : Node_Id;
Full_Context : Boolean);
pragma Inline (Add_Unit);
-- Add unit Unit_Id to the elaboration context. Prag denotes the
-- pragma which prompted the inclusion of the unit to the context.
-- If flag Full_Context is set, examine the nonlimited clauses of
-- unit Unit_Id and add each withed unit to the context.
procedure Find_Elaboration_Context (Comp_Unit : Node_Id);
pragma Inline (Find_Elaboration_Context);
-- Examine the context items of compilation unit Comp_Unit for
-- suitable elaboration-related pragmas and add all related units
-- to the context.
----------------
-- Add_Pragma --
----------------
procedure Add_Pragma (Prag : Node_Id) is
Prag_Args : constant List_Id :=
Pragma_Argument_Associations (Prag);
Prag_Nam : constant Name_Id := Pragma_Name (Prag);
Unit_Arg : Node_Id;
begin
-- Nothing to do if the pragma is not related to elaboration
if Prag_Nam not in Name_Elaborate | Name_Elaborate_All then
return;
-- Nothing to do when the pragma is illegal
elsif Error_Posted (Prag) then
return;
end if;
Unit_Arg := Get_Pragma_Arg (First (Prag_Args));
-- The argument of the pragma may appear in package.package form
if Nkind (Unit_Arg) = N_Selected_Component then
Unit_Arg := Selector_Name (Unit_Arg);
end if;
Add_Unit
(Unit_Id => Entity (Unit_Arg),
Prag => Prag,
Full_Context => Prag_Nam = Name_Elaborate_All);
end Add_Pragma;
--------------
-- Add_Unit --
--------------
procedure Add_Unit
(Unit_Id : Entity_Id;
Prag : Node_Id;
Full_Context : Boolean)
is
Clause : Node_Id;
EA_Id : Elaboration_Attributes_Id;
Unit_Prag : Node_Id;
begin
-- Nothing to do when some previous error left a with clause or a
-- pragma in a bad state.
if No (Unit_Id) then
return;
end if;
EA_Id := Elaboration_Attributes_Of (Unit_Id);
Unit_Prag := Elab_Pragma (EA_Id);
-- The unit is already included in the context by means of pragma
-- Elaborate[_All].
if Present (Unit_Prag) then
-- Upgrade an existing pragma Elaborate when the unit is
-- subject to Elaborate_All because the new pragma covers a
-- larger set of units.
if Pragma_Name (Unit_Prag) = Name_Elaborate
and then Pragma_Name (Prag) = Name_Elaborate_All
then
Set_Elab_Pragma (EA_Id, Prag);
-- Otherwise the unit retains its existing pragma and does not
-- need to be included in the context again.
else
return;
end if;
-- Otherwise the current unit is not included in the context
else
Set_Elab_Pragma (EA_Id, Prag);
end if;
-- Includes all units withed by the current one when computing the
-- full context.
if Full_Context then
-- Process all nonlimited with clauses found in the context of
-- the current unit. Note that limited clauses do not impose an
-- elaboration order.
Clause := First (Context_Items (Compilation_Unit (Unit_Id)));
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause
and then not Error_Posted (Clause)
and then not Limited_Present (Clause)
then
Add_Unit
(Unit_Id => Entity (Name (Clause)),
Prag => Prag,
Full_Context => Full_Context);
end if;
Next (Clause);
end loop;
end if;
end Add_Unit;
------------------------------
-- Find_Elaboration_Context --
------------------------------
procedure Find_Elaboration_Context (Comp_Unit : Node_Id) is
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
Prag : Node_Id;
begin
-- Process all elaboration-related pragmas found in the context of
-- the compilation unit.
Prag := First (Context_Items (Comp_Unit));
while Present (Prag) loop
if Nkind (Prag) = N_Pragma then
Add_Pragma (Prag);
end if;
Next (Prag);
end loop;
end Find_Elaboration_Context;
-- Local variables
Par_Id : Entity_Id;
Unit_Id : Node_Id;
-- Start of processing for Collect_Elaborated_Units
begin
-- Perform a traversal to examines the context of the main unit. The
-- traversal performs the following jumps:
--
-- subunit -> parent subunit
-- parent subunit -> body
-- body -> spec
-- spec -> parent spec
-- parent spec -> grandparent spec and so on
--
-- The traversal relies on units rather than scopes because the scope
-- of a subunit is some spec, while this traversal must process the
-- body as well. Given that protected and task bodies can also be
-- subunits, this complicates the scope approach even further.
Unit_Id := Unit (Cunit (Main_Unit));
-- Perform the following traversals when the main unit is a subunit
--
-- subunit -> parent subunit
-- parent subunit -> body
while Present (Unit_Id) and then Nkind (Unit_Id) = N_Subunit loop
Find_Elaboration_Context (Parent (Unit_Id));
-- Continue the traversal by going to the unit which contains the
-- corresponding stub.
if Present (Corresponding_Stub (Unit_Id)) then
Unit_Id :=
Unit (Cunit (Get_Source_Unit (Corresponding_Stub (Unit_Id))));
-- Otherwise the subunit may be erroneous or left in a bad state
else
exit;
end if;
end loop;
-- Perform the following traversal now that subunits have been taken
-- care of, or the main unit is a body.
--
-- body -> spec
if Present (Unit_Id)
and then Nkind (Unit_Id) in N_Package_Body | N_Subprogram_Body
then
Find_Elaboration_Context (Parent (Unit_Id));
-- Continue the traversal by going to the unit which contains the
-- corresponding spec.
if Present (Corresponding_Spec (Unit_Id)) then
Unit_Id :=
Unit (Cunit (Get_Source_Unit (Corresponding_Spec (Unit_Id))));
end if;
end if;
-- Perform the following traversals now that the body has been taken
-- care of, or the main unit is a spec.
--
-- spec -> parent spec
-- parent spec -> grandparent spec and so on
if Present (Unit_Id)
and then Nkind (Unit_Id) in N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Subprogram_Declaration
then
Find_Elaboration_Context (Parent (Unit_Id));
-- Process a potential chain of parent units which ends with the
-- main unit spec. The traversal can now safely rely on the scope
-- chain.
Par_Id := Scope (Defining_Entity (Unit_Id));
while Present (Par_Id) and then Par_Id /= Standard_Standard loop
Find_Elaboration_Context (Compilation_Unit (Par_Id));
Par_Id := Scope (Par_Id);
end loop;
end if;
end Collect_Elaborated_Units;
-------------
-- Destroy --
-------------
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id) is
pragma Unreferenced (EA_Id);
begin
null;
end Destroy;
-----------------
-- Elab_Pragma --
-----------------
function Elab_Pragma
(EA_Id : Elaboration_Attributes_Id) return Node_Id
is
pragma Assert (Present (EA_Id));
begin
return Elaboration_Attributes.Table (EA_Id).Elab_Pragma;
end Elab_Pragma;
-------------------------------
-- Elaboration_Attributes_Of --
-------------------------------
function Elaboration_Attributes_Of
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id
is
EA_Id : Elaboration_Attributes_Id;
begin
EA_Id := UA_Map.Get (Unit_To_Attributes_Map, Unit_Id);
-- The unit lacks elaboration attributes. This indicates that the
-- unit is encountered for the first time. Create the elaboration
-- attributes for it.
if not Present (EA_Id) then
Elaboration_Attributes.Append
((Elab_Pragma => Empty,
With_Clause => Empty));
EA_Id := Elaboration_Attributes.Last;
-- Associate the elaboration attributes with the unit
UA_Map.Put (Unit_To_Attributes_Map, Unit_Id, EA_Id);
end if;
pragma Assert (Present (EA_Id));
return EA_Id;
end Elaboration_Attributes_Of;
------------------------------
-- Ensure_Prior_Elaboration --
------------------------------
procedure Ensure_Prior_Elaboration
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
pragma Assert (Prag_Nam in Name_Elaborate | Name_Elaborate_All);
begin
-- Nothing to do when the need for prior elaboration came from a
-- partial finalization routine which occurs in an initialization
-- context. This behavior parallels that of the old ABE mechanism.
if In_State.Within_Partial_Finalization then
return;
-- Nothing to do when the need for prior elaboration came from a task
-- body and switch -gnatd.y (disable implicit pragma Elaborate_All on
-- task bodies) is in effect.
elsif Debug_Flag_Dot_Y and then In_State.Within_Task_Body then
return;
-- Nothing to do when the unit is elaborated prior to the main unit.
-- This check must also consider the following cases:
--
-- * No check is made against the context of the main unit because
-- this is specific to the elaboration model in effect and requires
-- custom handling (see Ensure_xxx_Prior_Elaboration).
--
-- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma
-- Elaborate[_All] MUST be generated even though Unit_Id is always
-- elaborated prior to the main unit. This conservative strategy
-- ensures that other units withed by Unit_Id will not lead to an
-- ABE.
--
-- package A is package body A is
-- procedure ABE; procedure ABE is ... end ABE;
-- end A; end A;
--
-- with A;
-- package B is package body B is
-- pragma Elaborate_Body; procedure Proc is
-- begin
-- procedure Proc; A.ABE;
-- package B; end Proc;
-- end B;
--
-- with B;
-- package C is package body C is
-- ... ...
-- end C; begin
-- B.Proc;
-- end C;
--
-- In the example above, the elaboration of C invokes B.Proc. B is
-- subject to pragma Elaborate_Body. If no pragma Elaborate[_All]
-- is gnerated for B in C, then the following elaboratio order will
-- lead to an ABE:
--
-- spec of A elaborated
-- spec of B elaborated
-- body of B elaborated
-- spec of C elaborated
-- body of C elaborated <-- calls B.Proc which calls A.ABE
-- body of A elaborated <-- problem
--
-- The generation of an implicit pragma Elaborate_All (B) ensures
-- that the elaboration-order mechanism will not pick the above
-- order.
--
-- An implicit Elaborate is NOT generated when the unit is subject
-- to Elaborate_Body because both pragmas have the same effect.
--
-- * Unit_Id is the main unit. An implicit pragma Elaborate[_All]
-- MUST NOT be generated in this case because a unit cannot depend
-- on its own elaboration. This case is therefore treated as valid
-- prior elaboration.
elsif Has_Prior_Elaboration
(Unit_Id => Unit_Id,
Same_Unit_OK => True,
Elab_Body_OK => Prag_Nam = Name_Elaborate)
then
return;
end if;
-- Suggest the use of pragma Prag_Nam when the dynamic model is in
-- effect.
if Dynamic_Elaboration_Checks then
Ensure_Prior_Elaboration_Dynamic
(N => N,
Unit_Id => Unit_Id,
Prag_Nam => Prag_Nam,
In_State => In_State);
-- Install an implicit pragma Prag_Nam when the static model is in
-- effect.
else
pragma Assert (Static_Elaboration_Checks);
Ensure_Prior_Elaboration_Static
(N => N,
Unit_Id => Unit_Id,
Prag_Nam => Prag_Nam,
In_State => In_State);
end if;
end Ensure_Prior_Elaboration;
--------------------------------------
-- Ensure_Prior_Elaboration_Dynamic --
--------------------------------------
procedure Ensure_Prior_Elaboration_Dynamic
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
procedure Info_Missing_Pragma;
pragma Inline (Info_Missing_Pragma);
-- Output information concerning missing Elaborate or Elaborate_All
-- pragma with name Prag_Nam for scenario N, which would ensure the
-- prior elaboration of Unit_Id.
-------------------------
-- Info_Missing_Pragma --
-------------------------
procedure Info_Missing_Pragma is
begin
-- Internal units are ignored as they cause unnecessary noise
if not In_Internal_Unit (Unit_Id) then
-- The name of the unit subjected to the elaboration pragma is
-- fully qualified to improve the clarity of the info message.
Error_Msg_Name_1 := Prag_Nam;
Error_Msg_Qual_Level := Nat'Last;
Error_Msg_NE ("info: missing pragma % for unit &", N, Unit_Id);
Error_Msg_Qual_Level := 0;
end if;
end Info_Missing_Pragma;
-- Local variables
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
N_Lvl : Enclosing_Level_Kind;
N_Rep : Scenario_Rep_Id;
-- Start of processing for Ensure_Prior_Elaboration_Dynamic
begin
-- Nothing to do when the unit is guaranteed prior elaboration by
-- means of a source Elaborate[_All] pragma.
if Present (Elab_Pragma (EA_Id)) then
return;
end if;
-- Output extra information on a missing Elaborate[_All] pragma when
-- switch -gnatel (info messages on implicit Elaborate[_All] pragmas
-- is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
N_Rep := Scenario_Representation_Of (N, In_State);
N_Lvl := Level (N_Rep);
-- Declaration-level scenario
if (Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N))
and then N_Lvl = Declaration_Level
then
null;
-- Library-level scenario
elsif N_Lvl in Library_Level then
null;
-- Instantiation library-level scenario
elsif N_Lvl = Instantiation_Level then
null;
-- Otherwise the scenario does not appear at the proper level
else
return;
end if;
Info_Missing_Pragma;
end if;
end Ensure_Prior_Elaboration_Dynamic;
-------------------------------------
-- Ensure_Prior_Elaboration_Static --
-------------------------------------
procedure Ensure_Prior_Elaboration_Static
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
function Find_With_Clause
(Items : List_Id;
Withed_Id : Entity_Id) return Node_Id;
pragma Inline (Find_With_Clause);
-- Find a nonlimited with clause in the list of context items Items
-- that withs unit Withed_Id. Return Empty if no such clause exists.
procedure Info_Implicit_Pragma;
pragma Inline (Info_Implicit_Pragma);
-- Output information concerning an implicitly generated Elaborate
-- or Elaborate_All pragma with name Prag_Nam for scenario N which
-- ensures the prior elaboration of unit Unit_Id.
----------------------
-- Find_With_Clause --
----------------------
function Find_With_Clause
(Items : List_Id;
Withed_Id : Entity_Id) return Node_Id
is
Item : Node_Id;
begin
-- Examine the context clauses looking for a suitable with. Note
-- that limited clauses do not affect the elaboration order.
Item := First (Items);
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Error_Posted (Item)
and then not Limited_Present (Item)
and then Entity (Name (Item)) = Withed_Id
then
return Item;
end if;
Next (Item);
end loop;
return Empty;
end Find_With_Clause;
--------------------------
-- Info_Implicit_Pragma --
--------------------------
procedure Info_Implicit_Pragma is
begin
-- Internal units are ignored as they cause unnecessary noise
if not In_Internal_Unit (Unit_Id) then
-- The name of the unit subjected to the elaboration pragma is
-- fully qualified to improve the clarity of the info message.
Error_Msg_Name_1 := Prag_Nam;
Error_Msg_Qual_Level := Nat'Last;
Error_Msg_NE
("info: implicit pragma % generated for unit &", N, Unit_Id);
Error_Msg_Qual_Level := 0;
Output_Active_Scenarios (N, In_State);
end if;
end Info_Implicit_Pragma;
-- Local variables
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
Main_Cunit : constant Node_Id := Cunit (Main_Unit);
Loc : constant Source_Ptr := Sloc (Main_Cunit);
Unit_Cunit : constant Node_Id := Compilation_Unit (Unit_Id);
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id);
Unit_With : constant Node_Id := With_Clause (EA_Id);
Clause : Node_Id;
Items : List_Id;
-- Start of processing for Ensure_Prior_Elaboration_Static
begin
-- Nothing to do when the caller has suppressed the generation of
-- implicit Elaborate[_All] pragmas.
if In_State.Suppress_Implicit_Pragmas then
return;
-- Nothing to do when the unit is guaranteed prior elaboration by
-- means of a source Elaborate[_All] pragma.
elsif Present (Unit_Prag) then
return;
-- Nothing to do when the unit has an existing implicit Elaborate or
-- Elaborate_All pragma installed by a previous scenario.
elsif Present (Unit_With) then
-- The unit is already guaranteed prior elaboration by means of an
-- implicit Elaborate pragma, however the current scenario imposes
-- a stronger requirement of Elaborate_All. "Upgrade" the existing
-- pragma to match this new requirement.
if Elaborate_Desirable (Unit_With)
and then Prag_Nam = Name_Elaborate_All
then
Set_Elaborate_All_Desirable (Unit_With);
Set_Elaborate_Desirable (Unit_With, False);
end if;
return;
end if;
-- At this point it is known that the unit has no prior elaboration
-- according to pragmas and hierarchical relationships.
Items := Context_Items (Main_Cunit);
if No (Items) then
Items := New_List;
Set_Context_Items (Main_Cunit, Items);
end if;
-- Locate the with clause for the unit. Note that there may not be a
-- clause if the unit is visible through a subunit-body, body-spec,
-- or spec-parent relationship.
Clause :=
Find_With_Clause
(Items => Items,
Withed_Id => Unit_Id);
-- Generate:
-- with Id;
-- Note that adding implicit with clauses is safe because analysis,
-- resolution, and expansion have already taken place and it is not
-- possible to interfere with visibility.
if No (Clause) then
Clause :=
Make_With_Clause (Loc,
Name => New_Occurrence_Of (Unit_Id, Loc));
Set_Implicit_With (Clause);
Set_Library_Unit (Clause, Unit_Cunit);
Append_To (Items, Clause);
end if;
-- Mark the with clause depending on the pragma required
if Prag_Nam = Name_Elaborate then
Set_Elaborate_Desirable (Clause);
else
Set_Elaborate_All_Desirable (Clause);
end if;
-- The implicit Elaborate[_All] ensures the prior elaboration of
-- the unit. Include the unit in the elaboration context of the
-- main unit.
Set_With_Clause (EA_Id, Clause);
-- Output extra information on an implicit Elaborate[_All] pragma
-- when switch -gnatel (info messages on implicit Elaborate[_All]
-- pragmas is in effect.
if Elab_Info_Messages then
Info_Implicit_Pragma;
end if;
end Ensure_Prior_Elaboration_Static;
-------------------------------
-- Finalize_Elaborated_Units --
-------------------------------
procedure Finalize_Elaborated_Units is
begin
UA_Map.Destroy (Unit_To_Attributes_Map);
end Finalize_Elaborated_Units;
---------------------------
-- Has_Prior_Elaboration --
---------------------------
function Has_Prior_Elaboration
(Unit_Id : Entity_Id;
Context_OK : Boolean := False;
Elab_Body_OK : Boolean := False;
Same_Unit_OK : Boolean := False) return Boolean
is
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
Main_Id : constant Entity_Id := Main_Unit_Entity;
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id);
Unit_With : constant Node_Id := With_Clause (EA_Id);
begin
-- A preelaborated unit is always elaborated prior to the main unit
if Is_Preelaborated_Unit (Unit_Id) then
return True;
-- An internal unit is always elaborated prior to a non-internal main
-- unit.
elsif In_Internal_Unit (Unit_Id)
and then not In_Internal_Unit (Main_Id)
then
return True;
-- A unit has prior elaboration if it appears within the context
-- of the main unit. Consider this case only when requested by the
-- caller.
elsif Context_OK
and then (Present (Unit_Prag) or else Present (Unit_With))
then
return True;
-- A unit whose body is elaborated together with its spec has prior
-- elaboration except with respect to itself. Consider this case only
-- when requested by the caller.
elsif Elab_Body_OK
and then Has_Pragma_Elaborate_Body (Unit_Id)
and then not Is_Same_Unit (Unit_Id, Main_Id)
then
return True;
-- A unit has no prior elaboration with respect to itself, but does
-- not require any means of ensuring its own elaboration either.
-- Treat this case as valid prior elaboration only when requested by
-- the caller.
elsif Same_Unit_OK and then Is_Same_Unit (Unit_Id, Main_Id) then
return True;
end if;
return False;
end Has_Prior_Elaboration;
---------------------------------
-- Initialize_Elaborated_Units --
---------------------------------
procedure Initialize_Elaborated_Units is
begin
Unit_To_Attributes_Map := UA_Map.Create (250);
end Initialize_Elaborated_Units;
----------------------------------
-- Meet_Elaboration_Requirement --
----------------------------------
procedure Meet_Elaboration_Requirement
(N : Node_Id;
Targ_Id : Entity_Id;
Req_Nam : Name_Id;
In_State : Processing_In_State)
is
pragma Assert (Req_Nam in Name_Elaborate | Name_Elaborate_All);
Main_Id : constant Entity_Id := Main_Unit_Entity;
Unit_Id : constant Entity_Id := Find_Top_Unit (Targ_Id);
procedure Elaboration_Requirement_Error;
pragma Inline (Elaboration_Requirement_Error);
-- Emit an error concerning scenario N which has failed to meet the
-- elaboration requirement.
function Find_Preelaboration_Pragma
(Prag_Nam : Name_Id) return Node_Id;
pragma Inline (Find_Preelaboration_Pragma);
-- Traverse the visible declarations of unit Unit_Id and locate a
-- source preelaboration-related pragma with name Prag_Nam.
procedure Info_Requirement_Met (Prag : Node_Id);
pragma Inline (Info_Requirement_Met);
-- Output information concerning pragma Prag which meets requirement
-- Req_Nam.
-----------------------------------
-- Elaboration_Requirement_Error --
-----------------------------------
procedure Elaboration_Requirement_Error is
begin
if Is_Suitable_Call (N) then
Info_Call
(Call => N,
Subp_Id => Targ_Id,
Info_Msg => False,
In_SPARK => True);
elsif Is_Suitable_Instantiation (N) then
Info_Instantiation
(Inst => N,
Gen_Id => Targ_Id,
Info_Msg => False,
In_SPARK => True);
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
Error_Msg_N
("read of refinement constituents during elaboration in "
& "SPARK", N);
elsif Is_Suitable_Variable_Reference (N) then
Info_Variable_Reference
(Ref => N,
Var_Id => Targ_Id);
-- No other scenario may impose a requirement on the context of
-- the main unit.
else
pragma Assert (False);
return;
end if;
Error_Msg_Name_1 := Req_Nam;
Error_Msg_Node_2 := Unit_Id;
Error_Msg_NE ("\\unit & requires pragma % for &", N, Main_Id);
Output_Active_Scenarios (N, In_State);
end Elaboration_Requirement_Error;
--------------------------------
-- Find_Preelaboration_Pragma --
--------------------------------
function Find_Preelaboration_Pragma
(Prag_Nam : Name_Id) return Node_Id
is
Spec : constant Node_Id := Parent (Unit_Id);
Decl : Node_Id;
begin
-- A preelaboration-related pragma comes from source and appears
-- at the top of the visible declarations of a package.
if Nkind (Spec) = N_Package_Specification then
Decl := First (Visible_Declarations (Spec));
while Present (Decl) loop
if Comes_From_Source (Decl) then
if Nkind (Decl) = N_Pragma
and then Pragma_Name (Decl) = Prag_Nam
then
return Decl;
-- Otherwise the construct terminates the region where
-- the preelaboration-related pragma may appear.
else
exit;
end if;
end if;
Next (Decl);
end loop;
end if;
return Empty;
end Find_Preelaboration_Pragma;
--------------------------
-- Info_Requirement_Met --
--------------------------
procedure Info_Requirement_Met (Prag : Node_Id) is
pragma Assert (Present (Prag));
begin
Error_Msg_Name_1 := Req_Nam;
Error_Msg_Sloc := Sloc (Prag);
Error_Msg_NE
("\\% requirement for unit & met by pragma #", N, Unit_Id);
end Info_Requirement_Met;
-- Local variables
EA_Id : Elaboration_Attributes_Id;
Elab_Nam : Name_Id;
Req_Met : Boolean;
Unit_Prag : Node_Id;
-- Start of processing for Meet_Elaboration_Requirement
begin
-- Assume that the requirement has not been met
Req_Met := False;
-- If the target is within the main unit, either at the source level
-- or through an instantiation, then there is no real requirement to
-- meet because the main unit cannot force its own elaboration by
-- means of an Elaborate[_All] pragma. Treat this case as valid
-- coverage.
if In_Extended_Main_Code_Unit (Targ_Id) then
Req_Met := True;
-- Otherwise the target resides in an external unit
-- The requirement is met when the target comes from an internal unit
-- because such a unit is elaborated prior to a non-internal unit.
elsif In_Internal_Unit (Unit_Id)
and then not In_Internal_Unit (Main_Id)
then
Req_Met := True;
-- The requirement is met when the target comes from a preelaborated
-- unit. This portion must parallel predicate Is_Preelaborated_Unit.
elsif Is_Preelaborated_Unit (Unit_Id) then
Req_Met := True;
-- Output extra information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
if Is_Preelaborated (Unit_Id) then
Elab_Nam := Name_Preelaborate;
elsif Is_Pure (Unit_Id) then
Elab_Nam := Name_Pure;
elsif Is_Remote_Call_Interface (Unit_Id) then
Elab_Nam := Name_Remote_Call_Interface;
elsif Is_Remote_Types (Unit_Id) then
Elab_Nam := Name_Remote_Types;
else
pragma Assert (Is_Shared_Passive (Unit_Id));
Elab_Nam := Name_Shared_Passive;
end if;
Info_Requirement_Met (Find_Preelaboration_Pragma (Elab_Nam));
end if;
-- Determine whether the context of the main unit has a pragma strong
-- enough to meet the requirement.
else
EA_Id := Elaboration_Attributes_Of (Unit_Id);
Unit_Prag := Elab_Pragma (EA_Id);
-- The pragma must be either Elaborate_All or be as strong as the
-- requirement.
if Present (Unit_Prag)
and then Pragma_Name (Unit_Prag) in Name_Elaborate_All | Req_Nam
then
Req_Met := True;
-- Output extra information when switch -gnatel (info messages
-- on implicit Elaborate[_All] pragmas.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Info_Requirement_Met (Unit_Prag);
end if;
end if;
end if;
-- The requirement was not met by the context of the main unit, issue
-- an error.
if not Req_Met then
Elaboration_Requirement_Error;
end if;
end Meet_Elaboration_Requirement;
-------------
-- Present --
-------------
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean is
begin
return EA_Id /= No_Elaboration_Attributes;
end Present;
---------------------
-- Set_Elab_Pragma --
---------------------
procedure Set_Elab_Pragma
(EA_Id : Elaboration_Attributes_Id;
Prag : Node_Id)
is
pragma Assert (Present (EA_Id));
begin
Elaboration_Attributes.Table (EA_Id).Elab_Pragma := Prag;
end Set_Elab_Pragma;
---------------------
-- Set_With_Clause --
---------------------
procedure Set_With_Clause
(EA_Id : Elaboration_Attributes_Id;
Clause : Node_Id)
is
pragma Assert (Present (EA_Id));
begin
Elaboration_Attributes.Table (EA_Id).With_Clause := Clause;
end Set_With_Clause;
-----------------
-- With_Clause --
-----------------
function With_Clause
(EA_Id : Elaboration_Attributes_Id) return Node_Id
is
pragma Assert (Present (EA_Id));
begin
return Elaboration_Attributes.Table (EA_Id).With_Clause;
end With_Clause;
end Elaborated_Units;
------------------------------
-- Elaboration_Phase_Active --
------------------------------
function Elaboration_Phase_Active return Boolean is
begin
return Elaboration_Phase = Active;
end Elaboration_Phase_Active;
------------------------------
-- Error_Preelaborated_Call --
------------------------------
procedure Error_Preelaborated_Call (N : Node_Id) is
begin
-- This is a warning in GNAT mode allowing such calls to be used in the
-- predefined library units with appropriate care.
Error_Msg_Warn := GNAT_Mode;
-- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
-- unchecked conversions are preelaborable.
if Ada_Version >= Ada_2022 then
Error_Msg_N
("<<non-preelaborable call not allowed in preelaborated unit", N);
else
Error_Msg_N
("<<non-static call not allowed in preelaborated unit", N);
end if;
end Error_Preelaborated_Call;
----------------------------------
-- Finalize_All_Data_Structures --
----------------------------------
procedure Finalize_All_Data_Structures is
begin
Finalize_Body_Processor;
Finalize_Early_Call_Region_Processor;
Finalize_Elaborated_Units;
Finalize_Internal_Representation;
Finalize_Invocation_Graph;
Finalize_Scenario_Storage;
end Finalize_All_Data_Structures;
-----------------------------
-- Find_Enclosing_Instance --
-----------------------------
function Find_Enclosing_Instance (N : Node_Id) return Node_Id is
Par : Node_Id;
begin
-- Climb the parent chain looking for an enclosing instance spec or body
Par := N;
while Present (Par) loop
if Nkind (Par) in N_Package_Body
| N_Package_Declaration
| N_Subprogram_Body
| N_Subprogram_Declaration
and then Is_Generic_Instance (Unique_Defining_Entity (Par))
then
return Par;
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Enclosing_Instance;
--------------------------
-- Find_Enclosing_Level --
--------------------------
function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind is
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind;
pragma Inline (Level_Of);
-- Obtain the corresponding level of unit Unit
--------------
-- Level_Of --
--------------
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind is
Spec_Id : Entity_Id;
begin
if Nkind (Unit) in N_Generic_Instantiation then
return Instantiation_Level;
elsif Nkind (Unit) = N_Generic_Package_Declaration then
return Generic_Spec_Level;
elsif Nkind (Unit) = N_Package_Declaration then
return Library_Spec_Level;
elsif Nkind (Unit) = N_Package_Body then
Spec_Id := Corresponding_Spec (Unit);
-- The body belongs to a generic package
if Present (Spec_Id)
and then Ekind (Spec_Id) = E_Generic_Package
then
return Generic_Body_Level;
-- Otherwise the body belongs to a non-generic package. This also
-- treats an illegal package body without a corresponding spec as
-- a non-generic package body.
else
return Library_Body_Level;
end if;
end if;
return No_Level;
end Level_Of;
-- Local variables
Context : Node_Id;
Curr : Node_Id;
Prev : Node_Id;
-- Start of processing for Find_Enclosing_Level
begin
-- Call markers and instantiations which appear at the declaration level
-- but are later relocated in a different context retain their original
-- declaration level.
if Nkind (N) in N_Call_Marker
| N_Function_Instantiation
| N_Package_Instantiation
| N_Procedure_Instantiation
and then Is_Declaration_Level_Node (N)
then
return Declaration_Level;
end if;
-- Climb the parent chain looking at the enclosing levels
Prev := N;
Curr := Parent (Prev);
while Present (Curr) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Curr) = N_Subunit then
Curr := Corresponding_Stub (Curr);
-- The current construct is a package. Packages are ignored because
-- they are always elaborated when the enclosing context is invoked
-- or elaborated.
elsif Nkind (Curr) in N_Package_Body | N_Package_Declaration then
null;
-- The current construct is a block statement
elsif Nkind (Curr) = N_Block_Statement then
-- Ignore internally generated blocks created by the expander for
-- various purposes such as abort defer/undefer.
if not Comes_From_Source (Curr) then
null;
-- If the traversal came from the handled sequence of statements,
-- then the node appears at the level of the enclosing construct.
-- This is a more reliable test because transients scopes within
-- the declarative region of the encapsulator are hard to detect.
elsif Nkind (Prev) = N_Handled_Sequence_Of_Statements
and then Handled_Statement_Sequence (Curr) = Prev
then
return Find_Enclosing_Level (Parent (Curr));
-- Otherwise the traversal came from the declarations, the node is
-- at the declaration level.
else
return Declaration_Level;
end if;
-- The current construct is a declaration-level encapsulator
elsif Nkind (Curr) in
N_Entry_Body | N_Subprogram_Body | N_Task_Body
then
-- If the traversal came from the handled sequence of statements,
-- then the node cannot possibly appear at any level. This is
-- a more reliable test because transients scopes within the
-- declarative region of the encapsulator are hard to detect.
if Nkind (Prev) = N_Handled_Sequence_Of_Statements
and then Handled_Statement_Sequence (Curr) = Prev
then
return No_Level;
-- Otherwise the traversal came from the declarations, the node is
-- at the declaration level.
else
return Declaration_Level;
end if;
-- The current construct is a non-library-level encapsulator which
-- indicates that the node cannot possibly appear at any level. Note
-- that the check must come after the declaration-level check because
-- both predicates share certain nodes.
elsif Is_Non_Library_Level_Encapsulator (Curr) then
Context := Parent (Curr);
-- The sole exception is when the encapsulator is the compilation
-- utit itself because the compilation unit node requires special
-- processing (see below).
if Present (Context)
and then Nkind (Context) = N_Compilation_Unit
then
null;
-- Otherwise the node is not at any level
else
return No_Level;
end if;
-- The current construct is a compilation unit. The node appears at
-- the [generic] library level when the unit is a [generic] package.
elsif Nkind (Curr) = N_Compilation_Unit then
return Level_Of (Unit (Curr));
end if;
Prev := Curr;
Curr := Parent (Prev);
end loop;
return No_Level;
end Find_Enclosing_Level;
-------------------
-- Find_Top_Unit --
-------------------
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id is
begin
return Find_Unit_Entity (Unit (Cunit (Get_Top_Level_Code_Unit (N))));
end Find_Top_Unit;
----------------------
-- Find_Unit_Entity --
----------------------
function Find_Unit_Entity (N : Node_Id) return Entity_Id is
Context : constant Node_Id := Parent (N);
Orig_N : constant Node_Id := Original_Node (N);
begin
-- The unit denotes a package body of an instantiation which acts as
-- a compilation unit. The proper entity is that of the package spec.
if Nkind (N) = N_Package_Body
and then Nkind (Orig_N) = N_Package_Instantiation
and then Nkind (Context) = N_Compilation_Unit
then
return Corresponding_Spec (N);
-- The unit denotes an anonymous package created to wrap a subprogram
-- instantiation which acts as a compilation unit. The proper entity is
-- that of the "related instance".
elsif Nkind (N) = N_Package_Declaration
and then Nkind (Orig_N) in
N_Function_Instantiation | N_Procedure_Instantiation
and then Nkind (Context) = N_Compilation_Unit
then
return Related_Instance (Defining_Entity (N));
-- The unit denotes a concurrent body acting as a subunit. Such bodies
-- are generally rewritten into null statements. The proper entity is
-- that of the "original node".
elsif Nkind (N) = N_Subunit
and then Nkind (Proper_Body (N)) = N_Null_Statement
and then Nkind (Original_Node (Proper_Body (N))) in
N_Protected_Body | N_Task_Body
then
return Defining_Entity (Original_Node (Proper_Body (N)));
-- Otherwise the proper entity is the defining entity
else
return Defining_Entity (N);
end if;
end Find_Unit_Entity;
-----------------------
-- First_Formal_Type --
-----------------------
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id is
Formal_Id : constant Entity_Id := First_Formal (Subp_Id);
Typ : Entity_Id;
begin
if Present (Formal_Id) then
Typ := Etype (Formal_Id);
-- Handle various combinations of concurrent and private types
loop
if Ekind (Typ) in E_Protected_Type | E_Task_Type
and then Present (Anonymous_Object (Typ))
then
Typ := Anonymous_Object (Typ);
elsif Is_Concurrent_Record_Type (Typ) then
Typ := Corresponding_Concurrent_Type (Typ);
elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
Typ := Full_View (Typ);
else
exit;
end if;
end loop;
return Typ;
end if;
return Empty;
end First_Formal_Type;
------------------------------
-- Guaranteed_ABE_Processor --
------------------------------
package body Guaranteed_ABE_Processor is
function Is_Guaranteed_ABE
(N : Node_Id;
Target_Decl : Node_Id;
Target_Body : Node_Id) return Boolean;
pragma Inline (Is_Guaranteed_ABE);
-- Determine whether scenario N with a target described by its initial
-- declaration Target_Decl and body Target_Decl results in a guaranteed
-- ABE.
procedure Process_Guaranteed_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Activation);
-- Perform common guaranteed ABE checks and diagnostics for activation
-- call Call which activates object Obj_Id of task type Task_Typ. Formal
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep denotes the representation of
-- the task type. In_State is the current state of the Processing phase.
procedure Process_Guaranteed_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Call);
-- Perform common guaranteed ABE checks and diagnostics for call Call
-- with representation Call_Rep. In_State denotes the current state of
-- the Processing phase.
procedure Process_Guaranteed_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Instantiation);
-- Perform common guaranteed ABE checks and diagnostics for instance
-- Inst with representation Inst_Rep. In_State is the current state of
-- the Processing phase.
-----------------------
-- Is_Guaranteed_ABE --
-----------------------
function Is_Guaranteed_ABE
(N : Node_Id;
Target_Decl : Node_Id;
Target_Body : Node_Id) return Boolean
is
Spec : Node_Id;
begin
-- Avoid cascaded errors if there were previous serious infractions.
-- As a result the scenario will not be treated as a guaranteed ABE.
-- This behavior parallels that of the old ABE mechanism.
if Serious_Errors_Detected > 0 then
return False;
-- The scenario and the target appear in the same context ignoring
-- enclosing library levels.
elsif In_Same_Context (N, Target_Decl) then
-- The target body has already been encountered. The scenario
-- results in a guaranteed ABE if it appears prior to the body.
if Present (Target_Body) then
return Earlier_In_Extended_Unit (N, Target_Body);
-- Otherwise the body has not been encountered yet. The scenario
-- is a guaranteed ABE since the body will appear later, unless
-- this is a null specification, which can occur if expansion is
-- disabled (e.g. -gnatc or GNATprove mode). It is assumed that
-- the caller has already ensured that the scenario is ABE-safe
-- because optional bodies are not considered here.
else
Spec := Specification (Target_Decl);
if Nkind (Spec) /= N_Procedure_Specification
or else not Null_Present (Spec)
then
return True;
end if;
end if;
end if;
return False;
end Is_Guaranteed_ABE;
----------------------------
-- Process_Guaranteed_ABE --
----------------------------
procedure Process_Guaranteed_ABE
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Only calls, instantiations, and task activations may result in a
-- guaranteed ABE.
-- Call or task activation
if Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Guaranteed_ABE_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scenario_Representation_Of (Scen, In_State),
Processor => Process_Guaranteed_ABE_Activation'Access,
In_State => In_State);
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Guaranteed_ABE_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_Guaranteed_ABE;
---------------------------------------
-- Process_Guaranteed_ABE_Activation --
---------------------------------------
procedure Process_Guaranteed_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Obj_Rep)
and then Elaboration_Checks_OK (Task_Rep);
-- A run-time ABE check may be installed only when the object and the
-- task type have active elaboration checks, and both are not ignored
-- Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the task is in the same unit, but outside this context.
--
-- task type Task_Typ; -- task declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- T : Task_Typ;
-- begin
-- <activation call> -- activation site
-- end;
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
--
-- In the example above, the context of X is the declarative list
-- of Proc. The "elaboration" of X may reach the activation of T
-- whose body is defined outside of X's context. The task body is
-- relevant only when Proc is invoked, but this happens only in
-- "normal" elaboration, therefore the task body must not be
-- considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the activation is ABE-safe
--
-- generic
-- package Gen is
-- task type Task_Typ;
-- end Gen;
--
-- package body Gen is
-- task body Task_Typ is
-- begin
-- ...
-- end Task_Typ;
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Nested is
-- package Inst is new Gen;
-- T : Inst.Task_Typ;
-- end Nested; -- safe activation
-- ...
elsif Is_Safe_Activation (Call, Task_Rep) then
return;
-- An activation call leads to a guaranteed ABE when the activation
-- call and the task appear within the same context ignoring library
-- levels, and the body of the task has not been seen yet or appears
-- after the activation call.
--
-- procedure Guaranteed_ABE is
-- task type Task_Typ;
--
-- package Nested is
-- T : Task_Typ;
-- <activation call> -- guaranteed ABE
-- end Nested;
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
-- ...
elsif Is_Guaranteed_ABE
(N => Call,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Task_Rep))
then
if Elaboration_Warnings_OK (Call_Rep) then
Error_Msg_Sloc := Sloc (Call);
Error_Msg_N
("??task & will be activated # before elaboration of its "
& "body", Obj_Id);
Error_Msg_N
("\Program_Error will be raised at run time", Obj_Id);
end if;
-- Mark the activation call as a guaranteed ABE
Set_Is_Known_Guaranteed_ABE (Call);
-- Install a run-time ABE failue because this activation call will
-- always result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Call,
Targ_Id => Task_Typ,
Targ_Rep => Task_Rep,
Disable => Obj_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Activation;
---------------------------------
-- Process_Guaranteed_ABE_Call --
---------------------------------
procedure Process_Guaranteed_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Call_Rep)
and then Elaboration_Checks_OK (Subp_Rep);
-- A run-time ABE check may be installed only when both the call
-- and the target have active elaboration checks, and both are not
-- ignored Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the target is in the same unit but outside this context.
--
-- function B ...; -- target declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- function B ... is
-- ...
-- end B;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach B which is
-- defined outside of X's context. B is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore B must not be considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the call is ABE-safe
--
-- generic
-- function Gen ...;
--
-- function Gen ... is
-- begin
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- function Inst is new Gen;
-- X : ... := Inst; -- safe call
-- ...
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then
return;
-- A call leads to a guaranteed ABE when the call and the target
-- appear within the same context ignoring library levels, and the
-- body of the target has not been seen yet or appears after the
-- call.
--
-- procedure Guaranteed_ABE is
-- function Func ...;
--
-- package Nested is
-- Obj : ... := Func; -- guaranteed ABE
-- end Nested;
--
-- function Func ... is
-- ...
-- end Func;
-- ...
elsif Is_Guaranteed_ABE
(N => Call,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Subp_Rep))
then
if Elaboration_Warnings_OK (Call_Rep) then
Error_Msg_NE
("??cannot call & before body seen", Call, Subp_Id);
Error_Msg_N ("\Program_Error will be raised at run time", Call);
end if;
-- Mark the call as a guaranteed ABE
Set_Is_Known_Guaranteed_ABE (Call);
-- Install a run-time ABE failure because the call will always
-- result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Call,
Targ_Id => Subp_Id,
Targ_Rep => Subp_Rep,
Disable => Call_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Call;
------------------------------------------
-- Process_Guaranteed_ABE_Instantiation --
------------------------------------------
procedure Process_Guaranteed_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Inst_Rep)
and then Elaboration_Checks_OK (Gen_Rep);
-- A run-time ABE check may be installed only when both the instance
-- and the generic have active elaboration checks and both are not
-- ignored Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the generic is in the same unit, but outside this
-- context.
--
-- generic
-- procedure Gen is ...; -- generic declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- procedure I is new Gen; -- instantiation site
-- ...
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- procedure Gen is
-- ...
-- end Gen;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach Gen which
-- appears outside of X's context. Gen is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore Gen must not be considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the instantiation is ABE-safe
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- package body Gen is
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Inst is new Gen (ABE); -- safe instantiation
-- ...
elsif Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then
return;
-- An instantiation leads to a guaranteed ABE when the instantiation
-- and the generic appear within the same context ignoring library
-- levels, and the body of the generic has not been seen yet or
-- appears after the instantiation.
--
-- procedure Guaranteed_ABE is
-- generic
-- procedure Gen;
--
-- package Nested is
-- procedure Inst is new Gen; -- guaranteed ABE
-- end Nested;
--
-- procedure Gen is
-- ...
-- end Gen;
-- ...
elsif Is_Guaranteed_ABE
(N => Inst,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Gen_Rep))
then
if Elaboration_Warnings_OK (Inst_Rep) then
Error_Msg_NE
("??cannot instantiate & before body seen", Inst, Gen_Id);
Error_Msg_N ("\Program_Error will be raised at run time", Inst);
end if;
-- Mark the instantiation as a guarantee ABE. This automatically
-- suppresses the instantiation of the generic body.
Set_Is_Known_Guaranteed_ABE (Inst);
-- Install a run-time ABE failure because the instantiation will
-- always result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Inst,
Targ_Id => Gen_Id,
Targ_Rep => Gen_Rep,
Disable => Inst_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Instantiation;
end Guaranteed_ABE_Processor;
--------------
-- Has_Body --
--------------
function Has_Body (Pack_Decl : Node_Id) return Boolean is
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id;
pragma Inline (Find_Corresponding_Body);
-- Try to locate the corresponding body of spec Spec_Id. If no body is
-- found, return Empty.
function Find_Body
(Spec_Id : Entity_Id;
From : Node_Id) return Node_Id;
pragma Inline (Find_Body);
-- Try to locate the corresponding body of spec Spec_Id in the node list
-- which follows arbitrary node From. If no body is found, return Empty.
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id;
pragma Inline (Load_Package_Body);
-- Attempt to load the body of unit Unit_Nam. If the load failed, return
-- Empty. If the compilation will not generate code, return Empty.
-----------------------------
-- Find_Corresponding_Body --
-----------------------------
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id is
Context : constant Entity_Id := Scope (Spec_Id);
Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
Body_Decl : Node_Id;
Body_Id : Entity_Id;
begin
if Is_Compilation_Unit (Spec_Id) then
Body_Id := Corresponding_Body (Spec_Decl);
if Present (Body_Id) then
return Unit_Declaration_Node (Body_Id);
-- The package is at the library and requires a body. Load the
-- corresponding body because the optional body may be declared
-- there.
elsif Unit_Requires_Body (Spec_Id) then
return
Load_Package_Body
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec_Decl))));
-- Otherwise there is no optional body
else
return Empty;
end if;
-- The immediate context is a package. The optional body may be
-- within the body of that package.
-- procedure Proc is
-- package Nested_1 is
-- package Nested_2 is
-- generic
-- package Pack is
-- end Pack;
-- end Nested_2;
-- end Nested_1;
-- package body Nested_1 is
-- package body Nested_2 is separate;
-- end Nested_1;
-- separate (Proc.Nested_1.Nested_2)
-- package body Nested_2 is
-- package body Pack is -- optional body
-- ...
-- end Pack;
-- end Nested_2;
elsif Is_Package_Or_Generic_Package (Context) then
Body_Decl := Find_Corresponding_Body (Context);
-- The optional body is within the body of the enclosing package
if Present (Body_Decl) then
return
Find_Body
(Spec_Id => Spec_Id,
From => First (Declarations (Body_Decl)));
-- Otherwise the enclosing package does not have a body. This may
-- be the result of an error or a genuine lack of a body.
else
return Empty;
end if;
-- Otherwise the immediate context is a body. The optional body may
-- be within the same list as the spec.
-- procedure Proc is
-- generic
-- package Pack is
-- end Pack;
-- package body Pack is -- optional body
-- ...
-- end Pack;
else
return
Find_Body
(Spec_Id => Spec_Id,
From => Next (Spec_Decl));
end if;
end Find_Corresponding_Body;
---------------
-- Find_Body --
---------------
function Find_Body
(Spec_Id : Entity_Id;
From : Node_Id) return Node_Id
is
Spec_Nam : constant Name_Id := Chars (Spec_Id);
Item : Node_Id;
Lib_Unit : Node_Id;
begin
Item := From;
while Present (Item) loop
-- The current item denotes the optional body
if Nkind (Item) = N_Package_Body
and then Chars (Defining_Entity (Item)) = Spec_Nam
then
return Item;
-- The current item denotes a stub, the optional body may be in
-- the subunit.
elsif Nkind (Item) = N_Package_Body_Stub
and then Chars (Defining_Entity (Item)) = Spec_Nam
then
Lib_Unit := Library_Unit (Item);
-- The corresponding subunit was previously loaded
if Present (Lib_Unit) then
return Lib_Unit;
-- Otherwise attempt to load the corresponding subunit
else
return Load_Package_Body (Get_Unit_Name (Item));
end if;
end if;
Next (Item);
end loop;
return Empty;
end Find_Body;
-----------------------
-- Load_Package_Body --
-----------------------
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id is
Body_Decl : Node_Id;
Unit_Num : Unit_Number_Type;
begin
-- The load is performed only when the compilation will generate code
if Operating_Mode = Generate_Code then
Unit_Num :=
Load_Unit
(Load_Name => Unit_Nam,
Required => False,
Subunit => False,
Error_Node => Pack_Decl);
-- The load failed most likely because the physical file is
-- missing.
if Unit_Num = No_Unit then
return Empty;
-- Otherwise the load was successful, return the body of the unit
else
Body_Decl := Unit (Cunit (Unit_Num));
-- If the unit is a subunit with an available proper body,
-- return the proper body.
if Nkind (Body_Decl) = N_Subunit
and then Present (Proper_Body (Body_Decl))
then
Body_Decl := Proper_Body (Body_Decl);
end if;
return Body_Decl;
end if;
end if;
return Empty;
end Load_Package_Body;
-- Local variables
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
-- Start of processing for Has_Body
begin
-- The body is available
if Present (Corresponding_Body (Pack_Decl)) then
return True;
-- The body is required if the package spec contains a construct which
-- requires a completion in a body.
elsif Unit_Requires_Body (Pack_Id) then
return True;
-- The body may be optional
else
return Present (Find_Corresponding_Body (Pack_Id));
end if;
end Has_Body;
----------
-- Hash --
----------
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type is
pragma Assert (Present (NE));
begin
return Bucket_Range_Type (NE);
end Hash;
--------------------------
-- In_External_Instance --
--------------------------
function In_External_Instance
(N : Node_Id;
Target_Decl : Node_Id) return Boolean
is
Inst : Node_Id;
Inst_Body : Node_Id;
Inst_Spec : Node_Id;
begin
Inst := Find_Enclosing_Instance (Target_Decl);
-- The target declaration appears within an instance spec. Visibility is
-- ignored because internally generated primitives for private types may
-- reside in the private declarations and still be invoked from outside.
if Present (Inst) and then Nkind (Inst) = N_Package_Declaration then
-- The scenario comes from the main unit and the instance does not
if In_Extended_Main_Code_Unit (N)
and then not In_Extended_Main_Code_Unit (Inst)
then
return True;
-- Otherwise the scenario must not appear within the instance spec or
-- body.
else
Spec_And_Body_From_Node
(N => Inst,
Spec_Decl => Inst_Spec,
Body_Decl => Inst_Body);
return not In_Subtree
(N => N,
Root1 => Inst_Spec,
Root2 => Inst_Body);
end if;
end if;
return False;
end In_External_Instance;
---------------------
-- In_Main_Context --
---------------------
function In_Main_Context (N : Node_Id) return Boolean is
begin
-- Scenarios outside the main unit are not considered because the ALI
-- information supplied to binde is for the main unit only.
if not In_Extended_Main_Code_Unit (N) then
return False;
-- Scenarios within internal units are not considered unless switch
-- -gnatdE (elaboration checks on predefined units) is in effect.
elsif not Debug_Flag_EE and then In_Internal_Unit (N) then
return False;
end if;
return True;
end In_Main_Context;
---------------------
-- In_Same_Context --
---------------------
function In_Same_Context
(N1 : Node_Id;
N2 : Node_Id;
Nested_OK : Boolean := False) return Boolean
is
function Find_Enclosing_Context (N : Node_Id) return Node_Id;
pragma Inline (Find_Enclosing_Context);
-- Return the nearest enclosing non-library-level or compilation unit
-- node which encapsulates arbitrary node N. Return Empty is no such
-- context is available.
function In_Nested_Context
(Outer : Node_Id;
Inner : Node_Id) return Boolean;
pragma Inline (In_Nested_Context);
-- Determine whether arbitrary node Outer encapsulates arbitrary node
-- Inner.
----------------------------
-- Find_Enclosing_Context --
----------------------------
function Find_Enclosing_Context (N : Node_Id) return Node_Id is
Context : Node_Id;
Par : Node_Id;
begin
Par := Parent (N);
while Present (Par) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Par) = N_Subunit then
Par := Corresponding_Stub (Par);
-- Stop the traversal when the nearest enclosing non-library-level
-- encapsulator has been reached.
elsif Is_Non_Library_Level_Encapsulator (Par) then
Context := Parent (Par);
-- The sole exception is when the encapsulator is the unit of
-- compilation because this case requires special processing
-- (see below).
if Present (Context)
and then Nkind (Context) = N_Compilation_Unit
then
null;
else
return Par;
end if;
-- Reaching a compilation unit node without hitting a non-library-
-- level encapsulator indicates that N is at the library level in
-- which case the compilation unit is the context.
elsif Nkind (Par) = N_Compilation_Unit then
return Par;
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Enclosing_Context;
-----------------------
-- In_Nested_Context --
-----------------------
function In_Nested_Context
(Outer : Node_Id;
Inner : Node_Id) return Boolean
is
Par : Node_Id;
begin
Par := Inner;
while Present (Par) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Par) = N_Subunit then
Par := Corresponding_Stub (Par);
elsif Par = Outer then
return True;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Nested_Context;
-- Local variables
Context_1 : constant Node_Id := Find_Enclosing_Context (N1);
Context_2 : constant Node_Id := Find_Enclosing_Context (N2);
-- Start of processing for In_Same_Context
begin
-- Both nodes appear within the same context
if Context_1 = Context_2 then
return True;
-- Both nodes appear in compilation units. Determine whether one unit
-- is the body of the other.
elsif Nkind (Context_1) = N_Compilation_Unit
and then Nkind (Context_2) = N_Compilation_Unit
then
return
Is_Same_Unit
(Unit_1 => Defining_Entity (Unit (Context_1)),
Unit_2 => Defining_Entity (Unit (Context_2)));
-- The context of N1 encloses the context of N2
elsif Nested_OK and then In_Nested_Context (Context_1, Context_2) then
return True;
end if;
return False;
end In_Same_Context;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
-- Set the soft link which enables Atree.Rewrite to update a scenario
-- each time it is transformed into another node.
Set_Rewriting_Proc (Update_Elaboration_Scenario'Access);
-- Create all internal data structures and activate the elaboration
-- phase of the compiler.
Initialize_All_Data_Structures;
Set_Elaboration_Phase (Active);
end Initialize;
------------------------------------
-- Initialize_All_Data_Structures --
------------------------------------
procedure Initialize_All_Data_Structures is
begin
Initialize_Body_Processor;
Initialize_Early_Call_Region_Processor;
Initialize_Elaborated_Units;
Initialize_Internal_Representation;
Initialize_Invocation_Graph;
Initialize_Scenario_Storage;
end Initialize_All_Data_Structures;
--------------------------
-- Instantiated_Generic --
--------------------------
function Instantiated_Generic (Inst : Node_Id) return Entity_Id is
begin
-- Traverse a possible chain of renamings to obtain the original generic
-- being instantiatied.
return Get_Renamed_Entity (Entity (Name (Inst)));
end Instantiated_Generic;
-----------------------------
-- Internal_Representation --
-----------------------------
package body Internal_Representation is
-----------
-- Types --
-----------
-- The following type represents the contents of a scenario
type Scenario_Rep_Record is record
Elab_Checks_OK : Boolean := False;
-- The status of elaboration checks for the scenario
Elab_Warnings_OK : Boolean := False;
-- The status of elaboration warnings for the scenario
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified;
-- The Ghost mode of the scenario
Kind : Scenario_Kind := No_Scenario;
-- The nature of the scenario
Level : Enclosing_Level_Kind := No_Level;
-- The enclosing level where the scenario resides
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified;
-- The SPARK mode of the scenario
Target : Entity_Id := Empty;
-- The target of the scenario
-- The following attributes are multiplexed and depend on the Kind of
-- the scenario. They are mapped as follows:
--
-- Call_Scenario
-- Is_Dispatching_Call (Flag_1)
--
-- Task_Activation_Scenario
-- Activated_Task_Objects (List_1)
-- Activated_Task_Type (Field_1)
--
-- Variable_Reference
-- Is_Read_Reference (Flag_1)
Flag_1 : Boolean := False;
Field_1 : Node_Or_Entity_Id := Empty;
List_1 : NE_List.Doubly_Linked_List := NE_List.Nil;
end record;
-- The following type represents the contents of a target
type Target_Rep_Record is record
Body_Decl : Node_Id := Empty;
-- The declaration of the target body
Elab_Checks_OK : Boolean := False;
-- The status of elaboration checks for the target
Elab_Warnings_OK : Boolean := False;
-- The status of elaboration warnings for the target
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified;
-- The Ghost mode of the target
Kind : Target_Kind := No_Target;
-- The nature of the target
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified;
-- The SPARK mode of the target
Spec_Decl : Node_Id := Empty;
-- The declaration of the target spec
Unit : Entity_Id := Empty;
-- The top unit where the target is declared
Version : Representation_Kind := No_Representation;
-- The version of the target representation
-- The following attributes are multiplexed and depend on the Kind of
-- the target. They are mapped as follows:
--
-- Subprogram_Target
-- Barrier_Body_Declaration (Field_1)
--
-- Variable_Target
-- Variable_Declaration (Field_1)
Field_1 : Node_Or_Entity_Id := Empty;
end record;
---------------------
-- Data structures --
---------------------
procedure Destroy (T_Id : in out Target_Rep_Id);
-- Destroy a target representation T_Id
package ETT_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Target_Rep_Id,
No_Value => No_Target_Rep,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates target representations to entities
Entity_To_Target_Map : ETT_Map.Dynamic_Hash_Table := ETT_Map.Nil;
procedure Destroy (S_Id : in out Scenario_Rep_Id);
-- Destroy a scenario representation S_Id
package NTS_Map is new Dynamic_Hash_Tables
(Key_Type => Node_Id,
Value_Type => Scenario_Rep_Id,
No_Value => No_Scenario_Rep,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates scenario representations to nodes
Node_To_Scenario_Map : NTS_Map.Dynamic_Hash_Table := NTS_Map.Nil;
-- The following table stores all scenario representations
package Scenario_Reps is new Table.Table
(Table_Index_Type => Scenario_Rep_Id,
Table_Component_Type => Scenario_Rep_Record,
Table_Low_Bound => First_Scenario_Rep,
Table_Initial => 1000,
Table_Increment => 200,
Table_Name => "Scenario_Reps");
-- The following table stores all target representations
package Target_Reps is new Table.Table
(Table_Index_Type => Target_Rep_Id,
Table_Component_Type => Target_Rep_Record,
Table_Low_Bound => First_Target_Rep,
Table_Initial => 1000,
Table_Increment => 200,
Table_Name => "Target_Reps");
--------------
-- Builders --
--------------
function Create_Access_Taken_Rep
(Attr : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Access_Taken_Rep);
-- Create the representation of 'Access attribute Attr
function Create_Call_Or_Task_Activation_Rep
(Call : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Call_Or_Task_Activation_Rep);
-- Create the representation of call or task activation Call
function Create_Derived_Type_Rep
(Typ_Decl : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Derived_Type_Rep);
-- Create the representation of a derived type described by declaration
-- Typ_Decl.
function Create_Generic_Rep
(Gen_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Generic_Rep);
-- Create the representation of generic Gen_Id
function Create_Instantiation_Rep
(Inst : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Instantiation_Rep);
-- Create the representation of instantiation Inst
function Create_Package_Rep
(Pack_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Package_Rep);
-- Create the representation of package Pack_Id
function Create_Protected_Entry_Rep
(PE_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Protected_Entry_Rep);
-- Create the representation of protected entry PE_Id
function Create_Protected_Subprogram_Rep
(PS_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Protected_Subprogram_Rep);
-- Create the representation of protected subprogram PS_Id
function Create_Refined_State_Pragma_Rep
(Prag : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Refined_State_Pragma_Rep);
-- Create the representation of Refined_State pragma Prag
function Create_Scenario_Rep
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Record;
pragma Inline (Create_Scenario_Rep);
-- Top level dispatcher. Create the representation of elaboration
-- scenario N. In_State is the current state of the Processing phase.
function Create_Subprogram_Rep
(Subp_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Subprogram_Rep);
-- Create the representation of entry, operator, or subprogram Subp_Id
function Create_Target_Rep
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Record;
pragma Inline (Create_Target_Rep);
-- Top level dispatcher. Create the representation of elaboration target
-- Id. In_State is the current state of the Processing phase.
function Create_Task_Entry_Rep
(TE_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Task_Entry_Rep);
-- Create the representation of task entry TE_Id
function Create_Task_Rep (Task_Typ : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Task_Rep);
-- Create the representation of task type Typ
function Create_Variable_Assignment_Rep
(Asmt : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Variable_Assignment_Rep);
-- Create the representation of variable assignment Asmt
function Create_Variable_Reference_Rep
(Ref : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Variable_Reference_Rep);
-- Create the representation of variable reference Ref
function Create_Variable_Rep
(Var_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Variable_Rep);
-- Create the representation of variable Var_Id
-----------------------
-- Local subprograms --
-----------------------
function Ghost_Mode_Of_Entity
(Id : Entity_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of_Entity);
-- Obtain the extended Ghost mode of arbitrary entity Id
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of_Node);
-- Obtain the extended Ghost mode of arbitrary node N
function Present (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Present);
-- Determine whether scenario representation S_Id exists
function Present (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Present);
-- Determine whether target representation T_Id exists
function SPARK_Mode_Of_Entity
(Id : Entity_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of_Entity);
-- Obtain the extended SPARK mode of arbitrary entity Id
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of_Node);
-- Obtain the extended SPARK mode of arbitrary node N
function To_Ghost_Mode
(Ignored_Status : Boolean) return Extended_Ghost_Mode;
pragma Inline (To_Ghost_Mode);
-- Convert a Ghost mode indicated by Ignored_Status into its extended
-- equivalent.
function To_SPARK_Mode (On_Status : Boolean) return Extended_SPARK_Mode;
pragma Inline (To_SPARK_Mode);
-- Convert a SPARK mode indicated by On_Status into its extended
-- equivalent.
function Version (T_Id : Target_Rep_Id) return Representation_Kind;
pragma Inline (Version);
-- Obtain the version of target representation T_Id
----------------------------
-- Activated_Task_Objects --
----------------------------
function Activated_Task_Objects
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
return Scenario_Reps.Table (S_Id).List_1;
end Activated_Task_Objects;
-------------------------
-- Activated_Task_Type --
-------------------------
function Activated_Task_Type
(S_Id : Scenario_Rep_Id) return Entity_Id
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
return Scenario_Reps.Table (S_Id).Field_1;
end Activated_Task_Type;
------------------------------
-- Barrier_Body_Declaration --
------------------------------
function Barrier_Body_Declaration
(T_Id : Target_Rep_Id) return Node_Id
is
pragma Assert (Present (T_Id));
pragma Assert (Kind (T_Id) = Subprogram_Target);
begin
return Target_Reps.Table (T_Id).Field_1;
end Barrier_Body_Declaration;
----------------------
-- Body_Declaration --
----------------------
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Body_Decl;
end Body_Declaration;
-----------------------------
-- Create_Access_Taken_Rep --
-----------------------------
function Create_Access_Taken_Rep
(Attr : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Attr);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Attr);
Rec.GM := Is_Checked_Or_Not_Specified;
Rec.SM := SPARK_Mode_Of_Node (Attr);
Rec.Kind := Access_Taken_Scenario;
Rec.Target := Canonical_Subprogram (Entity (Prefix (Attr)));
return Rec;
end Create_Access_Taken_Rep;
----------------------------------------
-- Create_Call_Or_Task_Activation_Rep --
----------------------------------------
function Create_Call_Or_Task_Activation_Rep
(Call : Node_Id) return Scenario_Rep_Record
is
Subp_Id : constant Entity_Id := Canonical_Subprogram (Target (Call));
Kind : Scenario_Kind;
Rec : Scenario_Rep_Record;
begin
if Is_Activation_Proc (Subp_Id) then
Kind := Task_Activation_Scenario;
else
Kind := Call_Scenario;
end if;
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Call);
Rec.GM := Ghost_Mode_Of_Node (Call);
Rec.SM := SPARK_Mode_Of_Node (Call);
Rec.Kind := Kind;
Rec.Target := Subp_Id;
-- Scenario-specific attributes
Rec.Flag_1 := Is_Dispatching_Call (Call); -- Dispatching_Call
return Rec;
end Create_Call_Or_Task_Activation_Rep;
-----------------------------
-- Create_Derived_Type_Rep --
-----------------------------
function Create_Derived_Type_Rep
(Typ_Decl : Node_Id) return Scenario_Rep_Record
is
Typ : constant Entity_Id := Defining_Entity (Typ_Decl);
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := False; -- not relevant
Rec.Elab_Warnings_OK := False; -- not relevant
Rec.GM := Ghost_Mode_Of_Entity (Typ);
Rec.SM := SPARK_Mode_Of_Entity (Typ);
Rec.Kind := Derived_Type_Scenario;
Rec.Target := Typ;
return Rec;
end Create_Derived_Type_Rep;
------------------------
-- Create_Generic_Rep --
------------------------
function Create_Generic_Rep
(Gen_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Generic_Target;
Spec_And_Body_From_Entity
(Id => Gen_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Generic_Rep;
------------------------------
-- Create_Instantiation_Rep --
------------------------------
function Create_Instantiation_Rep
(Inst : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Inst);
Rec.GM := Ghost_Mode_Of_Node (Inst);
Rec.SM := SPARK_Mode_Of_Node (Inst);
Rec.Kind := Instantiation_Scenario;
Rec.Target := Instantiated_Generic (Inst);
return Rec;
end Create_Instantiation_Rep;
------------------------
-- Create_Package_Rep --
------------------------
function Create_Package_Rep
(Pack_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Package_Target;
Spec_And_Body_From_Entity
(Id => Pack_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Package_Rep;
--------------------------------
-- Create_Protected_Entry_Rep --
--------------------------------
function Create_Protected_Entry_Rep
(PE_Id : Entity_Id) return Target_Rep_Record
is
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PE_Id);
Barf_Id : Entity_Id;
Dummy : Node_Id;
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- When the entry [family] has already been expanded, it carries both
-- the procedure which emulates the behavior of the entry [family] as
-- well as the barrier function.
if Present (Prot_Id) then
Barf_Id := Barrier_Function (PE_Id);
Spec_Id := Prot_Id;
-- Otherwise no expansion took place
else
Barf_Id := Empty;
Spec_Id := PE_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
-- Target-specific attributes
if Present (Barf_Id) then
Spec_And_Body_From_Entity
(Id => Barf_Id,
Body_Decl => Rec.Field_1, -- Barrier_Body_Declaration
Spec_Decl => Dummy);
end if;
return Rec;
end Create_Protected_Entry_Rep;
-------------------------------------
-- Create_Protected_Subprogram_Rep --
-------------------------------------
function Create_Protected_Subprogram_Rep
(PS_Id : Entity_Id) return Target_Rep_Record
is
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PS_Id);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- When the protected subprogram has already been expanded, it
-- carries the subprogram which seizes the lock and invokes the
-- original statements.
if Present (Prot_Id) then
Spec_Id := Prot_Id;
-- Otherwise no expansion took place
else
Spec_Id := PS_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Protected_Subprogram_Rep;
-------------------------------------
-- Create_Refined_State_Pragma_Rep --
-------------------------------------
function Create_Refined_State_Pragma_Rep
(Prag : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := False; -- not relevant
Rec.Elab_Warnings_OK := False; -- not relevant
Rec.GM :=
To_Ghost_Mode (Is_Ignored_Ghost_Pragma (Prag));
Rec.SM := Is_Off_Or_Not_Specified;
Rec.Kind := Refined_State_Pragma_Scenario;
Rec.Target := Empty;
return Rec;
end Create_Refined_State_Pragma_Rep;
-------------------------
-- Create_Scenario_Rep --
-------------------------
function Create_Scenario_Rep
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Record
is
pragma Unreferenced (In_State);
Rec : Scenario_Rep_Record;
begin
if Is_Suitable_Access_Taken (N) then
Rec := Create_Access_Taken_Rep (N);
elsif Is_Suitable_Call (N) then
Rec := Create_Call_Or_Task_Activation_Rep (N);
elsif Is_Suitable_Instantiation (N) then
Rec := Create_Instantiation_Rep (N);
elsif Is_Suitable_SPARK_Derived_Type (N) then
Rec := Create_Derived_Type_Rep (N);
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
Rec := Create_Refined_State_Pragma_Rep (N);
elsif Is_Suitable_Variable_Assignment (N) then
Rec := Create_Variable_Assignment_Rep (N);
elsif Is_Suitable_Variable_Reference (N) then
Rec := Create_Variable_Reference_Rep (N);
else
pragma Assert (False);
return Rec;
end if;
-- Common scenario attributes
Rec.Level := Find_Enclosing_Level (N);
return Rec;
end Create_Scenario_Rep;
---------------------------
-- Create_Subprogram_Rep --
---------------------------
function Create_Subprogram_Rep
(Subp_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
Spec_Id := Subp_Id;
-- The elaboration target denotes an internal function that returns a
-- constrained array type in a SPARK-to-C compilation. In this case
-- the function receives a corresponding procedure which has an out
-- parameter. The proper body for ABE checks and diagnostics is that
-- of the procedure.
if Ekind (Spec_Id) = E_Function
and then Rewritten_For_C (Spec_Id)
then
Spec_Id := Corresponding_Procedure (Spec_Id);
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Subprogram_Rep;
-----------------------
-- Create_Target_Rep --
-----------------------
function Create_Target_Rep
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
if Is_Generic_Unit (Id) then
Rec := Create_Generic_Rep (Id);
elsif Is_Protected_Entry (Id) then
Rec := Create_Protected_Entry_Rep (Id);
elsif Is_Protected_Subp (Id) then
Rec := Create_Protected_Subprogram_Rep (Id);
elsif Is_Task_Entry (Id) then
Rec := Create_Task_Entry_Rep (Id);
elsif Is_Task_Type (Id) then
Rec := Create_Task_Rep (Id);
elsif Ekind (Id) in E_Constant | E_Variable then
Rec := Create_Variable_Rep (Id);
elsif Ekind (Id) in E_Entry | E_Function | E_Operator | E_Procedure
then
Rec := Create_Subprogram_Rep (Id);
elsif Ekind (Id) = E_Package then
Rec := Create_Package_Rep (Id);
else
pragma Assert (False);
return Rec;
end if;
-- Common target attributes
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Id);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Id);
Rec.GM := Ghost_Mode_Of_Entity (Id);
Rec.SM := SPARK_Mode_Of_Entity (Id);
Rec.Unit := Find_Top_Unit (Id);
Rec.Version := In_State.Representation;
return Rec;
end Create_Target_Rep;
---------------------------
-- Create_Task_Entry_Rep --
---------------------------
function Create_Task_Entry_Rep
(TE_Id : Entity_Id) return Target_Rep_Record
is
Task_Typ : constant Entity_Id := Non_Private_View (Scope (TE_Id));
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- The task type has already been expanded, it carries the procedure
-- which emulates the behavior of the task body.
if Present (Task_Body_Id) then
Spec_Id := Task_Body_Id;
-- Otherwise no expansion took place
else
Spec_Id := TE_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Task_Entry_Rep;
---------------------
-- Create_Task_Rep --
---------------------
function Create_Task_Rep
(Task_Typ : Entity_Id) return Target_Rep_Record
is
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- The task type has already been expanded, it carries the procedure
-- which emulates the behavior of the task body.
if Present (Task_Body_Id) then
Spec_Id := Task_Body_Id;
-- Otherwise no expansion took place
else
Spec_Id := Task_Typ;
end if;
Rec.Kind := Task_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Task_Rep;
------------------------------------
-- Create_Variable_Assignment_Rep --
------------------------------------
function Create_Variable_Assignment_Rep
(Asmt : Node_Id) return Scenario_Rep_Record
is
Var_Id : constant Entity_Id := Entity (Assignment_Target (Asmt));
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Asmt);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Var_Id);
Rec.GM := Ghost_Mode_Of_Node (Asmt);
Rec.SM := SPARK_Mode_Of_Node (Asmt);
Rec.Kind := Variable_Assignment_Scenario;
Rec.Target := Var_Id;
return Rec;
end Create_Variable_Assignment_Rep;
-----------------------------------
-- Create_Variable_Reference_Rep --
-----------------------------------
function Create_Variable_Reference_Rep
(Ref : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Ref);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Ref);
Rec.GM := Ghost_Mode_Of_Node (Ref);
Rec.SM := SPARK_Mode_Of_Node (Ref);
Rec.Kind := Variable_Reference_Scenario;
Rec.Target := Target (Ref);
-- Scenario-specific attributes
Rec.Flag_1 := Is_Read (Ref); -- Is_Read_Reference
return Rec;
end Create_Variable_Reference_Rep;
-------------------------
-- Create_Variable_Rep --
-------------------------
function Create_Variable_Rep
(Var_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Variable_Target;
-- Target-specific attributes
Rec.Field_1 := Declaration_Node (Var_Id); -- Variable_Declaration
return Rec;
end Create_Variable_Rep;
-------------
-- Destroy --
-------------
procedure Destroy (S_Id : in out Scenario_Rep_Id) is
pragma Unreferenced (S_Id);
begin
null;
end Destroy;
-------------
-- Destroy --
-------------
procedure Destroy (T_Id : in out Target_Rep_Id) is
pragma Unreferenced (T_Id);
begin
null;
end Destroy;
--------------------------------
-- Disable_Elaboration_Checks --
--------------------------------
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id) is
pragma Assert (Present (S_Id));
begin
Scenario_Reps.Table (S_Id).Elab_Checks_OK := False;
end Disable_Elaboration_Checks;
--------------------------------
-- Disable_Elaboration_Checks --
--------------------------------
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id) is
pragma Assert (Present (T_Id));
begin
Target_Reps.Table (T_Id).Elab_Checks_OK := False;
end Disable_Elaboration_Checks;
---------------------------
-- Elaboration_Checks_OK --
---------------------------
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Elab_Checks_OK;
end Elaboration_Checks_OK;
---------------------------
-- Elaboration_Checks_OK --
---------------------------
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Elab_Checks_OK;
end Elaboration_Checks_OK;
-----------------------------
-- Elaboration_Warnings_OK --
-----------------------------
function Elaboration_Warnings_OK
(S_Id : Scenario_Rep_Id) return Boolean
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Elab_Warnings_OK;
end Elaboration_Warnings_OK;
-----------------------------
-- Elaboration_Warnings_OK --
-----------------------------
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Elab_Warnings_OK;
end Elaboration_Warnings_OK;
--------------------------------------
-- Finalize_Internal_Representation --
--------------------------------------
procedure Finalize_Internal_Representation is
begin
ETT_Map.Destroy (Entity_To_Target_Map);
NTS_Map.Destroy (Node_To_Scenario_Map);
end Finalize_Internal_Representation;
-------------------
-- Ghost_Mode_Of --
-------------------
function Ghost_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).GM;
end Ghost_Mode_Of;
-------------------
-- Ghost_Mode_Of --
-------------------
function Ghost_Mode_Of
(T_Id : Target_Rep_Id) return Extended_Ghost_Mode
is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).GM;
end Ghost_Mode_Of;
--------------------------
-- Ghost_Mode_Of_Entity --
--------------------------
function Ghost_Mode_Of_Entity
(Id : Entity_Id) return Extended_Ghost_Mode
is
begin
return To_Ghost_Mode (Is_Ignored_Ghost_Entity (Id));
end Ghost_Mode_Of_Entity;
------------------------
-- Ghost_Mode_Of_Node --
------------------------
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode is
begin
return To_Ghost_Mode (Is_Ignored_Ghost_Node (N));
end Ghost_Mode_Of_Node;
----------------------------------------
-- Initialize_Internal_Representation --
----------------------------------------
procedure Initialize_Internal_Representation is
begin
Entity_To_Target_Map := ETT_Map.Create (500);
Node_To_Scenario_Map := NTS_Map.Create (500);
end Initialize_Internal_Representation;
-------------------------
-- Is_Dispatching_Call --
-------------------------
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Call_Scenario);
begin
return Scenario_Reps.Table (S_Id).Flag_1;
end Is_Dispatching_Call;
-----------------------
-- Is_Read_Reference --
-----------------------
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Variable_Reference_Scenario);
begin
return Scenario_Reps.Table (S_Id).Flag_1;
end Is_Read_Reference;
----------
-- Kind --
----------
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Kind;
end Kind;
----------
-- Kind --
----------
function Kind (T_Id : Target_Rep_Id) return Target_Kind is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Kind;
end Kind;
-----------
-- Level --
-----------
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Level;
end Level;
-------------
-- Present --
-------------
function Present (S_Id : Scenario_Rep_Id) return Boolean is
begin
return S_Id /= No_Scenario_Rep;
end Present;
-------------
-- Present --
-------------
function Present (T_Id : Target_Rep_Id) return Boolean is
begin
return T_Id /= No_Target_Rep;
end Present;
--------------------------------
-- Scenario_Representation_Of --
--------------------------------
function Scenario_Representation_Of
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Id
is
S_Id : Scenario_Rep_Id;
begin
S_Id := NTS_Map.Get (Node_To_Scenario_Map, N);
-- The elaboration scenario lacks a representation. This indicates
-- that the scenario is encountered for the first time. Create the
-- representation of it.
if not Present (S_Id) then
Scenario_Reps.Append (Create_Scenario_Rep (N, In_State));
S_Id := Scenario_Reps.Last;
-- Associate the internal representation with the elaboration
-- scenario.
NTS_Map.Put (Node_To_Scenario_Map, N, S_Id);
end if;
pragma Assert (Present (S_Id));
return S_Id;
end Scenario_Representation_Of;
--------------------------------
-- Set_Activated_Task_Objects --
--------------------------------
procedure Set_Activated_Task_Objects
(S_Id : Scenario_Rep_Id;
Task_Objs : NE_List.Doubly_Linked_List)
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
Scenario_Reps.Table (S_Id).List_1 := Task_Objs;
end Set_Activated_Task_Objects;
-----------------------------
-- Set_Activated_Task_Type --
-----------------------------
procedure Set_Activated_Task_Type
(S_Id : Scenario_Rep_Id;
Task_Typ : Entity_Id)
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
Scenario_Reps.Table (S_Id).Field_1 := Task_Typ;
end Set_Activated_Task_Type;
-------------------
-- SPARK_Mode_Of --
-------------------
function SPARK_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).SM;
end SPARK_Mode_Of;
-------------------
-- SPARK_Mode_Of --
-------------------
function SPARK_Mode_Of
(T_Id : Target_Rep_Id) return Extended_SPARK_Mode
is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).SM;
end SPARK_Mode_Of;
--------------------------
-- SPARK_Mode_Of_Entity --
--------------------------
function SPARK_Mode_Of_Entity
(Id : Entity_Id) return Extended_SPARK_Mode
is
Prag : constant Node_Id := SPARK_Pragma (Id);
begin
return
To_SPARK_Mode
(Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On);
end SPARK_Mode_Of_Entity;
------------------------
-- SPARK_Mode_Of_Node --
------------------------
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode is
begin
return To_SPARK_Mode (Is_SPARK_Mode_On_Node (N));
end SPARK_Mode_Of_Node;
----------------------
-- Spec_Declaration --
----------------------
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Spec_Decl;
end Spec_Declaration;
------------
-- Target --
------------
function Target (S_Id : Scenario_Rep_Id) return Entity_Id is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Target;
end Target;
------------------------------
-- Target_Representation_Of --
------------------------------
function Target_Representation_Of
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Id
is
T_Id : Target_Rep_Id;
begin
T_Id := ETT_Map.Get (Entity_To_Target_Map, Id);
-- The elaboration target lacks an internal representation. This
-- indicates that the target is encountered for the first time.
-- Create the internal representation of it.
if not Present (T_Id) then
Target_Reps.Append (Create_Target_Rep (Id, In_State));
T_Id := Target_Reps.Last;
-- Associate the internal representation with the elaboration
-- target.
ETT_Map.Put (Entity_To_Target_Map, Id, T_Id);
-- The Processing phase is working with a partially analyzed tree,
-- where various attributes become available as analysis continues.
-- This case arrises in the context of guaranteed ABE processing.
-- Update the existing representation by including new attributes.
elsif In_State.Representation = Inconsistent_Representation then
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State);
-- Otherwise the Processing phase imposes a particular representation
-- version which is not satisfied by the target. This case arrises
-- when the Processing phase switches from guaranteed ABE checks and
-- diagnostics to some other mode of operation. Update the existing
-- representation to include all attributes.
elsif In_State.Representation /= Version (T_Id) then
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State);
end if;
pragma Assert (Present (T_Id));
return T_Id;
end Target_Representation_Of;
-------------------
-- To_Ghost_Mode --
-------------------
function To_Ghost_Mode
(Ignored_Status : Boolean) return Extended_Ghost_Mode
is
begin
if Ignored_Status then
return Is_Ignored;
else
return Is_Checked_Or_Not_Specified;
end if;
end To_Ghost_Mode;
-------------------
-- To_SPARK_Mode --
-------------------
function To_SPARK_Mode
(On_Status : Boolean) return Extended_SPARK_Mode
is
begin
if On_Status then
return Is_On;
else
return Is_Off_Or_Not_Specified;
end if;
end To_SPARK_Mode;
----------
-- Unit --
----------
function Unit (T_Id : Target_Rep_Id) return Entity_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Unit;
end Unit;
--------------------------
-- Variable_Declaration --
--------------------------
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
pragma Assert (Kind (T_Id) = Variable_Target);
begin
return Target_Reps.Table (T_Id).Field_1;
end Variable_Declaration;
-------------
-- Version --
-------------
function Version (T_Id : Target_Rep_Id) return Representation_Kind is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Version;
end Version;
end Internal_Representation;
----------------------
-- Invocation_Graph --
----------------------
package body Invocation_Graph is
-----------
-- Types --
-----------
-- The following type represents simplified version of an invocation
-- relation.
type Invoker_Target_Relation is record
Invoker : Entity_Id := Empty;
Target : Entity_Id := Empty;
end record;
-- The following variables define the entities of the dummy elaboration
-- procedures used as origins of library level paths.
Elab_Body_Id : Entity_Id := Empty;
Elab_Spec_Id : Entity_Id := Empty;
---------------------
-- Data structures --
---------------------
-- The following set contains all declared invocation constructs. It
-- ensures that the same construct is not declared multiple times in
-- the ALI file of the main unit.
Saved_Constructs_Set : NE_Set.Membership_Set := NE_Set.Nil;
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type;
-- Obtain the hash value of pair Key
package IR_Set is new Membership_Sets
(Element_Type => Invoker_Target_Relation,
"=" => "=",
Hash => Hash);
-- The following set contains all recorded simple invocation relations.
-- It ensures that multiple relations involving the same invoker and
-- target do not appear in the ALI file of the main unit.
Saved_Relations_Set : IR_Set.Membership_Set := IR_Set.Nil;
--------------
-- Builders --
--------------
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id;
pragma Inline (Signature_Of);
-- Obtain the invication signature id of arbitrary entity Id
-----------------------
-- Local subprograms --
-----------------------
procedure Build_Elaborate_Body_Procedure;
pragma Inline (Build_Elaborate_Body_Procedure);
-- Create a dummy elaborate body procedure and store its entity in
-- Elab_Body_Id.
procedure Build_Elaborate_Procedure
(Proc_Id : out Entity_Id;
Proc_Nam : Name_Id;
Loc : Source_Ptr);
pragma Inline (Build_Elaborate_Procedure);
-- Create a dummy elaborate procedure with name Proc_Nam and source
-- location Loc. The entity is returned in Proc_Id.
procedure Build_Elaborate_Spec_Procedure;
pragma Inline (Build_Elaborate_Spec_Procedure);
-- Create a dummy elaborate spec procedure and store its entity in
-- Elab_Spec_Id.
function Build_Subprogram_Invocation
(Subp_Id : Entity_Id) return Node_Id;
pragma Inline (Build_Subprogram_Invocation);
-- Create a dummy call marker that invokes subprogram Subp_Id
function Build_Task_Activation
(Task_Typ : Entity_Id;
In_State : Processing_In_State) return Node_Id;
pragma Inline (Build_Task_Activation);
-- Create a dummy call marker that activates an anonymous task object of
-- type Task_Typ.
procedure Declare_Invocation_Construct
(Constr_Id : Entity_Id;
In_State : Processing_In_State);
pragma Inline (Declare_Invocation_Construct);
-- Declare invocation construct Constr_Id by creating a declaration for
-- it in the ALI file of the main unit. In_State is the current state of
-- the Processing phase.
function Invocation_Graph_Recording_OK return Boolean;
pragma Inline (Invocation_Graph_Recording_OK);
-- Determine whether the invocation graph can be recorded
function Is_Invocation_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Invocation_Scenario);
-- Determine whether node N is a suitable scenario for invocation graph
-- recording purposes.
function Is_Invocation_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Invocation_Target);
-- Determine whether arbitrary entity Id denotes an invocation target
function Is_Saved_Construct (Constr : Entity_Id) return Boolean;
pragma Inline (Is_Saved_Construct);
-- Determine whether invocation construct Constr has already been
-- declared in the ALI file of the main unit.
function Is_Saved_Relation
(Rel : Invoker_Target_Relation) return Boolean;
pragma Inline (Is_Saved_Relation);
-- Determine whether simple invocation relation Rel has already been
-- recorded in the ALI file of the main unit.
procedure Process_Declarations
(Decls : List_Id;
In_State : Processing_In_State);
pragma Inline (Process_Declarations);
-- Process declaration list Decls by processing all invocation scenarios
-- within it.
procedure Process_Freeze_Node
(Fnode : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Freeze_Node);
-- Process freeze node Fnode by processing all invocation scenarios in
-- its Actions list.
procedure Process_Invocation_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Activation);
-- Process activation call Call which activates object Obj_Id of task
-- type Task_Typ by processing all invocation scenarios within the task
-- body. Call_Rep is the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep is the representation of the
-- task type. In_State is the current state of the Processing phase.
procedure Process_Invocation_Body_Scenarios;
pragma Inline (Process_Invocation_Body_Scenarios);
-- Process all library level body scenarios
procedure Process_Invocation_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Call);
-- Process invocation call scenario Call with representation Call_Rep.
-- In_State is the current state of the Processing phase.
procedure Process_Invocation_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Instantiation);
-- Process invocation instantiation scenario Inst with representation
-- Inst_Rep. In_State is the current state of the Processing phase.
procedure Process_Invocation_Scenario
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Scenario);
-- Process single invocation scenario N. In_State is the current state
-- of the Processing phase.
procedure Process_Invocation_Scenarios
(Iter : in out NE_Set.Iterator;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Scenarios);
-- Process all invocation scenarios obtained via iterator Iter. In_State
-- is the current state of the Processing phase.
procedure Process_Invocation_Spec_Scenarios;
pragma Inline (Process_Invocation_Spec_Scenarios);
-- Process all library level spec scenarios
procedure Process_Main_Unit;
pragma Inline (Process_Main_Unit);
-- Process all invocation scenarios within the main unit
procedure Process_Package_Declaration
(Pack_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Package_Declaration);
-- Process package declaration Pack_Decl by processing all invocation
-- scenarios in its visible and private declarations. If the main unit
-- contains a generic, the declarations of the body are also examined.
-- In_State is the current state of the Processing phase.
procedure Process_Protected_Type_Declaration
(Prot_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Protected_Type_Declaration);
-- Process the declarations of protected type Prot_Decl. In_State is the
-- current state of the Processing phase.
procedure Process_Subprogram_Declaration
(Subp_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Subprogram_Declaration);
-- Process subprogram declaration Subp_Decl by processing all invocation
-- scenarios within its body. In_State denotes the current state of the
-- Processing phase.
procedure Process_Subprogram_Instantiation
(Inst : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Subprogram_Instantiation);
-- Process subprogram instantiation Inst. In_State is the current state
-- of the Processing phase.
procedure Process_Task_Type_Declaration
(Task_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Task_Type_Declaration);
-- Process task declaration Task_Decl by processing all invocation
-- scenarios within its body. In_State is the current state of the
-- Processing phase.
procedure Record_Full_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Full_Invocation_Path);
-- Record all relations between scenario pairs found in the stack of
-- active scenarios. In_State is the current state of the Processing
-- phase.
procedure Record_Invocation_Graph_Encoding;
pragma Inline (Record_Invocation_Graph_Encoding);
-- Record the encoding format used to capture information related to
-- invocation constructs and relations.
procedure Record_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Invocation_Path);
-- Record the invocation relations found within the path represented in
-- the active scenario stack. In_State denotes the current state of the
-- Processing phase.
procedure Record_Simple_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Simple_Invocation_Path);
-- Record a single relation from the start to the end of the stack of
-- active scenarios. In_State is the current state of the Processing
-- phase.
procedure Record_Invocation_Relation
(Invk_Id : Entity_Id;
Targ_Id : Entity_Id;
In_State : Processing_In_State);
pragma Inline (Record_Invocation_Relation);
-- Record an invocation relation with invoker Invk_Id and target Targ_Id
-- by creating an entry for it in the ALI file of the main unit. Formal
-- In_State denotes the current state of the Processing phase.
procedure Set_Is_Saved_Construct (Constr : Entity_Id);
pragma Inline (Set_Is_Saved_Construct);
-- Mark invocation construct Constr as declared in the ALI file of the
-- main unit.
procedure Set_Is_Saved_Relation (Rel : Invoker_Target_Relation);
pragma Inline (Set_Is_Saved_Relation);
-- Mark simple invocation relation Rel as recorded in the ALI file of
-- the main unit.
function Target_Of
(Pos : Active_Scenario_Pos;
In_State : Processing_In_State) return Entity_Id;
pragma Inline (Target_Of);
-- Given position within the active scenario stack Pos, obtain the
-- target of the indicated scenario. In_State is the current state
-- of the Processing phase.
procedure Traverse_Invocation_Body
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Traverse_Invocation_Body);
-- Traverse subprogram body N looking for suitable invocation scenarios
-- that need to be processed for invocation graph recording purposes.
-- In_State is the current state of the Processing phase.
procedure Write_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Write_Invocation_Path);
-- Write out a path represented by the active scenario on the stack to
-- standard output. In_State denotes the current state of the Processing
-- phase.
------------------------------------
-- Build_Elaborate_Body_Procedure --
------------------------------------
procedure Build_Elaborate_Body_Procedure is
Body_Decl : Node_Id;
Spec_Decl : Node_Id;
begin
-- Nothing to do when a previous call already created the procedure
if Present (Elab_Body_Id) then
return;
end if;
Spec_And_Body_From_Entity
(Id => Main_Unit_Entity,
Body_Decl => Body_Decl,
Spec_Decl => Spec_Decl);
pragma Assert (Present (Body_Decl));
Build_Elaborate_Procedure
(Proc_Id => Elab_Body_Id,
Proc_Nam => Name_B,
Loc => Sloc (Body_Decl));
end Build_Elaborate_Body_Procedure;
-------------------------------
-- Build_Elaborate_Procedure --
-------------------------------
procedure Build_Elaborate_Procedure
(Proc_Id : out Entity_Id;
Proc_Nam : Name_Id;
Loc : Source_Ptr)
is
Proc_Decl : Node_Id;
pragma Unreferenced (Proc_Decl);
begin
Proc_Id := Make_Defining_Identifier (Loc, Proc_Nam);
-- Partially decorate the elaboration procedure because it will not
-- be insertred into the tree and analyzed.
Mutate_Ekind (Proc_Id, E_Procedure);
Set_Etype (Proc_Id, Standard_Void_Type);
Set_Scope (Proc_Id, Unique_Entity (Main_Unit_Entity));
-- Create a dummy declaration for the elaboration procedure. The
-- declaration does not need to be syntactically legal, but must
-- carry an accurate source location.
Proc_Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Proc_Id),
Declarations => No_List,
Handled_Statement_Sequence => Empty);
end Build_Elaborate_Procedure;
------------------------------------
-- Build_Elaborate_Spec_Procedure --
------------------------------------
procedure Build_Elaborate_Spec_Procedure is
Body_Decl : Node_Id;
Spec_Decl : Node_Id;
begin
-- Nothing to do when a previous call already created the procedure
if Present (Elab_Spec_Id) then
return;
end if;
Spec_And_Body_From_Entity
(Id => Main_Unit_Entity,
Body_Decl => Body_Decl,
Spec_Decl => Spec_Decl);
pragma Assert (Present (Spec_Decl));
Build_Elaborate_Procedure
(Proc_Id => Elab_Spec_Id,
Proc_Nam => Name_S,
Loc => Sloc (Spec_Decl));
end Build_Elaborate_Spec_Procedure;
---------------------------------
-- Build_Subprogram_Invocation --
---------------------------------
function Build_Subprogram_Invocation
(Subp_Id : Entity_Id) return Node_Id
is
Marker : constant Node_Id := Make_Call_Marker (Sloc (Subp_Id));
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
begin
-- Create a dummy call marker which invokes the subprogram
Set_Is_Declaration_Level_Node (Marker, False);
Set_Is_Dispatching_Call (Marker, False);
Set_Is_Elaboration_Checks_OK_Node (Marker, False);
Set_Is_Elaboration_Warnings_OK_Node (Marker, False);
Set_Is_Ignored_Ghost_Node (Marker, False);
Set_Is_Preelaborable_Call (Marker, False);
Set_Is_Source_Call (Marker, False);
Set_Is_SPARK_Mode_On_Node (Marker, False);
-- Invoke the uniform canonical entity of the subprogram
Set_Target (Marker, Canonical_Subprogram (Subp_Id));
-- Partially insert the marker into the tree
Set_Parent (Marker, Parent (Subp_Decl));
return Marker;
end Build_Subprogram_Invocation;
---------------------------
-- Build_Task_Activation --
---------------------------
function Build_Task_Activation
(Task_Typ : Entity_Id;
In_State : Processing_In_State) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Task_Typ);
Marker : constant Node_Id := Make_Call_Marker (Loc);
Task_Decl : constant Node_Id := Unit_Declaration_Node (Task_Typ);
Activ_Id : Entity_Id;
Marker_Rep_Id : Scenario_Rep_Id;
Task_Obj : Entity_Id;
Task_Objs : NE_List.Doubly_Linked_List;
begin
-- Create a dummy call marker which activates some tasks
Set_Is_Declaration_Level_Node (Marker, False);
Set_Is_Dispatching_Call (Marker, False);
Set_Is_Elaboration_Checks_OK_Node (Marker, False);
Set_Is_Elaboration_Warnings_OK_Node (Marker, False);
Set_Is_Ignored_Ghost_Node (Marker, False);
Set_Is_Preelaborable_Call (Marker, False);
Set_Is_Source_Call (Marker, False);
Set_Is_SPARK_Mode_On_Node (Marker, False);
-- Invoke the appropriate version of Activate_Tasks
if Restricted_Profile then
Activ_Id := RTE (RE_Activate_Restricted_Tasks);
else
Activ_Id := RTE (RE_Activate_Tasks);
end if;
Set_Target (Marker, Activ_Id);
-- Partially insert the marker into the tree
Set_Parent (Marker, Parent (Task_Decl));
-- Create a dummy task object. Partially decorate the object because
-- it will not be inserted into the tree and analyzed.
Task_Obj := Make_Temporary (Loc, 'T');
Mutate_Ekind (Task_Obj, E_Variable);
Set_Etype (Task_Obj, Task_Typ);
-- Associate the dummy task object with the activation call
Task_Objs := NE_List.Create;
NE_List.Append (Task_Objs, Task_Obj);
Marker_Rep_Id := Scenario_Representation_Of (Marker, In_State);
Set_Activated_Task_Objects (Marker_Rep_Id, Task_Objs);
Set_Activated_Task_Type (Marker_Rep_Id, Task_Typ);
return Marker;
end Build_Task_Activation;
----------------------------------
-- Declare_Invocation_Construct --
----------------------------------
procedure Declare_Invocation_Construct
(Constr_Id : Entity_Id;
In_State : Processing_In_State)
is
function Body_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind;
pragma Inline (Body_Placement_Of);
-- Obtain the placement of arbitrary entity Id's body
function Declaration_Placement_Of_Node
(N : Node_Id) return Declaration_Placement_Kind;
pragma Inline (Declaration_Placement_Of_Node);
-- Obtain the placement of arbitrary node N
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind;
pragma Inline (Kind_Of);
-- Obtain the invocation construct kind of arbitrary entity Id
function Spec_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind;
pragma Inline (Spec_Placement_Of);
-- Obtain the placement of arbitrary entity Id's spec
-----------------------
-- Body_Placement_Of --
-----------------------
function Body_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind
is
Id_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep);
begin
-- The entity has a body
if Present (Body_Decl) then
return Declaration_Placement_Of_Node (Body_Decl);
-- Otherwise the entity must have a spec
else
pragma Assert (Present (Spec_Decl));
return Declaration_Placement_Of_Node (Spec_Decl);
end if;
end Body_Placement_Of;
-----------------------------------
-- Declaration_Placement_Of_Node --
-----------------------------------
function Declaration_Placement_Of_Node
(N : Node_Id) return Declaration_Placement_Kind
is
Main_Unit_Id : constant Entity_Id := Main_Unit_Entity;
N_Unit_Id : constant Entity_Id := Find_Top_Unit (N);
begin
-- The node is in the main unit, its placement depends on the main
-- unit kind.
if N_Unit_Id = Main_Unit_Id then
-- The main unit is a body
if Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body
then
return In_Body;
-- The main unit is a stand-alone subprogram body
elsif Ekind (Main_Unit_Id) in E_Function | E_Procedure
and then Nkind (Unit_Declaration_Node (Main_Unit_Id)) =
N_Subprogram_Body
then
return In_Body;
-- Otherwise the main unit is a spec
else
return In_Spec;
end if;
-- Otherwise the node is in the complementary unit of the main
-- unit. The main unit is a body, the node is in the spec.
elsif Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body
then
return In_Spec;
-- The main unit is a spec, the node is in the body
else
return In_Body;
end if;
end Declaration_Placement_Of_Node;
-------------
-- Kind_Of --
-------------
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind is
begin
if Id = Elab_Body_Id then
return Elaborate_Body_Procedure;
elsif Id = Elab_Spec_Id then
return Elaborate_Spec_Procedure;
else
return Regular_Construct;
end if;
end Kind_Of;
-----------------------
-- Spec_Placement_Of --
-----------------------
function Spec_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind
is
Id_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep);
begin
-- The entity has a spec
if Present (Spec_Decl) then
return Declaration_Placement_Of_Node (Spec_Decl);
-- Otherwise the entity must have a body
else
pragma Assert (Present (Body_Decl));
return Declaration_Placement_Of_Node (Body_Decl);
end if;
end Spec_Placement_Of;
-- Start of processing for Declare_Invocation_Construct
begin
-- Nothing to do when the construct has already been declared in the
-- ALI file.
if Is_Saved_Construct (Constr_Id) then
return;
end if;
-- Mark the construct as declared in the ALI file
Set_Is_Saved_Construct (Constr_Id);
-- Add the construct in the ALI file
Add_Invocation_Construct
(Body_Placement => Body_Placement_Of (Constr_Id),
Kind => Kind_Of (Constr_Id),
Signature => Signature_Of (Constr_Id),
Spec_Placement => Spec_Placement_Of (Constr_Id),
Update_Units => False);
end Declare_Invocation_Construct;
-------------------------------
-- Finalize_Invocation_Graph --
-------------------------------
procedure Finalize_Invocation_Graph is
begin
NE_Set.Destroy (Saved_Constructs_Set);
IR_Set.Destroy (Saved_Relations_Set);
end Finalize_Invocation_Graph;
----------
-- Hash --
----------
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type is
pragma Assert (Present (Key.Invoker));
pragma Assert (Present (Key.Target));
begin
return
Hash_Two_Keys
(Bucket_Range_Type (Key.Invoker),
Bucket_Range_Type (Key.Target));
end Hash;
---------------------------------
-- Initialize_Invocation_Graph --
---------------------------------
procedure Initialize_Invocation_Graph is
begin
Saved_Constructs_Set := NE_Set.Create (100);
Saved_Relations_Set := IR_Set.Create (200);
end Initialize_Invocation_Graph;
-----------------------------------
-- Invocation_Graph_Recording_OK --
-----------------------------------
function Invocation_Graph_Recording_OK return Boolean is
Main_Cunit : constant Node_Id := Cunit (Main_Unit);
begin
-- Nothing to do when compiling for GNATprove because the invocation
-- graph is not needed.
if GNATprove_Mode then
return False;
-- Nothing to do when the compilation will not produce an ALI file
elsif Serious_Errors_Detected > 0 then
return False;
-- Nothing to do when the main unit requires a body. Processing the
-- completing body will create the ALI file for the unit and record
-- the invocation graph.
elsif Body_Required (Main_Cunit) then
return False;
end if;
return True;
end Invocation_Graph_Recording_OK;
----------------------------
-- Is_Invocation_Scenario --
----------------------------
function Is_Invocation_Scenario (N : Node_Id) return Boolean is
begin
return
Is_Suitable_Access_Taken (N)
or else Is_Suitable_Call (N)
or else Is_Suitable_Instantiation (N);
end Is_Invocation_Scenario;
--------------------------
-- Is_Invocation_Target --
--------------------------
function Is_Invocation_Target (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must either come from source, or denote an
-- Ada, bridge, or SPARK target.
return
Comes_From_Source (Id)
or else Is_Ada_Semantic_Target (Id)
or else Is_Bridge_Target (Id)
or else Is_SPARK_Semantic_Target (Id);
end Is_Invocation_Target;
------------------------
-- Is_Saved_Construct --
------------------------
function Is_Saved_Construct (Constr : Entity_Id) return Boolean is
pragma Assert (Present (Constr));
begin
return NE_Set.Contains (Saved_Constructs_Set, Constr);
end Is_Saved_Construct;
-----------------------
-- Is_Saved_Relation --
-----------------------
function Is_Saved_Relation
(Rel : Invoker_Target_Relation) return Boolean
is
pragma Assert (Present (Rel.Invoker));
pragma Assert (Present (Rel.Target));
begin
return IR_Set.Contains (Saved_Relations_Set, Rel);
end Is_Saved_Relation;
--------------------------
-- Process_Declarations --
--------------------------
procedure Process_Declarations
(Decls : List_Id;
In_State : Processing_In_State)
is
Decl : Node_Id;
begin
Decl := First (Decls);
while Present (Decl) loop
-- Freeze node
if Nkind (Decl) = N_Freeze_Entity then
Process_Freeze_Node
(Fnode => Decl,
In_State => In_State);
-- Package (nested)
elsif Nkind (Decl) = N_Package_Declaration then
Process_Package_Declaration
(Pack_Decl => Decl,
In_State => In_State);
-- Protected type
elsif Nkind (Decl) in N_Protected_Type_Declaration
| N_Single_Protected_Declaration
then
Process_Protected_Type_Declaration
(Prot_Decl => Decl,
In_State => In_State);
-- Subprogram or entry
elsif Nkind (Decl) in N_Entry_Declaration
| N_Subprogram_Declaration
then
Process_Subprogram_Declaration
(Subp_Decl => Decl,
In_State => In_State);
-- Subprogram body (stand alone)
elsif Nkind (Decl) = N_Subprogram_Body
and then No (Corresponding_Spec (Decl))
then
Process_Subprogram_Declaration
(Subp_Decl => Decl,
In_State => In_State);
-- Subprogram instantiation
elsif Nkind (Decl) in N_Subprogram_Instantiation then
Process_Subprogram_Instantiation
(Inst => Decl,
In_State => In_State);
-- Task type
elsif Nkind (Decl) in N_Single_Task_Declaration
| N_Task_Type_Declaration
then
Process_Task_Type_Declaration
(Task_Decl => Decl,
In_State => In_State);
-- Task type (derived)
elsif Nkind (Decl) = N_Full_Type_Declaration
and then Is_Task_Type (Defining_Entity (Decl))
then
Process_Task_Type_Declaration
(Task_Decl => Decl,
In_State => In_State);
end if;
Next (Decl);
end loop;
end Process_Declarations;
-------------------------
-- Process_Freeze_Node --
-------------------------
procedure Process_Freeze_Node
(Fnode : Node_Id;
In_State : Processing_In_State)
is
begin
Process_Declarations
(Decls => Actions (Fnode),
In_State => In_State);
end Process_Freeze_Node;
-----------------------------------
-- Process_Invocation_Activation --
-----------------------------------
procedure Process_Invocation_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call);
pragma Unreferenced (Call_Rep);
pragma Unreferenced (Obj_Id);
pragma Unreferenced (Obj_Rep);
begin
-- Nothing to do when the task type appears within an internal unit
if In_Internal_Unit (Task_Typ) then
return;
end if;
-- The task type being activated is within the main unit. Extend the
-- DFS traversal into its body.
if In_Extended_Main_Code_Unit (Task_Typ) then
Traverse_Invocation_Body
(N => Body_Declaration (Task_Rep),
In_State => In_State);
-- The task type being activated resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Task_Typ |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the task type.
else
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Activation;
---------------------------------------
-- Process_Invocation_Body_Scenarios --
---------------------------------------
procedure Process_Invocation_Body_Scenarios is
Iter : NE_Set.Iterator := Iterate_Library_Body_Scenarios;
begin
Process_Invocation_Scenarios
(Iter => Iter,
In_State => Invocation_Body_State);
end Process_Invocation_Body_Scenarios;
-----------------------------
-- Process_Invocation_Call --
-----------------------------
procedure Process_Invocation_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call);
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
begin
-- Nothing to do when the subprogram appears within an internal unit
if In_Internal_Unit (Subp_Id) then
return;
-- Nothing to do for an abstract subprogram because it has no body to
-- examine.
elsif Ekind (Subp_Id) in E_Function | E_Procedure
and then Is_Abstract_Subprogram (Subp_Id)
then
return;
-- Nothin to do for a formal subprogram because it has no body to
-- examine.
elsif Is_Formal_Subprogram (Subp_Id) then
return;
end if;
-- The subprogram being called is within the main unit. Extend the
-- DFS traversal into its barrier function and body.
if In_Extended_Main_Code_Unit (Subp_Id) then
if Ekind (Subp_Id) in E_Entry | E_Entry_Family | E_Procedure then
Traverse_Invocation_Body
(N => Barrier_Body_Declaration (Subp_Rep),
In_State => In_State);
end if;
Traverse_Invocation_Body
(N => Body_Declaration (Subp_Rep),
In_State => In_State);
-- The subprogram being called resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Subp_Id |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the subprogram.
else
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Call;
--------------------------------------
-- Process_Invocation_Instantiation --
--------------------------------------
procedure Process_Invocation_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Inst);
Gen_Id : constant Entity_Id := Target (Inst_Rep);
begin
-- Nothing to do when the generic appears within an internal unit
if In_Internal_Unit (Gen_Id) then
return;
end if;
-- The generic being instantiated resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Generic |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the generic.
if not In_Extended_Main_Code_Unit (Gen_Id) then
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Instantiation;
---------------------------------
-- Process_Invocation_Scenario --
---------------------------------
procedure Process_Invocation_Scenario
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Call or task activation
if Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
-- Routine Build_Call_Marker creates call markers regardless of
-- whether the call occurs within the main unit or not. This way
-- the serialization of internal names is kept consistent. Only
-- call markers found within the main unit must be processed.
if In_Main_Context (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Invocation_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Processor => Process_Invocation_Activation'Access,
In_State => In_State);
end if;
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Invocation_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all invocation constructs and paths have been saved.
Pop_Active_Scenario (Scen);
end Process_Invocation_Scenario;
----------------------------------
-- Process_Invocation_Scenarios --
----------------------------------
procedure Process_Invocation_Scenarios
(Iter : in out NE_Set.Iterator;
In_State : Processing_In_State)
is
N : Node_Id;
begin
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
-- Reset the traversed status of all subprogram bodies because the
-- current invocation scenario acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Invocation_Scenario (N, In_State);
end loop;
end Process_Invocation_Scenarios;
---------------------------------------
-- Process_Invocation_Spec_Scenarios --
---------------------------------------
procedure Process_Invocation_Spec_Scenarios is
Iter : NE_Set.Iterator := Iterate_Library_Spec_Scenarios;
begin
Process_Invocation_Scenarios
(Iter => Iter,
In_State => Invocation_Spec_State);
end Process_Invocation_Spec_Scenarios;
-----------------------
-- Process_Main_Unit --
-----------------------
procedure Process_Main_Unit is
Unit_Decl : constant Node_Id := Unit (Cunit (Main_Unit));
Spec_Id : Entity_Id;
begin
-- The main unit is a [generic] package body
if Nkind (Unit_Decl) = N_Package_Body then
Spec_Id := Corresponding_Spec (Unit_Decl);
pragma Assert (Present (Spec_Id));
Process_Package_Declaration
(Pack_Decl => Unit_Declaration_Node (Spec_Id),
In_State => Invocation_Construct_State);
-- The main unit is a [generic] package declaration
elsif Nkind (Unit_Decl) = N_Package_Declaration then
Process_Package_Declaration
(Pack_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
-- The main unit is a [generic] subprogram body
elsif Nkind (Unit_Decl) = N_Subprogram_Body then
Spec_Id := Corresponding_Spec (Unit_Decl);
-- The body completes a previous declaration
if Present (Spec_Id) then
Process_Subprogram_Declaration
(Subp_Decl => Unit_Declaration_Node (Spec_Id),
In_State => Invocation_Construct_State);
-- Otherwise the body is stand-alone
else
Process_Subprogram_Declaration
(Subp_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
end if;
-- The main unit is a subprogram instantiation
elsif Nkind (Unit_Decl) in N_Subprogram_Instantiation then
Process_Subprogram_Instantiation
(Inst => Unit_Decl,
In_State => Invocation_Construct_State);
-- The main unit is an imported subprogram declaration
elsif Nkind (Unit_Decl) = N_Subprogram_Declaration then
Process_Subprogram_Declaration
(Subp_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
end if;
end Process_Main_Unit;
---------------------------------
-- Process_Package_Declaration --
---------------------------------
procedure Process_Package_Declaration
(Pack_Decl : Node_Id;
In_State : Processing_In_State)
is
Body_Id : constant Entity_Id := Corresponding_Body (Pack_Decl);
Spec : constant Node_Id := Specification (Pack_Decl);
Spec_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
begin
-- Add a declaration for the generic package in the ALI of the main
-- unit in case a client unit instantiates it.
if Ekind (Spec_Id) = E_Generic_Package then
Declare_Invocation_Construct
(Constr_Id => Spec_Id,
In_State => In_State);
-- Otherwise inspect the visible and private declarations of the
-- package for invocation constructs.
else
Process_Declarations
(Decls => Visible_Declarations (Spec),
In_State => In_State);
Process_Declarations
(Decls => Private_Declarations (Spec),
In_State => In_State);
-- The package body containst at least one generic unit or an
-- inlinable subprogram. Such constructs may grant clients of
-- the main unit access to the private enclosing contexts of
-- the constructs. Process the main unit body to discover and
-- encode relevant invocation constructs and relations that
-- may ultimately reach an external unit.
if Present (Body_Id)
and then Save_Invocation_Graph_Of_Body (Cunit (Main_Unit))
then
Process_Declarations
(Decls => Declarations (Unit_Declaration_Node (Body_Id)),
In_State => In_State);
end if;
end if;
end Process_Package_Declaration;
----------------------------------------
-- Process_Protected_Type_Declaration --
----------------------------------------
procedure Process_Protected_Type_Declaration
(Prot_Decl : Node_Id;
In_State : Processing_In_State)
is
Prot_Def : constant Node_Id := Protected_Definition (Prot_Decl);
begin
if Present (Prot_Def) then
Process_Declarations
(Decls => Visible_Declarations (Prot_Def),
In_State => In_State);
end if;
end Process_Protected_Type_Declaration;
------------------------------------
-- Process_Subprogram_Declaration --
------------------------------------
procedure Process_Subprogram_Declaration
(Subp_Decl : Node_Id;
In_State : Processing_In_State)
is
Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
begin
-- Nothing to do when the subprogram is not an invocation target
if not Is_Invocation_Target (Subp_Id) then
return;
end if;
-- Add a declaration for the subprogram in the ALI file of the main
-- unit in case a client unit calls or instantiates it.
Declare_Invocation_Construct
(Constr_Id => Subp_Id,
In_State => In_State);
-- Do not process subprograms without a body because they do not
-- contain any invocation scenarios.
if Is_Bodiless_Subprogram (Subp_Id) then
null;
-- Do not process generic subprograms because generics must not be
-- examined.
elsif Is_Generic_Subprogram (Subp_Id) then
null;
-- Otherwise create a dummy scenario which calls the subprogram to
-- act as a root for a DFS traversal.
else
-- Reset the traversed status of all subprogram bodies because the
-- subprogram acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Invocation_Scenario
(N => Build_Subprogram_Invocation (Subp_Id),
In_State => In_State);
end if;
end Process_Subprogram_Declaration;
--------------------------------------
-- Process_Subprogram_Instantiation --
--------------------------------------
procedure Process_Subprogram_Instantiation
(Inst : Node_Id;
In_State : Processing_In_State)
is
begin
-- Add a declaration for the instantiation in the ALI file of the
-- main unit in case a client unit calls it.
Declare_Invocation_Construct
(Constr_Id => Defining_Entity (Inst),
In_State => In_State);
end Process_Subprogram_Instantiation;
-----------------------------------
-- Process_Task_Type_Declaration --
-----------------------------------
procedure Process_Task_Type_Declaration
(Task_Decl : Node_Id;
In_State : Processing_In_State)
is
Task_Typ : constant Entity_Id := Defining_Entity (Task_Decl);
Task_Def : Node_Id;
begin
-- Add a declaration for the task type the ALI file of the main unit
-- in case a client unit creates a task object and activates it.
Declare_Invocation_Construct
(Constr_Id => Task_Typ,
In_State => In_State);
-- Process the entries of the task type because they represent valid
-- entry points into the task body.
if Nkind (Task_Decl) in N_Single_Task_Declaration
| N_Task_Type_Declaration
then
Task_Def := Task_Definition (Task_Decl);
if Present (Task_Def) then
Process_Declarations
(Decls => Visible_Declarations (Task_Def),
In_State => In_State);
end if;
end if;
-- Reset the traversed status of all subprogram bodies because the
-- task type acts as a new DFS traversal root.
Reset_Traversed_Bodies;
-- Create a dummy scenario which activates an anonymous object of the
-- task type to acts as a root of a DFS traversal.
Process_Invocation_Scenario
(N => Build_Task_Activation (Task_Typ, In_State),
In_State => In_State);
end Process_Task_Type_Declaration;
---------------------------------
-- Record_Full_Invocation_Path --
---------------------------------
procedure Record_Full_Invocation_Path (In_State : Processing_In_State) is
package Scenarios renames Active_Scenario_Stack;
begin
-- The path originates from the elaboration of the body. Add an extra
-- relation from the elaboration body procedure to the first active
-- scenario.
if In_State.Processing = Invocation_Body_Processing then
Build_Elaborate_Body_Procedure;
Record_Invocation_Relation
(Invk_Id => Elab_Body_Id,
Targ_Id => Target_Of (Scenarios.First, In_State),
In_State => In_State);
-- The path originates from the elaboration of the spec. Add an extra
-- relation from the elaboration spec procedure to the first active
-- scenario.
elsif In_State.Processing = Invocation_Spec_Processing then
Build_Elaborate_Spec_Procedure;
Record_Invocation_Relation
(Invk_Id => Elab_Spec_Id,
Targ_Id => Target_Of (Scenarios.First, In_State),
In_State => In_State);
end if;
-- Record individual relations formed by pairs of scenarios
for Index in Scenarios.First .. Scenarios.Last - 1 loop
Record_Invocation_Relation
(Invk_Id => Target_Of (Index, In_State),
Targ_Id => Target_Of (Index + 1, In_State),
In_State => In_State);
end loop;
end Record_Full_Invocation_Path;
-----------------------------
-- Record_Invocation_Graph --
-----------------------------
procedure Record_Invocation_Graph is
begin
-- Nothing to do when the invocation graph is not recorded
if not Invocation_Graph_Recording_OK then
return;
end if;
-- Save the encoding format used to capture information about the
-- invocation constructs and relations in the ALI file of the main
-- unit.
Record_Invocation_Graph_Encoding;
-- Examine all library level invocation scenarios and perform DFS
-- traversals from each one. Encode a path in the ALI file of the
-- main unit if it reaches into an external unit.
Process_Invocation_Body_Scenarios;
Process_Invocation_Spec_Scenarios;
-- Examine all invocation constructs within the spec and body of the
-- main unit and perform DFS traversals from each one. Encode a path
-- in the ALI file of the main unit if it reaches into an external
-- unit.
Process_Main_Unit;
end Record_Invocation_Graph;
--------------------------------------
-- Record_Invocation_Graph_Encoding --
--------------------------------------
procedure Record_Invocation_Graph_Encoding is
Kind : Invocation_Graph_Encoding_Kind := No_Encoding;
begin
-- Switch -gnatd_F (encode full invocation paths in ALI files) is in
-- effect.
if Debug_Flag_Underscore_FF then
Kind := Full_Path_Encoding;
else
Kind := Endpoints_Encoding;
end if;
-- Save the encoding format in the ALI file of the main unit
Set_Invocation_Graph_Encoding
(Kind => Kind,
Update_Units => False);
end Record_Invocation_Graph_Encoding;
----------------------------
-- Record_Invocation_Path --
----------------------------
procedure Record_Invocation_Path (In_State : Processing_In_State) is
package Scenarios renames Active_Scenario_Stack;
begin
-- Save a path when the active scenario stack contains at least one
-- invocation scenario.
if Scenarios.Last - Scenarios.First < 0 then
return;
end if;
-- Register all relations in the path when switch -gnatd_F (encode
-- full invocation paths in ALI files) is in effect.
if Debug_Flag_Underscore_FF then
Record_Full_Invocation_Path (In_State);
-- Otherwise register a single relation
else
Record_Simple_Invocation_Path (In_State);
end if;
Write_Invocation_Path (In_State);
end Record_Invocation_Path;
--------------------------------
-- Record_Invocation_Relation --
--------------------------------
procedure Record_Invocation_Relation
(Invk_Id : Entity_Id;
Targ_Id : Entity_Id;
In_State : Processing_In_State)
is
pragma Assert (Present (Invk_Id));
pragma Assert (Present (Targ_Id));
procedure Get_Invocation_Attributes
(Extra : out Entity_Id;
Kind : out Invocation_Kind);
pragma Inline (Get_Invocation_Attributes);
-- Return the additional entity used in error diagnostics in Extra
-- and the invocation kind in Kind which pertain to the invocation
-- relation with invoker Invk_Id and target Targ_Id.
-------------------------------
-- Get_Invocation_Attributes --
-------------------------------
procedure Get_Invocation_Attributes
(Extra : out Entity_Id;
Kind : out Invocation_Kind)
is
begin
-- Accept within a task body
if Is_Accept_Alternative_Proc (Targ_Id) then
Extra := Receiving_Entry (Targ_Id);
Kind := Accept_Alternative;
-- Activation of a task object
elsif Is_Activation_Proc (Targ_Id)
or else Is_Task_Type (Targ_Id)
then
Extra := Empty;
Kind := Task_Activation;
-- Controlled adjustment actions
elsif Is_Controlled_Proc (Targ_Id, Name_Adjust) then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Adjustment;
-- Controlled finalization actions
elsif Is_Controlled_Proc (Targ_Id, Name_Finalize)
or else Is_Finalizer_Proc (Targ_Id)
then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Finalization;
-- Controlled initialization actions
elsif Is_Controlled_Proc (Targ_Id, Name_Initialize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Initialization;
-- Default_Initial_Condition verification
elsif Is_Default_Initial_Condition_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Default_Initial_Condition_Verification;
-- Initialization of object
elsif Is_Init_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Type_Initialization;
-- Initial_Condition verification
elsif Is_Initial_Condition_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Initial_Condition_Verification;
-- Instantiation
elsif Is_Generic_Unit (Targ_Id) then
Extra := Empty;
Kind := Instantiation;
-- Internal controlled adjustment actions
elsif Is_TSS (Targ_Id, TSS_Deep_Adjust) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Adjustment;
-- Internal controlled finalization actions
elsif Is_TSS (Targ_Id, TSS_Deep_Finalize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Finalization;
-- Internal controlled initialization actions
elsif Is_TSS (Targ_Id, TSS_Deep_Initialize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Initialization;
-- Invariant verification
elsif Is_Invariant_Proc (Targ_Id)
or else Is_Partial_Invariant_Proc (Targ_Id)
then
Extra := First_Formal_Type (Targ_Id);
Kind := Invariant_Verification;
-- Protected entry call
elsif Is_Protected_Entry (Targ_Id) then
Extra := Empty;
Kind := Protected_Entry_Call;
-- Protected subprogram call
elsif Is_Protected_Subp (Targ_Id) then
Extra := Empty;
Kind := Protected_Subprogram_Call;
-- Task entry call
elsif Is_Task_Entry (Targ_Id) then
Extra := Empty;
Kind := Task_Entry_Call;
-- Entry, operator, or subprogram call. This case must come last
-- because most invocations above are variations of this case.
elsif Ekind (Targ_Id) in
E_Entry | E_Function | E_Operator | E_Procedure
then
Extra := Empty;
Kind := Call;
else
pragma Assert (False);
Extra := Empty;
Kind := No_Invocation;
end if;
end Get_Invocation_Attributes;
-- Local variables
Extra : Entity_Id;
Extra_Nam : Name_Id;
Kind : Invocation_Kind;
Rel : Invoker_Target_Relation;
-- Start of processing for Record_Invocation_Relation
begin
Rel.Invoker := Invk_Id;
Rel.Target := Targ_Id;
-- Nothing to do when the invocation relation has already been
-- recorded in ALI file of the main unit.
if Is_Saved_Relation (Rel) then
return;
end if;
-- Mark the relation as recorded in the ALI file
Set_Is_Saved_Relation (Rel);
-- Declare the invoker in the ALI file
Declare_Invocation_Construct
(Constr_Id => Invk_Id,
In_State => In_State);
-- Obtain the invocation-specific attributes of the relation
Get_Invocation_Attributes (Extra, Kind);
-- Certain invocations lack an extra entity used in error diagnostics
if Present (Extra) then
Extra_Nam := Chars (Extra);
else
Extra_Nam := No_Name;
end if;
-- Add the relation in the ALI file
Add_Invocation_Relation
(Extra => Extra_Nam,
Invoker => Signature_Of (Invk_Id),
Kind => Kind,
Target => Signature_Of (Targ_Id),
Update_Units => False);
end Record_Invocation_Relation;
-----------------------------------
-- Record_Simple_Invocation_Path --
-----------------------------------
procedure Record_Simple_Invocation_Path
(In_State : Processing_In_State)
is
package Scenarios renames Active_Scenario_Stack;
Last_Targ : constant Entity_Id :=
Target_Of (Scenarios.Last, In_State);
First_Targ : Entity_Id;
begin
-- The path originates from the elaboration of the body. Add an extra
-- relation from the elaboration body procedure to the first active
-- scenario.
if In_State.Processing = Invocation_Body_Processing then
Build_Elaborate_Body_Procedure;
First_Targ := Elab_Body_Id;
-- The path originates from the elaboration of the spec. Add an extra
-- relation from the elaboration spec procedure to the first active
-- scenario.
elsif In_State.Processing = Invocation_Spec_Processing then
Build_Elaborate_Spec_Procedure;
First_Targ := Elab_Spec_Id;
else
First_Targ := Target_Of (Scenarios.First, In_State);
end if;
-- Record a single relation from the first to the last scenario
if First_Targ /= Last_Targ then
Record_Invocation_Relation
(Invk_Id => First_Targ,
Targ_Id => Last_Targ,
In_State => In_State);
end if;
end Record_Simple_Invocation_Path;
----------------------------
-- Set_Is_Saved_Construct --
----------------------------
procedure Set_Is_Saved_Construct (Constr : Entity_Id) is
pragma Assert (Present (Constr));
begin
NE_Set.Insert (Saved_Constructs_Set, Constr);
end Set_Is_Saved_Construct;
---------------------------
-- Set_Is_Saved_Relation --
---------------------------
procedure Set_Is_Saved_Relation (Rel : Invoker_Target_Relation) is
begin
IR_Set.Insert (Saved_Relations_Set, Rel);
end Set_Is_Saved_Relation;
------------------
-- Signature_Of --
------------------
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id is
Loc : constant Source_Ptr := Sloc (Id);
function Instantiation_Locations return Name_Id;
pragma Inline (Instantiation_Locations);
-- Create a concatenation of all lines and colums of each instance
-- where source location Loc appears. Return No_Name if no instances
-- exist.
function Qualified_Scope return Name_Id;
pragma Inline (Qualified_Scope);
-- Obtain the qualified name of Id's scope
-----------------------------
-- Instantiation_Locations --
-----------------------------
function Instantiation_Locations return Name_Id is
Buffer : Bounded_String (2052);
Inst : Source_Ptr;
Loc_Nam : Name_Id;
SFI : Source_File_Index;
begin
SFI := Get_Source_File_Index (Loc);
Inst := Instantiation (SFI);
-- The location is within an instance. Construct a concatenation
-- of all lines and colums of each individual instance using the
-- following format:
--
-- line1_column1_line2_column2_ ... _lineN_columnN
if Inst /= No_Location then
loop
Append (Buffer, Nat (Get_Logical_Line_Number (Inst)));
Append (Buffer, '_');
Append (Buffer, Nat (Get_Column_Number (Inst)));
SFI := Get_Source_File_Index (Inst);
Inst := Instantiation (SFI);
exit when Inst = No_Location;
Append (Buffer, '_');
end loop;
Loc_Nam := Name_Find (Buffer);
return Loc_Nam;
-- Otherwise there no instances are involved
else
return No_Name;
end if;
end Instantiation_Locations;
---------------------
-- Qualified_Scope --
---------------------
function Qualified_Scope return Name_Id is
Scop : Entity_Id;
begin
Scop := Scope (Id);
-- The entity appears within an anonymous concurrent type created
-- for a single protected or task type declaration. Use the entity
-- of the anonymous object as it represents the original scope.
if Is_Concurrent_Type (Scop)
and then Present (Anonymous_Object (Scop))
then
Scop := Anonymous_Object (Scop);
end if;
return Get_Qualified_Name (Scop);
end Qualified_Scope;
-- Start of processing for Signature_Of
begin
return
Invocation_Signature_Of
(Column => Nat (Get_Column_Number (Loc)),
Line => Nat (Get_Logical_Line_Number (Loc)),
Locations => Instantiation_Locations,
Name => Chars (Id),
Scope => Qualified_Scope);
end Signature_Of;
---------------
-- Target_Of --
---------------
function Target_Of
(Pos : Active_Scenario_Pos;
In_State : Processing_In_State) return Entity_Id
is
package Scenarios renames Active_Scenario_Stack;
-- Ensure that the position is within the bounds of the active
-- scenario stack.
pragma Assert (Scenarios.First <= Pos);
pragma Assert (Pos <= Scenarios.Last);
Scen_Rep : constant Scenario_Rep_Id :=
Scenario_Representation_Of
(Scenarios.Table (Pos), In_State);
begin
-- The true target of an activation call is the current task type
-- rather than routine Activate_Tasks.
if Kind (Scen_Rep) = Task_Activation_Scenario then
return Activated_Task_Type (Scen_Rep);
else
return Target (Scen_Rep);
end if;
end Target_Of;
------------------------------
-- Traverse_Invocation_Body --
------------------------------
procedure Traverse_Invocation_Body
(N : Node_Id;
In_State : Processing_In_State)
is
begin
Traverse_Body
(N => N,
Requires_Processing => Is_Invocation_Scenario'Access,
Processor => Process_Invocation_Scenario'Access,
In_State => In_State);
end Traverse_Invocation_Body;
---------------------------
-- Write_Invocation_Path --
---------------------------
procedure Write_Invocation_Path (In_State : Processing_In_State) is
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean);
pragma Inline (Write_Target);
-- Write out invocation target Targ_Id to standard output. Flag
-- Is_First should be set when the target is first in a path.
-------------
-- Targ_Id --
-------------
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean) is
begin
if not Is_First then
Write_Str (" --> ");
end if;
Write_Name (Get_Qualified_Name (Targ_Id));
Write_Eol;
end Write_Target;
-- Local variables
package Scenarios renames Active_Scenario_Stack;
First_Seen : Boolean := False;
-- Start of processing for Write_Invocation_Path
begin
-- Nothing to do when flag -gnatd_T (output trace information on
-- invocation path recording) is not in effect.
if not Debug_Flag_Underscore_TT then
return;
end if;
-- The path originates from the elaboration of the body. Write the
-- elaboration body procedure.
if In_State.Processing = Invocation_Body_Processing then
Write_Target (Elab_Body_Id, True);
First_Seen := True;
-- The path originates from the elaboration of the spec. Write the
-- elaboration spec procedure.
elsif In_State.Processing = Invocation_Spec_Processing then
Write_Target (Elab_Spec_Id, True);
First_Seen := True;
end if;
-- Write each individual target invoked by its corresponding scenario
-- on the active scenario stack.
for Index in Scenarios.First .. Scenarios.Last loop
Write_Target
(Targ_Id => Target_Of (Index, In_State),
Is_First => Index = Scenarios.First and then not First_Seen);
end loop;
Write_Eol;
end Write_Invocation_Path;
end Invocation_Graph;
------------------------
-- Is_Safe_Activation --
------------------------
function Is_Safe_Activation
(Call : Node_Id;
Task_Rep : Target_Rep_Id) return Boolean
is
begin
-- The activation of a task coming from an external instance cannot
-- cause an ABE because the generic was already instantiated. Note
-- that the instantiation itself may lead to an ABE.
return
In_External_Instance
(N => Call,
Target_Decl => Spec_Declaration (Task_Rep));
end Is_Safe_Activation;
------------------
-- Is_Safe_Call --
------------------
function Is_Safe_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id) return Boolean
is
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
begin
-- The target is either an abstract subprogram, formal subprogram, or
-- imported, in which case it does not have a body at compile or bind
-- time. Assume that the call is ABE-safe.
if Is_Bodiless_Subprogram (Subp_Id) then
return True;
-- The target is an instantiation of a generic subprogram. The call
-- cannot cause an ABE because the generic was already instantiated.
-- Note that the instantiation itself may lead to an ABE.
elsif Is_Generic_Instance (Subp_Id) then
return True;
-- The invocation of a target coming from an external instance cannot
-- cause an ABE because the generic was already instantiated. Note that
-- the instantiation itself may lead to an ABE.
elsif In_External_Instance
(N => Call,
Target_Decl => Spec_Decl)
then
return True;
-- The target is a subprogram body without a previous declaration. The
-- call cannot cause an ABE because the body has already been seen.
elsif Nkind (Spec_Decl) = N_Subprogram_Body
and then No (Corresponding_Spec (Spec_Decl))
then
return True;
-- The target is a subprogram body stub without a prior declaration.
-- The call cannot cause an ABE because the proper body substitutes
-- the stub.
elsif Nkind (Spec_Decl) = N_Subprogram_Body_Stub
and then No (Corresponding_Spec_Of_Stub (Spec_Decl))
then
return True;
-- A call to an expression function that is not a completion cannot
-- cause an ABE because it has no prior declaration; this remains
-- true even if the FE transforms the callee into something else.
elsif Nkind (Original_Node (Spec_Decl)) = N_Expression_Function then
return True;
-- Subprogram bodies which wrap attribute references used as actuals
-- in instantiations are always ABE-safe. These bodies are artifacts
-- of expansion.
elsif Present (Body_Decl)
and then Nkind (Body_Decl) = N_Subprogram_Body
and then Was_Attribute_Reference (Body_Decl)
then
return True;
end if;
return False;
end Is_Safe_Call;
---------------------------
-- Is_Safe_Instantiation --
---------------------------
function Is_Safe_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id) return Boolean
is
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep);
begin
-- The generic is an intrinsic subprogram in which case it does not
-- have a body at compile or bind time. Assume that the instantiation
-- is ABE-safe.
if Is_Bodiless_Subprogram (Gen_Id) then
return True;
-- The instantiation of an external nested generic cannot cause an ABE
-- if the outer generic was already instantiated. Note that the instance
-- of the outer generic may lead to an ABE.
elsif In_External_Instance
(N => Inst,
Target_Decl => Spec_Decl)
then
return True;
-- The generic is a package. The instantiation cannot cause an ABE when
-- the package has no body.
elsif Ekind (Gen_Id) = E_Generic_Package
and then not Has_Body (Spec_Decl)
then
return True;
end if;
return False;
end Is_Safe_Instantiation;
------------------
-- Is_Same_Unit --
------------------
function Is_Same_Unit
(Unit_1 : Entity_Id;
Unit_2 : Entity_Id) return Boolean
is
begin
return Unit_Entity (Unit_1) = Unit_Entity (Unit_2);
end Is_Same_Unit;
-------------------------------
-- Kill_Elaboration_Scenario --
-------------------------------
procedure Kill_Elaboration_Scenario (N : Node_Id) is
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE lechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
end if;
-- Eliminate a recorded scenario when it appears within dead code
-- because it will not be executed at elaboration time.
if Is_Scenario (N) then
Delete_Scenario (N);
end if;
end Kill_Elaboration_Scenario;
----------------------
-- Main_Unit_Entity --
----------------------
function Main_Unit_Entity return Entity_Id is
begin
-- Note that Cunit_Entity (Main_Unit) is not reliable in the presence of
-- generic bodies and may return an outdated entity.
return Defining_Entity (Unit (Cunit (Main_Unit)));
end Main_Unit_Entity;
----------------------
-- Non_Private_View --
----------------------
function Non_Private_View (Typ : Entity_Id) return Entity_Id is
begin
if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
return Full_View (Typ);
else
return Typ;
end if;
end Non_Private_View;
---------------------------------
-- Record_Elaboration_Scenario --
---------------------------------
procedure Record_Elaboration_Scenario (N : Node_Id) is
procedure Check_Preelaborated_Call
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind);
pragma Inline (Check_Preelaborated_Call);
-- Verify that entry, operator, or subprogram call Call with enclosing
-- level Call_Lvl does not appear at the library level of preelaborated
-- unit.
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id;
pragma Inline (Find_Code_Unit);
-- Return the code unit which contains arbitrary node or entity Nod.
-- This is the unit of the file which physically contains the related
-- construct denoted by Nod except when Nod is within an instantiation.
-- In that case the unit is that of the top-level instantiation.
function In_Preelaborated_Context (Nod : Node_Id) return Boolean;
pragma Inline (In_Preelaborated_Context);
-- Determine whether arbitrary node Nod appears within a preelaborated
-- context.
procedure Record_Access_Taken
(Attr : Node_Id;
Attr_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Access_Taken);
-- Record 'Access scenario Attr with enclosing level Attr_Lvl
procedure Record_Call_Or_Task_Activation
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Call_Or_Task_Activation);
-- Record call scenario Call with enclosing level Call_Lvl
procedure Record_Instantiation
(Inst : Node_Id;
Inst_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Instantiation);
-- Record instantiation scenario Inst with enclosing level Inst_Lvl
procedure Record_Variable_Assignment
(Asmt : Node_Id;
Asmt_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Variable_Assignment);
-- Record variable assignment scenario Asmt with enclosing level
-- Asmt_Lvl.
procedure Record_Variable_Reference
(Ref : Node_Id;
Ref_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Variable_Reference);
-- Record variable reference scenario Ref with enclosing level Ref_Lvl
------------------------------
-- Check_Preelaborated_Call --
------------------------------
procedure Check_Preelaborated_Call
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind)
is
begin
-- Nothing to do when the call is internally generated because it is
-- assumed that it will never violate preelaboration.
if not Is_Source_Call (Call) then
return;
-- Nothing to do when the call is preelaborable by definition
elsif Is_Preelaborable_Call (Call) then
return;
-- Library-level calls are always considered because they are part of
-- the associated unit's elaboration actions.
elsif Call_Lvl in Library_Level then
null;
-- Calls at the library level of a generic package body have to be
-- checked because they would render an instantiation illegal if the
-- template is marked as preelaborated. Note that this does not apply
-- to calls at the library level of a generic package spec.
elsif Call_Lvl = Generic_Body_Level then
null;
-- Otherwise the call does not appear at the proper level and must
-- not be considered for this check.
else
return;
end if;
-- If the call appears within a preelaborated unit, give an error
if In_Preelaborated_Context (Call) then
Error_Preelaborated_Call (Call);
end if;
end Check_Preelaborated_Call;
--------------------
-- Find_Code_Unit --
--------------------
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id is
begin
return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (Nod))));
end Find_Code_Unit;
------------------------------
-- In_Preelaborated_Context --
------------------------------
function In_Preelaborated_Context (Nod : Node_Id) return Boolean is
Body_Id : constant Entity_Id := Find_Code_Unit (Nod);
Spec_Id : constant Entity_Id := Unique_Entity (Body_Id);
begin
-- The node appears within a package body whose corresponding spec is
-- subject to pragma Remote_Call_Interface or Remote_Types. This does
-- not result in a preelaborated context because the package body may
-- be on another machine.
if Ekind (Body_Id) = E_Package_Body
and then Is_Package_Or_Generic_Package (Spec_Id)
and then (Is_Remote_Call_Interface (Spec_Id)
or else Is_Remote_Types (Spec_Id))
then
return False;
-- Otherwise the node appears within a preelaborated context when the
-- associated unit is preelaborated.
else
return Is_Preelaborated_Unit (Spec_Id);
end if;
end In_Preelaborated_Context;
-------------------------
-- Record_Access_Taken --
-------------------------
procedure Record_Access_Taken
(Attr : Node_Id;
Attr_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal any enclosing local exception handlers that the 'Access may
-- raise Program_Error due to a failed ABE check when switch -gnatd.o
-- (conservative elaboration order for indirect calls) is in effect.
-- Marking the exception handlers ensures proper expansion by both
-- the front and back end restriction when No_Exception_Propagation
-- is in effect.
if Debug_Flag_Dot_O then
Possible_Local_Raise (Attr, Standard_Program_Error);
end if;
-- Add 'Access to the appropriate set
if Attr_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Attr);
elsif Attr_Lvl = Library_Spec_Level
or else Attr_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Attr);
end if;
-- 'Access requires a conditional ABE check when the dynamic model is
-- in effect.
Add_Dynamic_ABE_Check_Scenario (Attr);
end Record_Access_Taken;
------------------------------------
-- Record_Call_Or_Task_Activation --
------------------------------------
procedure Record_Call_Or_Task_Activation
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal any enclosing local exception handlers that the call may
-- raise Program_Error due to failed ABE check. Marking the exception
-- handlers ensures proper expansion by both the front and back end
-- restriction when No_Exception_Propagation is in effect.
Possible_Local_Raise (Call, Standard_Program_Error);
-- Perform early detection of guaranteed ABEs in order to suppress
-- the instantiation of generic bodies because gigi cannot handle
-- certain types of premature instantiations.
Process_Guaranteed_ABE
(N => Call,
In_State => Guaranteed_ABE_State);
-- Add the call or task activation to the appropriate set
if Call_Lvl = Declaration_Level then
Add_Declaration_Scenario (Call);
elsif Call_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Call);
elsif Call_Lvl = Library_Spec_Level
or else Call_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Call);
end if;
-- A call or a task activation requires a conditional ABE check when
-- the dynamic model is in effect.
Add_Dynamic_ABE_Check_Scenario (Call);
end Record_Call_Or_Task_Activation;
--------------------------
-- Record_Instantiation --
--------------------------
procedure Record_Instantiation
(Inst : Node_Id;
Inst_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal enclosing local exception handlers that instantiation may
-- raise Program_Error due to failed ABE check. Marking the exception
-- handlers ensures proper expansion by both the front and back end
-- restriction when No_Exception_Propagation is in effect.
Possible_Local_Raise (Inst, Standard_Program_Error);
-- Perform early detection of guaranteed ABEs in order to suppress
-- the instantiation of generic bodies because gigi cannot handle
-- certain types of premature instantiations.
Process_Guaranteed_ABE
(N => Inst,
In_State => Guaranteed_ABE_State);
-- Add the instantiation to the appropriate set
if Inst_Lvl = Declaration_Level then
Add_Declaration_Scenario (Inst);
elsif Inst_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Inst);
elsif Inst_Lvl = Library_Spec_Level
or else Inst_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Inst);
end if;
-- Instantiations of generics subject to SPARK_Mode On require
-- elaboration-related checks even though the instantiations may
-- not appear within elaboration code.
if Is_Suitable_SPARK_Instantiation (Inst) then
Add_SPARK_Scenario (Inst);
end if;
-- An instantiation requires a conditional ABE check when the dynamic
-- model is in effect.
Add_Dynamic_ABE_Check_Scenario (Inst);
end Record_Instantiation;
--------------------------------
-- Record_Variable_Assignment --
--------------------------------
procedure Record_Variable_Assignment
(Asmt : Node_Id;
Asmt_Lvl : Enclosing_Level_Kind)
is
begin
-- Add the variable assignment to the appropriate set
if Asmt_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Asmt);
elsif Asmt_Lvl = Library_Spec_Level
or else Asmt_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Asmt);
end if;
end Record_Variable_Assignment;
-------------------------------
-- Record_Variable_Reference --
-------------------------------
procedure Record_Variable_Reference
(Ref : Node_Id;
Ref_Lvl : Enclosing_Level_Kind)
is
begin
-- Add the variable reference to the appropriate set
if Ref_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Ref);
elsif Ref_Lvl = Library_Spec_Level
or else Ref_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Ref);
end if;
end Record_Variable_Reference;
-- Local variables
Scen : constant Node_Id := Scenario (N);
Scen_Lvl : Enclosing_Level_Kind;
-- Start of processing for Record_Elaboration_Scenario
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the scenario is being preanalyzed
elsif Preanalysis_Active then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
end if;
Scen_Lvl := Find_Enclosing_Level (Scen);
-- Ensure that a library-level call does not appear in a preelaborated
-- unit. The check must come before ignoring scenarios within external
-- units or inside generics because calls in those context must also be
-- verified.
if Is_Suitable_Call (Scen) then
Check_Preelaborated_Call (Scen, Scen_Lvl);
end if;
-- Nothing to do when the scenario does not appear within the main unit
if not In_Main_Context (Scen) then
return;
-- Nothing to do when the scenario appears within a generic
elsif Inside_A_Generic then
return;
-- 'Access
elsif Is_Suitable_Access_Taken (Scen) then
Record_Access_Taken
(Attr => Scen,
Attr_Lvl => Scen_Lvl);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Record_Call_Or_Task_Activation
(Call => Scen,
Call_Lvl => Scen_Lvl);
-- Derived type declaration
elsif Is_Suitable_SPARK_Derived_Type (Scen) then
Add_SPARK_Scenario (Scen);
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Record_Instantiation
(Inst => Scen,
Inst_Lvl => Scen_Lvl);
-- Refined_State pragma
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Add_SPARK_Scenario (Scen);
-- Variable assignment
elsif Is_Suitable_Variable_Assignment (Scen) then
Record_Variable_Assignment
(Asmt => Scen,
Asmt_Lvl => Scen_Lvl);
-- Variable reference
elsif Is_Suitable_Variable_Reference (Scen) then
Record_Variable_Reference
(Ref => Scen,
Ref_Lvl => Scen_Lvl);
end if;
end Record_Elaboration_Scenario;
--------------
-- Scenario --
--------------
function Scenario (N : Node_Id) return Node_Id is
Orig_N : constant Node_Id := Original_Node (N);
begin
-- An expanded instantiation is rewritten into a spec-body pair where
-- N denotes the spec. In this case the original instantiation is the
-- proper elaboration scenario.
if Nkind (Orig_N) in N_Generic_Instantiation then
return Orig_N;
-- Otherwise the scenario is already in its proper form
else
return N;
end if;
end Scenario;
----------------------
-- Scenario_Storage --
----------------------
package body Scenario_Storage is
---------------------
-- Data structures --
---------------------
-- The following sets store all scenarios
Declaration_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Dynamic_ABE_Check_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Library_Body_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Library_Spec_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
SPARK_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
-------------------------------
-- Finalize_Scenario_Storage --
-------------------------------
procedure Finalize_Scenario_Storage is
begin
NE_Set.Destroy (Declaration_Scenarios);
NE_Set.Destroy (Dynamic_ABE_Check_Scenarios);
NE_Set.Destroy (Library_Body_Scenarios);
NE_Set.Destroy (Library_Spec_Scenarios);
NE_Set.Destroy (SPARK_Scenarios);
end Finalize_Scenario_Storage;
---------------------------------
-- Initialize_Scenario_Storage --
---------------------------------
procedure Initialize_Scenario_Storage is
begin
Declaration_Scenarios := NE_Set.Create (1000);
Dynamic_ABE_Check_Scenarios := NE_Set.Create (500);
Library_Body_Scenarios := NE_Set.Create (1000);
Library_Spec_Scenarios := NE_Set.Create (1000);
SPARK_Scenarios := NE_Set.Create (100);
end Initialize_Scenario_Storage;
------------------------------
-- Add_Declaration_Scenario --
------------------------------
procedure Add_Declaration_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Declaration_Scenarios, N);
end Add_Declaration_Scenario;
------------------------------------
-- Add_Dynamic_ABE_Check_Scenario --
------------------------------------
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
if not Check_Or_Failure_Generation_OK then
return;
-- Nothing to do if the dynamic model is not in effect
elsif not Dynamic_Elaboration_Checks then
return;
end if;
NE_Set.Insert (Dynamic_ABE_Check_Scenarios, N);
end Add_Dynamic_ABE_Check_Scenario;
-------------------------------
-- Add_Library_Body_Scenario --
-------------------------------
procedure Add_Library_Body_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Library_Body_Scenarios, N);
end Add_Library_Body_Scenario;
-------------------------------
-- Add_Library_Spec_Scenario --
-------------------------------
procedure Add_Library_Spec_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Library_Spec_Scenarios, N);
end Add_Library_Spec_Scenario;
------------------------
-- Add_SPARK_Scenario --
------------------------
procedure Add_SPARK_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (SPARK_Scenarios, N);
end Add_SPARK_Scenario;
---------------------
-- Delete_Scenario --
---------------------
procedure Delete_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
-- Delete the scenario from whichever set it belongs to
NE_Set.Delete (Declaration_Scenarios, N);
NE_Set.Delete (Dynamic_ABE_Check_Scenarios, N);
NE_Set.Delete (Library_Body_Scenarios, N);
NE_Set.Delete (Library_Spec_Scenarios, N);
NE_Set.Delete (SPARK_Scenarios, N);
end Delete_Scenario;
-----------------------------------
-- Iterate_Declaration_Scenarios --
-----------------------------------
function Iterate_Declaration_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Declaration_Scenarios);
end Iterate_Declaration_Scenarios;
-----------------------------------------
-- Iterate_Dynamic_ABE_Check_Scenarios --
-----------------------------------------
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Dynamic_ABE_Check_Scenarios);
end Iterate_Dynamic_ABE_Check_Scenarios;
------------------------------------
-- Iterate_Library_Body_Scenarios --
------------------------------------
function Iterate_Library_Body_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Library_Body_Scenarios);
end Iterate_Library_Body_Scenarios;
------------------------------------
-- Iterate_Library_Spec_Scenarios --
------------------------------------
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Library_Spec_Scenarios);
end Iterate_Library_Spec_Scenarios;
-----------------------------
-- Iterate_SPARK_Scenarios --
-----------------------------
function Iterate_SPARK_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (SPARK_Scenarios);
end Iterate_SPARK_Scenarios;
----------------------
-- Replace_Scenario --
----------------------
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id) is
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set);
-- Determine whether scenario Old_N is present in set Scenarios, and
-- if this is the case it, replace it with New_N.
-------------------------
-- Replace_Scenario_In --
-------------------------
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set) is
begin
-- The set is intentionally checked for existance because node
-- rewriting may occur after Sem_Elab has verified all scenarios
-- and data structures have been destroyed.
if NE_Set.Present (Scenarios)
and then NE_Set.Contains (Scenarios, Old_N)
then
NE_Set.Delete (Scenarios, Old_N);
NE_Set.Insert (Scenarios, New_N);
end if;
end Replace_Scenario_In;
-- Start of processing for Replace_Scenario
begin
Replace_Scenario_In (Declaration_Scenarios);
Replace_Scenario_In (Dynamic_ABE_Check_Scenarios);
Replace_Scenario_In (Library_Body_Scenarios);
Replace_Scenario_In (Library_Spec_Scenarios);
Replace_Scenario_In (SPARK_Scenarios);
end Replace_Scenario;
end Scenario_Storage;
---------------
-- Semantics --
---------------
package body Semantics is
--------------------------------
-- Is_Accept_Alternative_Proc --
--------------------------------
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a procedure with a receiving
-- entry.
return
Ekind (Id) = E_Procedure and then Present (Receiving_Entry (Id));
end Is_Accept_Alternative_Proc;
------------------------
-- Is_Activation_Proc --
------------------------
function Is_Activation_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote one of the runtime procedures
-- in charge of task activation.
if Ekind (Id) = E_Procedure then
if Restricted_Profile then
return Is_RTE (Id, RE_Activate_Restricted_Tasks);
else
return Is_RTE (Id, RE_Activate_Tasks);
end if;
end if;
return False;
end Is_Activation_Proc;
----------------------------
-- Is_Ada_Semantic_Target --
----------------------------
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Activation_Proc (Id)
or else Is_Controlled_Proc (Id, Name_Adjust)
or else Is_Controlled_Proc (Id, Name_Finalize)
or else Is_Controlled_Proc (Id, Name_Initialize)
or else Is_Init_Proc (Id)
or else Is_Invariant_Proc (Id)
or else Is_Protected_Entry (Id)
or else Is_Protected_Subp (Id)
or else Is_Protected_Body_Subp (Id)
or else Is_Subprogram_Inst (Id)
or else Is_Task_Entry (Id);
end Is_Ada_Semantic_Target;
--------------------------------
-- Is_Assertion_Pragma_Target --
--------------------------------
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Default_Initial_Condition_Proc (Id)
or else Is_Initial_Condition_Proc (Id)
or else Is_Invariant_Proc (Id)
or else Is_Partial_Invariant_Proc (Id);
end Is_Assertion_Pragma_Target;
----------------------------
-- Is_Bodiless_Subprogram --
----------------------------
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean is
begin
-- An abstract subprogram does not have a body
if Ekind (Subp_Id) in E_Function | E_Operator | E_Procedure
and then Is_Abstract_Subprogram (Subp_Id)
then
return True;
-- A formal subprogram does not have a body
elsif Is_Formal_Subprogram (Subp_Id) then
return True;
-- An imported subprogram may have a body, however it is not known at
-- compile or bind time where the body resides and whether it will be
-- elaborated on time.
elsif Is_Imported (Subp_Id) then
return True;
end if;
return False;
end Is_Bodiless_Subprogram;
----------------------
-- Is_Bridge_Target --
----------------------
function Is_Bridge_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Accept_Alternative_Proc (Id)
or else Is_Finalizer_Proc (Id)
or else Is_Partial_Invariant_Proc (Id)
or else Is_TSS (Id, TSS_Deep_Adjust)
or else Is_TSS (Id, TSS_Deep_Finalize)
or else Is_TSS (Id, TSS_Deep_Initialize);
end Is_Bridge_Target;
------------------------
-- Is_Controlled_Proc --
------------------------
function Is_Controlled_Proc
(Subp_Id : Entity_Id;
Subp_Nam : Name_Id) return Boolean
is
Formal_Id : Entity_Id;
begin
pragma Assert
(Subp_Nam in Name_Adjust | Name_Finalize | Name_Initialize);
-- To qualify, the subprogram must denote a source procedure with
-- name Adjust, Finalize, or Initialize where the sole formal is
-- controlled.
if Comes_From_Source (Subp_Id)
and then Ekind (Subp_Id) = E_Procedure
and then Chars (Subp_Id) = Subp_Nam
then
Formal_Id := First_Formal (Subp_Id);
return
Present (Formal_Id)
and then Is_Controlled (Etype (Formal_Id))
and then No (Next_Formal (Formal_Id));
end if;
return False;
end Is_Controlled_Proc;
---------------------------------------
-- Is_Default_Initial_Condition_Proc --
---------------------------------------
function Is_Default_Initial_Condition_Proc
(Id : Entity_Id) return Boolean
is
begin
-- To qualify, the entity must denote a Default_Initial_Condition
-- procedure.
return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id);
end Is_Default_Initial_Condition_Proc;
-----------------------
-- Is_Finalizer_Proc --
-----------------------
function Is_Finalizer_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a _Finalizer procedure
return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
end Is_Finalizer_Proc;
-------------------------------
-- Is_Initial_Condition_Proc --
-------------------------------
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an Initial_Condition procedure
return
Ekind (Id) = E_Procedure
and then Is_Initial_Condition_Procedure (Id);
end Is_Initial_Condition_Proc;
--------------------
-- Is_Initialized --
--------------------
function Is_Initialized (Obj_Decl : Node_Id) return Boolean is
begin
-- To qualify, the object declaration must have an expression
return
Present (Expression (Obj_Decl))
or else Has_Init_Expression (Obj_Decl);
end Is_Initialized;
-----------------------
-- Is_Invariant_Proc --
-----------------------
function Is_Invariant_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote the "full" invariant procedure
return Ekind (Id) = E_Procedure and then Is_Invariant_Procedure (Id);
end Is_Invariant_Proc;
---------------------------------------
-- Is_Non_Library_Level_Encapsulator --
---------------------------------------
function Is_Non_Library_Level_Encapsulator
(N : Node_Id) return Boolean
is
begin
case Nkind (N) is
when N_Abstract_Subprogram_Declaration
| N_Aspect_Specification
| N_Component_Declaration
| N_Entry_Body
| N_Entry_Declaration
| N_Expression_Function
| N_Formal_Abstract_Subprogram_Declaration
| N_Formal_Concrete_Subprogram_Declaration
| N_Formal_Object_Declaration
| N_Formal_Package_Declaration
| N_Formal_Type_Declaration
| N_Generic_Association
| N_Implicit_Label_Declaration
| N_Incomplete_Type_Declaration
| N_Private_Extension_Declaration
| N_Private_Type_Declaration
| N_Protected_Body
| N_Protected_Type_Declaration
| N_Single_Protected_Declaration
| N_Single_Task_Declaration
| N_Subprogram_Body
| N_Subprogram_Declaration
| N_Task_Body
| N_Task_Type_Declaration
=>
return True;
when others =>
return Is_Generic_Declaration_Or_Body (N);
end case;
end Is_Non_Library_Level_Encapsulator;
-------------------------------
-- Is_Partial_Invariant_Proc --
-------------------------------
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote the "partial" invariant
-- procedure.
return
Ekind (Id) = E_Procedure
and then Is_Partial_Invariant_Procedure (Id);
end Is_Partial_Invariant_Proc;
---------------------------
-- Is_Preelaborated_Unit --
---------------------------
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean is
begin
return
Is_Preelaborated (Id)
or else Is_Pure (Id)
or else Is_Remote_Call_Interface (Id)
or else Is_Remote_Types (Id)
or else Is_Shared_Passive (Id);
end Is_Preelaborated_Unit;
------------------------
-- Is_Protected_Entry --
------------------------
function Is_Protected_Entry (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an entry defined in a protected
-- type.
return
Is_Entry (Id)
and then Is_Protected_Type (Non_Private_View (Scope (Id)));
end Is_Protected_Entry;
-----------------------
-- Is_Protected_Subp --
-----------------------
function Is_Protected_Subp (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a subprogram defined within a
-- protected type.
return
Ekind (Id) in E_Function | E_Procedure
and then Is_Protected_Type (Non_Private_View (Scope (Id)));
end Is_Protected_Subp;
----------------------------
-- Is_Protected_Body_Subp --
----------------------------
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a subprogram with attribute
-- Protected_Subprogram set.
return
Ekind (Id) in E_Function | E_Procedure
and then Present (Protected_Subprogram (Id));
end Is_Protected_Body_Subp;
-----------------
-- Is_Scenario --
-----------------
function Is_Scenario (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Assignment_Statement
| N_Attribute_Reference
| N_Call_Marker
| N_Entry_Call_Statement
| N_Expanded_Name
| N_Function_Call
| N_Function_Instantiation
| N_Identifier
| N_Package_Instantiation
| N_Procedure_Call_Statement
| N_Procedure_Instantiation
| N_Requeue_Statement
=>
return True;
when others =>
return False;
end case;
end Is_Scenario;
------------------------------
-- Is_SPARK_Semantic_Target --
------------------------------
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Default_Initial_Condition_Proc (Id)
or else Is_Initial_Condition_Proc (Id);
end Is_SPARK_Semantic_Target;
------------------------
-- Is_Subprogram_Inst --
------------------------
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a function or a procedure which
-- is hidden within an anonymous package, and is a generic instance.
return
Ekind (Id) in E_Function | E_Procedure
and then Is_Hidden (Id)
and then Is_Generic_Instance (Id);
end Is_Subprogram_Inst;
------------------------------
-- Is_Suitable_Access_Taken --
------------------------------
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean is
Nam : Name_Id;
Pref : Node_Id;
Subp_Id : Entity_Id;
begin
-- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
if Debug_Flag_Dot_UU then
return False;
-- Nothing to do when the scenario is not an attribute reference
elsif Nkind (N) /= N_Attribute_Reference then
return False;
-- Nothing to do for internally-generated attributes because they are
-- assumed to be ABE safe.
elsif not Comes_From_Source (N) then
return False;
end if;
Nam := Attribute_Name (N);
Pref := Prefix (N);
-- Sanitize the prefix of the attribute
if not Is_Entity_Name (Pref) then
return False;
elsif No (Entity (Pref)) then
return False;
end if;
Subp_Id := Entity (Pref);
if not Is_Subprogram_Or_Entry (Subp_Id) then
return False;
end if;
-- Traverse a possible chain of renamings to obtain the original
-- entry or subprogram which the prefix may rename.
Subp_Id := Get_Renamed_Entity (Subp_Id);
-- To qualify, the attribute must meet the following prerequisites:
return
-- The prefix must denote a source entry, operator, or subprogram
-- which is not imported.
Comes_From_Source (Subp_Id)
and then Is_Subprogram_Or_Entry (Subp_Id)
and then not Is_Bodiless_Subprogram (Subp_Id)
-- The attribute name must be one of the 'Access forms. Note that
-- 'Unchecked_Access cannot apply to a subprogram.
and then Nam in Name_Access | Name_Unrestricted_Access;
end Is_Suitable_Access_Taken;
----------------------
-- Is_Suitable_Call --
----------------------
function Is_Suitable_Call (N : Node_Id) return Boolean is
begin
-- Entry and subprogram calls are intentionally ignored because they
-- may undergo expansion depending on the compilation mode, previous
-- errors, generic context, etc. Call markers play the role of calls
-- and provide a uniform foundation for ABE processing.
return Nkind (N) = N_Call_Marker;
end Is_Suitable_Call;
-------------------------------
-- Is_Suitable_Instantiation --
-------------------------------
function Is_Suitable_Instantiation (N : Node_Id) return Boolean is
Inst : constant Node_Id := Scenario (N);
begin
-- To qualify, the instantiation must come from source
return
Comes_From_Source (Inst)
and then Nkind (Inst) in N_Generic_Instantiation;
end Is_Suitable_Instantiation;
------------------------------------
-- Is_Suitable_SPARK_Derived_Type --
------------------------------------
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean is
Prag : Node_Id;
Typ : Entity_Id;
begin
-- To qualify, the type declaration must denote a derived tagged type
-- with primitive operations, subject to pragma SPARK_Mode On.
if Nkind (N) = N_Full_Type_Declaration
and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
then
Typ := Defining_Entity (N);
Prag := SPARK_Pragma (Typ);
return
Is_Tagged_Type (Typ)
and then Has_Primitive_Operations (Typ)
and then Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On;
end if;
return False;
end Is_Suitable_SPARK_Derived_Type;
-------------------------------------
-- Is_Suitable_SPARK_Instantiation --
-------------------------------------
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean is
Inst : constant Node_Id := Scenario (N);
Gen_Id : Entity_Id;
Prag : Node_Id;
begin
-- To qualify, both the instantiation and the generic must be subject
-- to SPARK_Mode On.
if Is_Suitable_Instantiation (N) then
Gen_Id := Instantiated_Generic (Inst);
Prag := SPARK_Pragma (Gen_Id);
return
Is_SPARK_Mode_On_Node (Inst)
and then Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On;
end if;
return False;
end Is_Suitable_SPARK_Instantiation;
--------------------------------------------
-- Is_Suitable_SPARK_Refined_State_Pragma --
--------------------------------------------
function Is_Suitable_SPARK_Refined_State_Pragma
(N : Node_Id) return Boolean
is
begin
-- To qualfy, the pragma must denote Refined_State
return
Nkind (N) = N_Pragma
and then Pragma_Name (N) = Name_Refined_State;
end Is_Suitable_SPARK_Refined_State_Pragma;
-------------------------------------
-- Is_Suitable_Variable_Assignment --
-------------------------------------
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean is
N_Unit : Node_Id;
N_Unit_Id : Entity_Id;
Nam : Node_Id;
Var_Decl : Node_Id;
Var_Id : Entity_Id;
Var_Unit : Node_Id;
Var_Unit_Id : Entity_Id;
begin
-- Nothing to do when the scenario is not an assignment
if Nkind (N) /= N_Assignment_Statement then
return False;
-- Nothing to do for internally-generated assignments because they
-- are assumed to be ABE safe.
elsif not Comes_From_Source (N) then
return False;
-- Assignments are ignored in GNAT mode on the assumption that
-- they are ABE-safe. This behavior parallels that of the old
-- ABE mechanism.
elsif GNAT_Mode then
return False;
end if;
Nam := Assignment_Target (N);
-- Sanitize the left hand side of the assignment
if not Is_Entity_Name (Nam) then
return False;
elsif No (Entity (Nam)) then
return False;
end if;
Var_Id := Entity (Nam);
-- Sanitize the variable
if Var_Id = Any_Id then
return False;
elsif Ekind (Var_Id) /= E_Variable then
return False;
end if;
Var_Decl := Declaration_Node (Var_Id);
if Nkind (Var_Decl) /= N_Object_Declaration then
return False;
end if;
N_Unit_Id := Find_Top_Unit (N);
N_Unit := Unit_Declaration_Node (N_Unit_Id);
Var_Unit_Id := Find_Top_Unit (Var_Decl);
Var_Unit := Unit_Declaration_Node (Var_Unit_Id);
-- To qualify, the assignment must meet the following prerequisites:
return
Comes_From_Source (Var_Id)
-- The variable must be declared in the spec of compilation unit
-- U.
and then Nkind (Var_Unit) = N_Package_Declaration
and then Find_Enclosing_Level (Var_Decl) = Library_Spec_Level
-- The assignment must occur in the body of compilation unit U
and then Nkind (N_Unit) = N_Package_Body
and then Present (Corresponding_Body (Var_Unit))
and then Corresponding_Body (Var_Unit) = N_Unit_Id;
end Is_Suitable_Variable_Assignment;
------------------------------------
-- Is_Suitable_Variable_Reference --
------------------------------------
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean is
begin
-- Expanded names and identifiers are intentionally ignored because
-- they be folded, optimized away, etc. Variable references markers
-- play the role of variable references and provide a uniform
-- foundation for ABE processing.
return Nkind (N) = N_Variable_Reference_Marker;
end Is_Suitable_Variable_Reference;
-------------------
-- Is_Task_Entry --
-------------------
function Is_Task_Entry (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an entry defined in a task type
return
Is_Entry (Id) and then Is_Task_Type (Non_Private_View (Scope (Id)));
end Is_Task_Entry;
------------------------
-- Is_Up_Level_Target --
------------------------
function Is_Up_Level_Target
(Targ_Decl : Node_Id;
In_State : Processing_In_State) return Boolean
is
Root : constant Node_Id := Root_Scenario;
Root_Rep : constant Scenario_Rep_Id :=
Scenario_Representation_Of (Root, In_State);
begin
-- The root appears within the declaratons of a block statement,
-- entry body, subprogram body, or task body ignoring enclosing
-- packages. The root is always within the main unit.
if not In_State.Suppress_Up_Level_Targets
and then Level (Root_Rep) = Declaration_Level
then
-- The target is within the main unit. It acts as an up-level
-- target when it appears within a context which encloses the
-- root.
--
-- package body Main_Unit is
-- function Func ...; -- target
--
-- procedure Proc is
-- X : ... := Func; -- root scenario
if In_Extended_Main_Code_Unit (Targ_Decl) then
return not In_Same_Context (Root, Targ_Decl, Nested_OK => True);
-- Otherwise the target is external to the main unit which makes
-- it an up-level target.
else
return True;
end if;
end if;
return False;
end Is_Up_Level_Target;
end Semantics;
---------------------------
-- Set_Elaboration_Phase --
---------------------------
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status) is
begin
Elaboration_Phase := Status;
end Set_Elaboration_Phase;
---------------------
-- SPARK_Processor --
---------------------
package body SPARK_Processor is
-----------------------
-- Local subprograms --
-----------------------
procedure Process_SPARK_Derived_Type
(Typ_Decl : Node_Id;
Typ_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Derived_Type);
-- Verify that the freeze node of a derived type denoted by declaration
-- Typ_Decl is within the early call region of each overriding primitive
-- body that belongs to the derived type (SPARK RM 7.7(8)). Typ_Rep is
-- the representation of the type. In_State denotes the current state of
-- the Processing phase.
procedure Process_SPARK_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Instantiation);
-- Verify that instantiation Inst does not precede the generic body it
-- instantiates (SPARK RM 7.7(6)). Inst_Rep is the representation of the
-- instantiation. In_State is the current state of the Processing phase.
procedure Process_SPARK_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Refined_State_Pragma);
-- Verify that each constituent of Refined_State pragma Prag which
-- belongs to abstract state mentioned in pragma Initializes has prior
-- elaboration with respect to the main unit (SPARK RM 7.7.1(7)).
-- Prag_Rep is the representation of the pragma. In_State denotes the
-- current state of the Processing phase.
procedure Process_SPARK_Scenario
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Scenario);
-- Top-level dispatcher for verifying SPARK scenarios which are not
-- always executable during elaboration but still need elaboration-
-- related checks. In_State is the current state of the Processing
-- phase.
---------------------------------
-- Check_SPARK_Model_In_Effect --
---------------------------------
SPARK_Model_Warning_Posted : Boolean := False;
-- This flag prevents the same SPARK model-related warning from being
-- emitted multiple times.
procedure Check_SPARK_Model_In_Effect is
Spec_Id : constant Entity_Id := Unique_Entity (Main_Unit_Entity);
begin
-- Do not emit the warning multiple times as this creates useless
-- noise.
if SPARK_Model_Warning_Posted then
null;
-- SPARK rule verification requires the "strict" static model
elsif Static_Elaboration_Checks
and not Relaxed_Elaboration_Checks
then
null;
-- Any other combination of models does not guarantee the absence of
-- ABE problems for SPARK rule verification purposes. Note that there
-- is no need to check for the presence of the legacy ABE mechanism
-- because the legacy code has its own dedicated processing for SPARK
-- rules.
else
SPARK_Model_Warning_Posted := True;
Error_Msg_N
("??SPARK elaboration checks require static elaboration model",
Spec_Id);
if Dynamic_Elaboration_Checks then
Error_Msg_N
("\dynamic elaboration model is in effect", Spec_Id);
else
pragma Assert (Relaxed_Elaboration_Checks);
Error_Msg_N
("\relaxed elaboration model is in effect", Spec_Id);
end if;
end if;
end Check_SPARK_Model_In_Effect;
---------------------------
-- Check_SPARK_Scenarios --
---------------------------
procedure Check_SPARK_Scenarios is
Iter : NE_Set.Iterator;
N : Node_Id;
begin
Iter := Iterate_SPARK_Scenarios;
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
Process_SPARK_Scenario
(N => N,
In_State => SPARK_State);
end loop;
end Check_SPARK_Scenarios;
--------------------------------
-- Process_SPARK_Derived_Type --
--------------------------------
procedure Process_SPARK_Derived_Type
(Typ_Decl : Node_Id;
Typ_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (In_State);
Typ : constant Entity_Id := Target (Typ_Rep);
Stop_Check : exception;
-- This exception is raised when the freeze node violates the
-- placement rules.
procedure Check_Overriding_Primitive
(Prim : Entity_Id;
FNode : Node_Id);
pragma Inline (Check_Overriding_Primitive);
-- Verify that freeze node FNode is within the early call region of
-- overriding primitive Prim's body.
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr;
pragma Inline (Freeze_Node_Location);
-- Return a more accurate source location associated with freeze node
-- FNode.
function Precedes_Source_Construct (N : Node_Id) return Boolean;
pragma Inline (Precedes_Source_Construct);
-- Determine whether arbitrary node N appears prior to some source
-- construct.
procedure Suggest_Elaborate_Body
(N : Node_Id;
Body_Decl : Node_Id;
Error_Nod : Node_Id);
pragma Inline (Suggest_Elaborate_Body);
-- Suggest the use of pragma Elaborate_Body when the pragma will
-- allow for node N to appear within the early call region of
-- subprogram body Body_Decl. The suggestion is attached to
-- Error_Nod as a continuation error.
--------------------------------
-- Check_Overriding_Primitive --
--------------------------------
procedure Check_Overriding_Primitive
(Prim : Entity_Id;
FNode : Node_Id)
is
Prim_Decl : constant Node_Id := Unit_Declaration_Node (Prim);
Body_Decl : Node_Id;
Body_Id : Entity_Id;
Region : Node_Id;
begin
-- Nothing to do for predefined primitives because they are
-- artifacts of tagged type expansion and cannot override source
-- primitives. Nothing to do as well for inherited primitives, as
-- the check concerns overriding ones. Finally, nothing to do for
-- abstract subprograms, because they have no body that could be
-- examined.
if Is_Predefined_Dispatching_Operation (Prim)
or else not Is_Overriding_Subprogram (Prim)
or else Is_Abstract_Subprogram (Prim)
then
return;
end if;
Body_Id := Corresponding_Body (Prim_Decl);
-- Nothing to do when the primitive does not have a corresponding
-- body. This can happen when the unit with the bodies is not the
-- main unit subjected to ABE checks.
if No (Body_Id) then
return;
-- The primitive overrides a parent or progenitor primitive
elsif Present (Overridden_Operation (Prim)) then
-- Nothing to do when overriding an interface primitive happens
-- by inheriting a non-interface primitive as the check would
-- be done on the parent primitive.
if Present (Alias (Prim)) then
return;
end if;
-- Nothing to do when the primitive is not overriding. The body of
-- such a primitive cannot be targeted by a dispatching call which
-- is executable during elaboration, and cannot cause an ABE.
else
return;
end if;
Body_Decl := Unit_Declaration_Node (Body_Id);
Region := Find_Early_Call_Region (Body_Decl);
-- The freeze node appears prior to the early call region of the
-- primitive body.
-- IMPORTANT: This check must always be performed even when
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the static model cannot guarantee the absence
-- of ABEs in the presence of dispatching calls.
if Earlier_In_Extended_Unit (FNode, Region) then
Error_Msg_Node_2 := Prim;
Error_Msg_Code := GEC_Type_Early_Call_Region;
Error_Msg_NE
("first freezing point of type & must appear within early "
& "call region of primitive body '[[]']",
Typ_Decl, Typ);
Error_Msg_Sloc := Sloc (Region);
Error_Msg_N ("\region starts #", Typ_Decl);
Error_Msg_Sloc := Sloc (Body_Decl);
Error_Msg_N ("\region ends #", Typ_Decl);
Error_Msg_Sloc := Freeze_Node_Location (FNode);
Error_Msg_N ("\first freezing point #", Typ_Decl);
-- If applicable, suggest the use of pragma Elaborate_Body in
-- the associated package spec.
Suggest_Elaborate_Body
(N => FNode,
Body_Decl => Body_Decl,
Error_Nod => Typ_Decl);
raise Stop_Check;
end if;
end Check_Overriding_Primitive;
--------------------------
-- Freeze_Node_Location --
--------------------------
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr is
Context : constant Node_Id := Parent (FNode);
Loc : constant Source_Ptr := Sloc (FNode);
Prv_Decls : List_Id;
Vis_Decls : List_Id;
begin
-- In general, the source location of the freeze node is as close
-- as possible to the real freeze point, except when the freeze
-- node is at the "bottom" of a package spec.
if Nkind (Context) = N_Package_Specification then
Prv_Decls := Private_Declarations (Context);
Vis_Decls := Visible_Declarations (Context);
-- The freeze node appears in the private declarations of the
-- package.
if Present (Prv_Decls)
and then List_Containing (FNode) = Prv_Decls
then
null;
-- The freeze node appears in the visible declarations of the
-- package and there are no private declarations.
elsif Present (Vis_Decls)
and then List_Containing (FNode) = Vis_Decls
and then Is_Empty_List (Prv_Decls)
then
null;
-- Otherwise the freeze node is not in the "last" declarative
-- list of the package. Use the existing source location of the
-- freeze node.
else
return Loc;
end if;
-- The freeze node appears at the "bottom" of the package when
-- it is in the "last" declarative list and is either the last
-- in the list or is followed by internal constructs only. In
-- that case the more appropriate source location is that of
-- the package end label.
if not Precedes_Source_Construct (FNode) then
return Sloc (End_Label (Context));
end if;
end if;
return Loc;
end Freeze_Node_Location;
-------------------------------
-- Precedes_Source_Construct --
-------------------------------
function Precedes_Source_Construct (N : Node_Id) return Boolean is
Decl : Node_Id;
begin
Decl := Next (N);
while Present (Decl) loop
if Comes_From_Source (Decl) then
return True;
-- A generated body for a source expression function is treated
-- as a source construct.
elsif Nkind (Decl) = N_Subprogram_Body
and then Was_Expression_Function (Decl)
and then Comes_From_Source (Original_Node (Decl))
then
return True;
end if;
Next (Decl);
end loop;
return False;
end Precedes_Source_Construct;
----------------------------
-- Suggest_Elaborate_Body --
----------------------------
procedure Suggest_Elaborate_Body
(N : Node_Id;
Body_Decl : Node_Id;
Error_Nod : Node_Id)
is
Unit_Id : constant Node_Id := Unit (Cunit (Main_Unit));
Region : Node_Id;
begin
-- The suggestion applies only when the subprogram body resides in
-- a compilation package body, and a pragma Elaborate_Body would
-- allow for the node to appear in the early call region of the
-- subprogram body. This implies that all code from the subprogram
-- body up to the node is preelaborable.
if Nkind (Unit_Id) = N_Package_Body then
-- Find the start of the early call region again assuming that
-- the package spec has pragma Elaborate_Body. Note that the
-- internal data structures are intentionally not updated
-- because this is a speculative search.
Region :=
Find_Early_Call_Region
(Body_Decl => Body_Decl,
Assume_Elab_Body => True,
Skip_Memoization => True);
-- If the node appears within the early call region, assuming
-- that the package spec carries pragma Elaborate_Body, then it
-- is safe to suggest the pragma.
if Earlier_In_Extended_Unit (Region, N) then
Error_Msg_Name_1 := Name_Elaborate_Body;
Error_Msg_NE
("\consider adding pragma % in spec of unit &",
Error_Nod, Defining_Entity (Unit_Id));
end if;
end if;
end Suggest_Elaborate_Body;
-- Local variables
FNode : constant Node_Id := Freeze_Node (Typ);
Prims : constant Elist_Id := Direct_Primitive_Operations (Typ);
Prim_Elmt : Elmt_Id;
-- Start of processing for Process_SPARK_Derived_Type
begin
-- A type should have its freeze node set by the time SPARK scenarios
-- are being verified.
pragma Assert (Present (FNode));
-- Verify that the freeze node of the derived type is within the
-- early call region of each overriding primitive body
-- (SPARK RM 7.7(8)).
if Present (Prims) then
Prim_Elmt := First_Elmt (Prims);
while Present (Prim_Elmt) loop
Check_Overriding_Primitive
(Prim => Node (Prim_Elmt),
FNode => FNode);
Next_Elmt (Prim_Elmt);
end loop;
end if;
exception
when Stop_Check =>
null;
end Process_SPARK_Derived_Type;
---------------------------------
-- Process_SPARK_Instantiation --
---------------------------------
procedure Process_SPARK_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep);
begin
-- The instantiation and the generic body are both in the main unit
if Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
-- If the instantiation appears prior to the generic body, then the
-- instantiation is illegal (SPARK RM 7.7(6)).
-- IMPORTANT: This check must always be performed even when
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the rule prevents use-before-declaration of
-- objects that may precede the generic body.
and then Earlier_In_Extended_Unit (Inst, Body_Decl)
then
Error_Msg_NE
("cannot instantiate & before body seen", Inst, Gen_Id);
end if;
end Process_SPARK_Instantiation;
----------------------------
-- Process_SPARK_Scenario --
----------------------------
procedure Process_SPARK_Scenario
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Derived type
if Is_Suitable_SPARK_Derived_Type (Scen) then
Process_SPARK_Derived_Type
(Typ_Decl => Scen,
Typ_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Instantiation
elsif Is_Suitable_SPARK_Instantiation (Scen) then
Process_SPARK_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Refined_State pragma
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Process_SPARK_Refined_State_Pragma
(Prag => Scen,
Prag_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_SPARK_Scenario;
----------------------------------------
-- Process_SPARK_Refined_State_Pragma --
----------------------------------------
procedure Process_SPARK_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Prag_Rep);
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id);
pragma Inline (Check_SPARK_Constituent);
-- Ensure that a single constituent Constit_Id is elaborated prior to
-- the main unit.
procedure Check_SPARK_Constituents (Constits : Elist_Id);
pragma Inline (Check_SPARK_Constituents);
-- Ensure that all constituents found in list Constits are elaborated
-- prior to the main unit.
procedure Check_SPARK_Initialized_State (State : Node_Id);
pragma Inline (Check_SPARK_Initialized_State);
-- Ensure that the constituents of single abstract state State are
-- elaborated prior to the main unit.
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id);
pragma Inline (Check_SPARK_Initialized_States);
-- Ensure that the constituents of all abstract states which appear
-- in the Initializes pragma of package Pack_Id are elaborated prior
-- to the main unit.
-----------------------------
-- Check_SPARK_Constituent --
-----------------------------
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id) is
SM_Prag : Node_Id;
begin
-- Nothing to do for "null" constituents
if Nkind (Constit_Id) = N_Null then
return;
-- Nothing to do for illegal constituents
elsif Error_Posted (Constit_Id) then
return;
end if;
SM_Prag := SPARK_Pragma (Constit_Id);
-- The check applies only when the constituent is subject to
-- pragma SPARK_Mode On.
if Present (SM_Prag)
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On
then
-- An external constituent of an abstract state which appears
-- in the Initializes pragma of a package spec imposes an
-- Elaborate requirement on the context of the main unit.
-- Determine whether the context has a pragma strong enough to
-- meet the requirement.
-- IMPORTANT: This check is performed only when -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is in effect
-- because the static model can ensure the prior elaboration of
-- the unit which contains a constituent by installing implicit
-- Elaborate pragma.
if Debug_Flag_Dot_V then
Meet_Elaboration_Requirement
(N => Prag,
Targ_Id => Constit_Id,
Req_Nam => Name_Elaborate,
In_State => In_State);
-- Otherwise ensure that the unit with the external constituent
-- is elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Prag,
Unit_Id => Find_Top_Unit (Constit_Id),
Prag_Nam => Name_Elaborate,
In_State => In_State);
end if;
end if;
end Check_SPARK_Constituent;
------------------------------
-- Check_SPARK_Constituents --
------------------------------
procedure Check_SPARK_Constituents (Constits : Elist_Id) is
Constit_Elmt : Elmt_Id;
begin
if Present (Constits) then
Constit_Elmt := First_Elmt (Constits);
while Present (Constit_Elmt) loop
Check_SPARK_Constituent (Node (Constit_Elmt));
Next_Elmt (Constit_Elmt);
end loop;
end if;
end Check_SPARK_Constituents;
-----------------------------------
-- Check_SPARK_Initialized_State --
-----------------------------------
procedure Check_SPARK_Initialized_State (State : Node_Id) is
SM_Prag : Node_Id;
State_Id : Entity_Id;
begin
-- Nothing to do for "null" initialization items
if Nkind (State) = N_Null then
return;
-- Nothing to do for illegal states
elsif Error_Posted (State) then
return;
end if;
State_Id := Entity_Of (State);
-- Sanitize the state
if No (State_Id) then
return;
elsif Error_Posted (State_Id) then
return;
elsif Ekind (State_Id) /= E_Abstract_State then
return;
end if;
-- The check is performed only when the abstract state is subject
-- to SPARK_Mode On.
SM_Prag := SPARK_Pragma (State_Id);
if Present (SM_Prag)
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On
then
Check_SPARK_Constituents (Refinement_Constituents (State_Id));
end if;
end Check_SPARK_Initialized_State;
------------------------------------
-- Check_SPARK_Initialized_States --
------------------------------------
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id) is
Init_Prag : constant Node_Id :=
Get_Pragma (Pack_Id, Pragma_Initializes);
Init : Node_Id;
Inits : Node_Id;
begin
if Present (Init_Prag) then
Inits := Expression (Get_Argument (Init_Prag, Pack_Id));
-- Avoid processing a "null" initialization list. The only
-- other alternative is an aggregate.
if Nkind (Inits) = N_Aggregate then
-- The initialization items appear in list form:
--
-- (state1, state2)
if Present (Expressions (Inits)) then
Init := First (Expressions (Inits));
while Present (Init) loop
Check_SPARK_Initialized_State (Init);
Next (Init);
end loop;
end if;
-- The initialization items appear in associated form:
--
-- (state1 => item1,
-- state2 => (item2, item3))
if Present (Component_Associations (Inits)) then
Init := First (Component_Associations (Inits));
while Present (Init) loop
Check_SPARK_Initialized_State (Init);
Next (Init);
end loop;
end if;
end if;
end if;
end Check_SPARK_Initialized_States;
-- Local variables
Pack_Body : constant Node_Id := Find_Related_Package_Or_Body (Prag);
-- Start of processing for Process_SPARK_Refined_State_Pragma
begin
-- Pragma Refined_State must be associated with a package body
pragma Assert
(Present (Pack_Body) and then Nkind (Pack_Body) = N_Package_Body);
-- Verify that each external contitunent of an abstract state
-- mentioned in pragma Initializes is properly elaborated.
Check_SPARK_Initialized_States (Unique_Defining_Entity (Pack_Body));
end Process_SPARK_Refined_State_Pragma;
end SPARK_Processor;
-------------------------------
-- Spec_And_Body_From_Entity --
-------------------------------
procedure Spec_And_Body_From_Entity
(Id : Entity_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id)
is
begin
Spec_And_Body_From_Node
(N => Unit_Declaration_Node (Id),
Spec_Decl => Spec_Decl,
Body_Decl => Body_Decl);
end Spec_And_Body_From_Entity;
-----------------------------
-- Spec_And_Body_From_Node --
-----------------------------
procedure Spec_And_Body_From_Node
(N : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id)
is
Body_Id : Entity_Id;
Spec_Id : Entity_Id;
begin
-- Assume that the construct lacks spec and body
Body_Decl := Empty;
Spec_Decl := Empty;
-- Bodies
if Nkind (N) in N_Package_Body
| N_Protected_Body
| N_Subprogram_Body
| N_Task_Body
then
Spec_Id := Corresponding_Spec (N);
-- The body completes a previous declaration
if Present (Spec_Id) then
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Otherwise the body acts as the initial declaration, and is both a
-- spec and body. There is no need to look for an optional body.
else
Body_Decl := N;
Spec_Decl := N;
return;
end if;
-- Declarations
elsif Nkind (N) in N_Entry_Declaration
| N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Protected_Type_Declaration
| N_Subprogram_Declaration
| N_Task_Type_Declaration
then
Spec_Decl := N;
-- Expression function
elsif Nkind (N) = N_Expression_Function then
Spec_Id := Corresponding_Spec (N);
pragma Assert (Present (Spec_Id));
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Instantiations
elsif Nkind (N) in N_Generic_Instantiation then
Spec_Decl := Instance_Spec (N);
pragma Assert (Present (Spec_Decl));
-- Stubs
elsif Nkind (N) in N_Body_Stub then
Spec_Id := Corresponding_Spec_Of_Stub (N);
-- The stub completes a previous declaration
if Present (Spec_Id) then
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Otherwise the stub acts as a spec
else
Spec_Decl := N;
end if;
end if;
-- Obtain an optional or mandatory body
if Present (Spec_Decl) then
Body_Id := Corresponding_Body (Spec_Decl);
if Present (Body_Id) then
Body_Decl := Unit_Declaration_Node (Body_Id);
end if;
end if;
end Spec_And_Body_From_Node;
-------------------------------
-- Static_Elaboration_Checks --
-------------------------------
function Static_Elaboration_Checks return Boolean is
begin
return not Dynamic_Elaboration_Checks;
end Static_Elaboration_Checks;
-----------------
-- Unit_Entity --
-----------------
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id is
function Is_Subunit (Id : Entity_Id) return Boolean;
pragma Inline (Is_Subunit);
-- Determine whether the entity of an initial declaration denotes a
-- subunit.
----------------
-- Is_Subunit --
----------------
function Is_Subunit (Id : Entity_Id) return Boolean is
Decl : constant Node_Id := Unit_Declaration_Node (Id);
begin
return
Nkind (Decl) in N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Protected_Type_Declaration
| N_Subprogram_Declaration
| N_Task_Type_Declaration
and then Present (Corresponding_Body (Decl))
and then Nkind (Parent (Unit_Declaration_Node
(Corresponding_Body (Decl)))) = N_Subunit;
end Is_Subunit;
-- Local variables
Id : Entity_Id;
-- Start of processing for Unit_Entity
begin
Id := Unique_Entity (Unit_Id);
-- Skip all subunits found in the scope chain which ends at the input
-- unit.
while Is_Subunit (Id) loop
Id := Scope (Id);
end loop;
return Id;
end Unit_Entity;
---------------------------------
-- Update_Elaboration_Scenario --
---------------------------------
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id) is
begin
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
if not Elaboration_Phase_Active then
return;
-- Nothing to do when the old and new scenarios are one and the same
elsif Old_N = New_N then
return;
end if;
-- A scenario is being transformed by Atree.Rewrite. Update all relevant
-- internal data structures to reflect this change. This ensures that a
-- potential run-time conditional ABE check or a guaranteed ABE failure
-- is inserted at the proper place in the tree.
if Is_Scenario (Old_N) then
Replace_Scenario (Old_N, New_N);
end if;
end Update_Elaboration_Scenario;
---------------------------------------------------------------------------
-- --
-- L E G A C Y A C C E S S B E F O R E E L A B O R A T I O N --
-- --
-- M E C H A N I S M --
-- --
---------------------------------------------------------------------------
-- This section contains the implementation of the pre-18.x legacy ABE
-- mechanism. The mechanism can be activated using switch -gnatH (legacy
-- elaboration checking mode enabled).
-----------------------------
-- Description of Approach --
-----------------------------
-- Every non-static call that is encountered by Sem_Res results in a call
-- to Check_Elab_Call, with N being the call node, and Outer set to its
-- default value of True. In addition X'Access is treated like a call
-- for the access-to-procedure case, and in SPARK mode only we also
-- check variable references.
-- The goal of Check_Elab_Call is to determine whether or not the reference
-- in question can generate an access before elaboration error (raising
-- Program_Error) either by directly calling a subprogram whose body
-- has not yet been elaborated, or indirectly, by calling a subprogram
-- whose body has been elaborated, but which contains a call to such a
-- subprogram.
-- In addition, in SPARK mode, we are checking for a variable reference in
-- another package, which requires an explicit Elaborate_All pragma.
-- The only references that we need to look at the outer level are
-- references that occur in elaboration code. There are two cases. The
-- reference can be at the outer level of elaboration code, or it can
-- be within another unit, e.g. the elaboration code of a subprogram.
-- In the case of an elaboration call at the outer level, we must trace
-- all calls to outer level routines either within the current unit or to
-- other units that are with'ed. For calls within the current unit, we can
-- determine if the body has been elaborated or not, and if it has not,
-- then a warning is generated.
-- Note that there are two subcases. If the original call directly calls a
-- subprogram whose body has not been elaborated, then we know that an ABE
-- will take place, and we replace the call by a raise of Program_Error.
-- If the call is indirect, then we don't know that the PE will be raised,
-- since the call might be guarded by a conditional. In this case we set
-- Do_Elab_Check on the call so that a dynamic check is generated, and
-- output a warning.
-- For calls to a subprogram in a with'ed unit or a 'Access or variable
-- reference (SPARK mode case), we require that a pragma Elaborate_All
-- or pragma Elaborate be present, or that the referenced unit have a
-- pragma Preelaborate, pragma Pure, or pragma Elaborate_Body. If none
-- of these conditions is met, then a warning is generated that a pragma
-- Elaborate_All may be needed (error in the SPARK case), or an implicit
-- pragma is generated.
-- For the case of an elaboration call at some inner level, we are
-- interested in tracing only calls to subprograms at the same level, i.e.
-- those that can be called during elaboration. Any calls to outer level
-- routines cannot cause ABE's as a result of the original call (there
-- might be an outer level call to the subprogram from outside that causes
-- the ABE, but that gets analyzed separately).
-- Note that we never trace calls to inner level subprograms, since these
-- cannot result in ABE's unless there is an elaboration problem at a lower
-- level, which will be separately detected.
-- Note on pragma Elaborate. The checking here assumes that a pragma
-- Elaborate on a with'ed unit guarantees that subprograms within the unit
-- can be called without causing an ABE. This is not in fact the case since
-- pragma Elaborate does not guarantee the transitive coverage guaranteed
-- by Elaborate_All. However, we decide to trust the user in this case.
--------------------------------------
-- Instantiation Elaboration Errors --
--------------------------------------
-- A special case arises when an instantiation appears in a context that is
-- known to be before the body is elaborated, e.g.
-- generic package x is ...
-- ...
-- package xx is new x;
-- ...
-- package body x is ...
-- In this situation it is certain that an elaboration error will occur,
-- and an unconditional raise Program_Error statement is inserted before
-- the instantiation, and a warning generated.
-- The problem is that in this case we have no place to put the body of
-- the instantiation. We can't put it in the normal place, because it is
-- too early, and will cause errors to occur as a result of referencing
-- entities before they are declared.
-- Our approach in this case is simply to avoid creating the body of the
-- instantiation in such a case. The instantiation spec is modified to
-- include dummy bodies for all subprograms, so that the resulting code
-- does not contain subprogram specs with no corresponding bodies.
-- The following table records the recursive call chain for output in the
-- Output routine. Each entry records the call node and the entity of the
-- called routine. The number of entries in the table (i.e. the value of
-- Elab_Call.Last) indicates the current depth of recursion and is used to
-- identify the outer level.
type Elab_Call_Element is record
Cloc : Source_Ptr;
Ent : Entity_Id;
end record;
package Elab_Call is new Table.Table
(Table_Component_Type => Elab_Call_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 100,
Table_Name => "Elab_Call");
-- The following table records all calls that have been processed starting
-- from an outer level call. The table prevents both infinite recursion and
-- useless reanalysis of calls within the same context. The use of context
-- is important because it allows for proper checks in more complex code:
-- if ... then
-- Call; -- requires a check
-- Call; -- does not need a check thanks to the table
-- elsif ... then
-- Call; -- requires a check, different context
-- end if;
-- Call; -- requires a check, different context
type Visited_Element is record
Subp_Id : Entity_Id;
-- The entity of the subprogram being called
Context : Node_Id;
-- The context where the call to the subprogram occurs
end record;
package Elab_Visited is new Table.Table
(Table_Component_Type => Visited_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 200,
Table_Increment => 100,
Table_Name => "Elab_Visited");
-- The following table records delayed calls which must be examined after
-- all generic bodies have been instantiated.
type Delay_Element is record
N : Node_Id;
-- The parameter N from the call to Check_Internal_Call. Note that this
-- node may get rewritten over the delay period by expansion in the call
-- case (but not in the instantiation case).
E : Entity_Id;
-- The parameter E from the call to Check_Internal_Call
Orig_Ent : Entity_Id;
-- The parameter Orig_Ent from the call to Check_Internal_Call
Curscop : Entity_Id;
-- The current scope of the call. This is restored when we complete the
-- delayed call, so that we do this in the right scope.
Outer_Scope : Entity_Id;
-- Save scope of outer level call
From_Elab_Code : Boolean;
-- Save indication of whether this call is from elaboration code
In_Task_Activation : Boolean;
-- Save indication of whether this call is from a task body. Tasks are
-- activated at the "begin", which is after all local procedure bodies,
-- so calls to those procedures can't fail, even if they occur after the
-- task body.
From_SPARK_Code : Boolean;
-- Save indication of whether this call is under SPARK_Mode => On
end record;
package Delay_Check is new Table.Table
(Table_Component_Type => Delay_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 1000,
Table_Increment => 100,
Table_Name => "Delay_Check");
C_Scope : Entity_Id;
-- Top-level scope of current scope. Compute this only once at the outer
-- level, i.e. for a call to Check_Elab_Call from outside this unit.
Outer_Level_Sloc : Source_Ptr;
-- Save Sloc value for outer level call node for comparisons of source
-- locations. A body is too late if it appears after the *outer* level
-- call, not the particular call that is being analyzed.
From_Elab_Code : Boolean;
-- This flag shows whether the outer level call currently being examined
-- is or is not in elaboration code. We are only interested in calls to
-- routines in other units if this flag is True.
In_Task_Activation : Boolean := False;
-- This flag indicates whether we are performing elaboration checks on task
-- bodies, at the point of activation. If true, we do not raise
-- Program_Error for calls to local procedures, because all local bodies
-- are known to be elaborated. However, we still need to trace such calls,
-- because a local procedure could call a procedure in another package,
-- so we might need an implicit Elaborate_All.
Delaying_Elab_Checks : Boolean := True;
-- This is set True till the compilation is complete, including the
-- insertion of all instance bodies. Then when Check_Elab_Calls is called,
-- the delay table is used to make the delayed calls and this flag is reset
-- to False, so that the calls are processed.
-----------------------
-- Local Subprograms --
-----------------------
-- Note: Outer_Scope in all following specs represents the scope of
-- interest of the outer level call. If it is set to Standard_Standard,
-- then it means the outer level call was at elaboration level, and that
-- thus all calls are of interest. If it was set to some other scope,
-- then the original call was an inner call, and we are not interested
-- in calls that go outside this scope.
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id);
-- Analysis of construct N shows that we should set Elaborate_All_Desirable
-- for the WITH clause for unit U (which will always be present). A special
-- case is when N is a function or procedure instantiation, in which case
-- it is sufficient to set Elaborate_Desirable, since in this case there is
-- no possibility of transitive elaboration issues.
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True;
In_Init_Proc : Boolean := False);
-- This is the internal recursive routine that is called to check for
-- possible elaboration error. The argument N is a subprogram call or
-- generic instantiation, or 'Access attribute reference to be checked, and
-- E is the entity of the called subprogram, or instantiated generic unit,
-- or subprogram referenced by 'Access.
--
-- In SPARK mode, N can also be a variable reference, since in SPARK this
-- also triggers a requirement for Elaborate_All, and in this case E is the
-- entity being referenced.
--
-- Outer_Scope is the outer level scope for the original reference.
-- Inter_Unit_Only is set if the call is only to be checked in the
-- case where it is to another unit (and skipped if within a unit).
-- Generate_Warnings is set to False to suppress warning messages about
-- missing pragma Elaborate_All's. These messages are not wanted for
-- inner calls in the dynamic model. Note that an instance of the Access
-- attribute applied to a subprogram also generates a call to this
-- procedure (since the referenced subprogram may be called later
-- indirectly). Flag In_Init_Proc should be set whenever the current
-- context is a type init proc.
--
-- Note: this might better be called Check_A_Reference to recognize the
-- variable case for SPARK, but we prefer to retain the historical name
-- since in practice this is mostly about checking calls for the possible
-- occurrence of an access-before-elaboration exception.
procedure Check_Bad_Instantiation (N : Node_Id);
-- N is a node for an instantiation (if called with any other node kind,
-- Check_Bad_Instantiation ignores the call). This subprogram checks for
-- the special case of a generic instantiation of a generic spec in the
-- same declarative part as the instantiation where a body is present and
-- has not yet been seen. This is an obvious error, but needs to be checked
-- specially at the time of the instantiation, since it is a case where we
-- cannot insert the body anywhere. If this case is detected, warnings are
-- generated, and a raise of Program_Error is inserted. In addition any
-- subprograms in the generic spec are stubbed, and the Bad_Instantiation
-- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
-- flag as an indication that no attempt should be made to insert an
-- instance body.
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- N is a function call or procedure statement call node and E is the
-- entity of the called function, which is within the current compilation
-- unit (where subunits count as part of the parent). This call checks if
-- this call, or any call within any accessed body could cause an ABE, and
-- if so, outputs a warning. Orig_Ent differs from E only in the case of
-- renamings, and points to the original name of the entity. This is used
-- for error messages. Outer_Scope is the outer level scope for the
-- original call.
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- The processing for Check_Internal_Call is divided up into two phases,
-- and this represents the second phase. The second phase is delayed if
-- Delaying_Elab_Checks is set to True. In this delayed case, the first
-- phase makes an entry in the Delay_Check table, which is processed when
-- Check_Elab_Calls is called. N, E and Orig_Ent are as for the call to
-- Check_Internal_Call. Outer_Scope is the outer level scope for the
-- original call.
function Get_Referenced_Ent (N : Node_Id) return Entity_Id;
-- N is either a function or procedure call or an access attribute that
-- references a subprogram. This call retrieves the relevant entity. If
-- this is a call to a protected subprogram, the entity is a selected
-- component. The callable entity may be absent, in which case Empty is
-- returned. This happens with non-analyzed calls in nested generics.
--
-- If SPARK_Mode is On, then N can also be a reference to an E_Variable
-- entity, in which case, the value returned is simply this entity.
function Has_Generic_Body (N : Node_Id) return Boolean;
-- N is a generic package instantiation node, and this routine determines
-- if this package spec does in fact have a generic body. If so, then
-- True is returned, otherwise False. Note that this is not at all the
-- same as checking if the unit requires a body, since it deals with
-- the case of optional bodies accurately (i.e. if a body is optional,
-- then it looks to see if a body is actually present). Note: this
-- function can only do a fully correct job if in generating code mode
-- where all bodies have to be present. If we are operating in semantics
-- check only mode, then in some cases of optional bodies, a result of
-- False may incorrectly be given. In practice this simply means that
-- some cases of warnings for incorrect order of elaboration will only
-- be given when generating code, which is not a big problem (and is
-- inevitable, given the optional body semantics of Ada).
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
-- Given code for an elaboration check (or unconditional raise if the check
-- is not needed), inserts the code in the appropriate place. N is the call
-- or instantiation node for which the check code is required. C is the
-- test whose failure triggers the raise.
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean;
-- Returns True if node N is a call to a generic formal subprogram
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean;
-- Determine whether entity Id denotes a [Deep_]Finalize procedure
procedure Output_Calls
(N : Node_Id;
Check_Elab_Flag : Boolean);
-- Outputs chain of calls stored in the Elab_Call table. The caller has
-- already generated the main warning message, so the warnings generated
-- are all continuation messages. The argument is the call node at which
-- the messages are to be placed. When Check_Elab_Flag is set, calls are
-- enumerated only when flag Elab_Warning is set for the dynamic case or
-- when flag Elab_Info_Messages is set for the static case.
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
-- Given two scopes, determine whether they are the same scope from an
-- elaboration point of view, i.e. packages and blocks are ignored.
procedure Set_C_Scope;
-- On entry C_Scope is set to some scope. On return, C_Scope is reset
-- to be the enclosing compilation unit of this scope.
procedure Set_Elaboration_Constraint
(Call : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id);
-- The current unit U may depend semantically on some unit P that is not
-- in the current context. If there is an elaboration call that reaches P,
-- we need to indicate that P requires an Elaborate_All, but this is not
-- effective in U's ali file, if there is no with_clause for P. In this
-- case we add the Elaborate_All on the unit Q that directly or indirectly
-- makes P available. This can happen in two cases:
--
-- a) Q declares a subtype of a type declared in P, and the call is an
-- initialization call for an object of that subtype.
--
-- b) Q declares an object of some tagged type whose root type is
-- declared in P, and the initialization call uses object notation on
-- that object to reach a primitive operation or a classwide operation
-- declared in P.
--
-- If P appears in the context of U, the current processing is correct.
-- Otherwise we must identify these two cases to retrieve Q and place the
-- Elaborate_All_Desirable on it.
function Spec_Entity (E : Entity_Id) return Entity_Id;
-- Given a compilation unit entity, if it is a spec entity, it is returned
-- unchanged. If it is a body entity, then the spec for the corresponding
-- spec is returned
function Within (E1, E2 : Entity_Id) return Boolean;
-- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
-- of its contained scopes, False otherwise.
function Within_Elaborate_All
(Unit : Unit_Number_Type;
E : Entity_Id) return Boolean;
-- Return True if we are within the scope of an Elaborate_All for E, or if
-- we are within the scope of an Elaborate_All for some other unit U, and U
-- with's E. This prevents spurious warnings when the called entity is
-- renamed within U, or in case of generic instances.
--------------------------------------
-- Activate_Elaborate_All_Desirable --
--------------------------------------
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id) is
UN : constant Unit_Number_Type := Get_Code_Unit (N);
CU : constant Node_Id := Cunit (UN);
UE : constant Entity_Id := Cunit_Entity (UN);
Unm : constant Unit_Name_Type := Unit_Name (UN);
CI : constant List_Id := Context_Items (CU);
Itm : Node_Id;
Ent : Entity_Id;
procedure Add_To_Context_And_Mark (Itm : Node_Id);
-- This procedure is called when the elaborate indication must be
-- applied to a unit not in the context of the referencing unit. The
-- unit gets added to the context as an implicit with.
function In_Withs_Of (UEs : Entity_Id) return Boolean;
-- UEs is the spec entity of a unit. If the unit to be marked is
-- in the context item list of this unit spec, then the call returns
-- True and Itm is left set to point to the relevant N_With_Clause node.
procedure Set_Elab_Flag (Itm : Node_Id);
-- Sets Elaborate_[All_]Desirable as appropriate on Itm
-----------------------------
-- Add_To_Context_And_Mark --
-----------------------------
procedure Add_To_Context_And_Mark (Itm : Node_Id) is
CW : constant Node_Id :=
Make_With_Clause (Sloc (Itm),
Name => Name (Itm));
begin
Set_Library_Unit (CW, Library_Unit (Itm));
Set_Implicit_With (CW);
-- Set elaborate all desirable on copy and then append the copy to
-- the list of body with's and we are done.
Set_Elab_Flag (CW);
Append_To (CI, CW);
end Add_To_Context_And_Mark;
-----------------
-- In_Withs_Of --
-----------------
function In_Withs_Of (UEs : Entity_Id) return Boolean is
UNs : constant Unit_Number_Type := Get_Source_Unit (UEs);
CUs : constant Node_Id := Cunit (UNs);
CIs : constant List_Id := Context_Items (CUs);
begin
Itm := First (CIs);
while Present (Itm) loop
if Nkind (Itm) = N_With_Clause then
Ent :=
Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
if U = Ent then
return True;
end if;
end if;
Next (Itm);
end loop;
return False;
end In_Withs_Of;
-------------------
-- Set_Elab_Flag --
-------------------
procedure Set_Elab_Flag (Itm : Node_Id) is
begin
if Nkind (N) in N_Subprogram_Instantiation then
Set_Elaborate_Desirable (Itm);
else
Set_Elaborate_All_Desirable (Itm);
end if;
end Set_Elab_Flag;
-- Start of processing for Activate_Elaborate_All_Desirable
begin
-- Do not set binder indication if expansion is disabled, as when
-- compiling a generic unit.
if not Expander_Active then
return;
end if;
-- If an instance of a generic package contains a controlled object (so
-- we're calling Initialize at elaboration time), and the instance is in
-- a package body P that says "with P;", then we need to return without
-- adding "pragma Elaborate_All (P);" to P.
if U = Main_Unit_Entity then
return;
end if;
Itm := First (CI);
while Present (Itm) loop
if Nkind (Itm) = N_With_Clause then
Ent := Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
-- If we find it, then mark elaborate all desirable and return
if U = Ent then
Set_Elab_Flag (Itm);
return;
end if;
end if;
Next (Itm);
end loop;
-- If we fall through then the with clause is not present in the
-- current unit. One legitimate possibility is that the with clause
-- is present in the spec when we are a body.
if Is_Body_Name (Unm)
and then In_Withs_Of (Spec_Entity (UE))
then
Add_To_Context_And_Mark (Itm);
return;
end if;
-- Similarly, we may be in the spec or body of a child unit, where
-- the unit in question is with'ed by some ancestor of the child unit.
if Is_Child_Name (Unm) then
declare
Pkg : Entity_Id;
begin
Pkg := UE;
loop
Pkg := Scope (Pkg);
exit when Pkg = Standard_Standard;
if In_Withs_Of (Pkg) then
Add_To_Context_And_Mark (Itm);
return;
end if;
end loop;
end;
end if;
-- Here if we do not find with clause on spec or body. We just ignore
-- this case; it means that the elaboration involves some other unit
-- than the unit being compiled, and will be caught elsewhere.
end Activate_Elaborate_All_Desirable;
------------------
-- Check_A_Call --
------------------
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True;
In_Init_Proc : Boolean := False)
is
Access_Case : constant Boolean := Nkind (N) = N_Attribute_Reference;
-- Indicates if we have Access attribute case
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean;
-- True if we're calling an instance of a generic subprogram, or a
-- subprogram in an instance of a generic package, and the call is
-- outside that instance.
procedure Elab_Warning
(Msg_D : String;
Msg_S : String;
Ent : Node_Or_Entity_Id);
-- Generate a call to Error_Msg_NE with parameters Msg_D or Msg_S (for
-- dynamic or static elaboration model), N and Ent. Msg_D is a real
-- warning (output if Msg_D is non-null and Elab_Warnings is set),
-- Msg_S is an info message (output if Elab_Info_Messages is set).
function Find_W_Scope return Entity_Id;
-- Find top-level scope for called entity (not following renamings
-- or derivations). This is where the Elaborate_All will go if it is
-- needed. We start with the called entity, except in the case of an
-- initialization procedure outside the current package, where the init
-- proc is in the root package, and we start from the entity of the name
-- in the call.
-----------------------------------
-- Call_To_Instance_From_Outside --
-----------------------------------
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean is
Scop : Entity_Id := Id;
begin
loop
if Scop = Standard_Standard then
return False;
end if;
if Is_Generic_Instance (Scop) then
return not In_Open_Scopes (Scop);
end if;
Scop := Scope (Scop);
end loop;
end Call_To_Instance_From_Outside;
------------------
-- Elab_Warning --
------------------
procedure Elab_Warning
(Msg_D : String;
Msg_S : String;
Ent : Node_Or_Entity_Id)
is
begin
-- Dynamic elaboration checks, real warning
if Dynamic_Elaboration_Checks then
if not Access_Case then
if Msg_D /= "" and then Elab_Warnings then
Error_Msg_NE (Msg_D, N, Ent);
end if;
-- In the access case emit first warning message as well,
-- otherwise list of calls will appear as errors.
elsif Elab_Warnings then
Error_Msg_NE (Msg_S, N, Ent);
end if;
-- Static elaboration checks, info message
else
if Elab_Info_Messages then
Error_Msg_NE (Msg_S, N, Ent);
end if;
end if;
end Elab_Warning;
------------------
-- Find_W_Scope --
------------------
function Find_W_Scope return Entity_Id is
Refed_Ent : constant Entity_Id := Get_Referenced_Ent (N);
W_Scope : Entity_Id;
begin
if Is_Init_Proc (Refed_Ent)
and then not In_Same_Extended_Unit (N, Refed_Ent)
then
W_Scope := Scope (Refed_Ent);
else
W_Scope := E;
end if;
-- Now loop through scopes to get to the enclosing compilation unit
while not Is_Compilation_Unit (W_Scope) loop
W_Scope := Scope (W_Scope);
end loop;
return W_Scope;
end Find_W_Scope;
-- Local variables
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
-- Indicates if we have instantiation case
Loc : constant Source_Ptr := Sloc (N);
Variable_Case : constant Boolean :=
Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable;
-- Indicates if we have variable reference case
W_Scope : constant Entity_Id := Find_W_Scope;
-- Top-level scope of directly called entity for subprogram. This
-- differs from E_Scope in the case where renamings or derivations
-- are involved, since it does not follow these links. W_Scope is
-- generally in a visible unit, and it is this scope that may require
-- an Elaborate_All. However, there are some cases (initialization
-- calls and calls involving object notation) where W_Scope might not
-- be in the context of the current unit, and there is an intermediate
-- package that is, in which case the Elaborate_All has to be placed
-- on this intermediate package. These special cases are handled in
-- Set_Elaboration_Constraint.
Ent : Entity_Id;
Callee_Unit_Internal : Boolean;
Caller_Unit_Internal : Boolean;
Decl : Node_Id;
Inst_Callee : Source_Ptr;
Inst_Caller : Source_Ptr;
Unit_Callee : Unit_Number_Type;
Unit_Caller : Unit_Number_Type;
Body_Acts_As_Spec : Boolean;
-- Set to true if call is to body acting as spec (no separate spec)
Cunit_SC : Boolean := False;
-- Set to suppress dynamic elaboration checks where one of the
-- enclosing scopes has Elaboration_Checks_Suppressed set, or else
-- if a pragma Elaborate[_All] applies to that scope, in which case
-- warnings on the scope are also suppressed. For the internal case,
-- we ignore this flag.
E_Scope : Entity_Id;
-- Top-level scope of entity for called subprogram. This value includes
-- following renamings and derivations, so this scope can be in a
-- non-visible unit. This is the scope that is to be investigated to
-- see whether an elaboration check is required.
Is_DIC : Boolean;
-- Flag set when the subprogram being invoked is the procedure generated
-- for pragma Default_Initial_Condition.
SPARK_Elab_Errors : Boolean;
-- Flag set when an entity is called or a variable is read during SPARK
-- dynamic elaboration.
-- Start of processing for Check_A_Call
begin
-- If the call is known to be within a local Suppress Elaboration
-- pragma, nothing to check. This can happen in task bodies. But
-- we ignore this for a call to a generic formal.
if Nkind (N) in N_Subprogram_Call
and then No_Elaboration_Check (N)
and then not Is_Call_Of_Generic_Formal (N)
then
return;
-- If this is a rewrite of a Valid_Scalars attribute, then nothing to
-- check, we don't mind in this case if the call occurs before the body
-- since this is all generated code.
elsif Nkind (Original_Node (N)) = N_Attribute_Reference
and then Attribute_Name (Original_Node (N)) = Name_Valid_Scalars
then
return;
-- Intrinsics such as instances of Unchecked_Deallocation do not have
-- any body, so elaboration checking is not needed, and would be wrong.
elsif Is_Intrinsic_Subprogram (E) then
return;
-- Do not consider references to internal variables for SPARK semantics
elsif Variable_Case and then not Comes_From_Source (E) then
return;
end if;
-- Proceed with check
Ent := E;
-- For a variable reference, just set Body_Acts_As_Spec to False
if Variable_Case then
Body_Acts_As_Spec := False;
-- Additional checks for all other cases
else
-- Go to parent for derived subprogram, or to original subprogram in
-- the case of a renaming (Alias covers both these cases).
loop
if (Suppress_Elaboration_Warnings (Ent)
or else Elaboration_Checks_Suppressed (Ent))
and then (Inst_Case or else No (Alias (Ent)))
then
return;
end if;
-- Nothing to do for imported entities
if Is_Imported (Ent) then
return;
end if;
exit when Inst_Case or else No (Alias (Ent));
Ent := Alias (Ent);
end loop;
Decl := Unit_Declaration_Node (Ent);
if Nkind (Decl) = N_Subprogram_Body then
Body_Acts_As_Spec := True;
elsif Nkind (Decl) in
N_Subprogram_Declaration | N_Subprogram_Body_Stub
or else Inst_Case
then
Body_Acts_As_Spec := False;
-- If we have none of an instantiation, subprogram body or subprogram
-- declaration, or in the SPARK case, a variable reference, then
-- it is not a case that we want to check. (One case is a call to a
-- generic formal subprogram, where we do not want the check in the
-- template).
else
return;
end if;
end if;
E_Scope := Ent;
loop
if Elaboration_Checks_Suppressed (E_Scope)
or else Suppress_Elaboration_Warnings (E_Scope)
then
Cunit_SC := True;
end if;
-- Exit when we get to compilation unit, not counting subunits
exit when Is_Compilation_Unit (E_Scope)
and then (Is_Child_Unit (E_Scope)
or else Scope (E_Scope) = Standard_Standard);
pragma Assert (E_Scope /= Standard_Standard);
-- Move up a scope looking for compilation unit
E_Scope := Scope (E_Scope);
end loop;
-- No checks needed for pure or preelaborated compilation units
if Is_Pure (E_Scope) or else Is_Preelaborated (E_Scope) then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately, or else we know that the
-- body we need appears as needed at the point of the instantiation.
-- However, this assumption is only valid if we are in static mode.
if not Dynamic_Elaboration_Checks
and then
Instantiation_Depth (Sloc (Ent)) > Instantiation_Depth (Sloc (N))
then
return;
end if;
-- Do not give a warning for a package with no body
if Ekind (Ent) = E_Generic_Package and then not Has_Generic_Body (N) then
return;
end if;
-- Case of entity is in same unit as call or instantiation. In the
-- instantiation case, W_Scope may be different from E_Scope; we want
-- the unit in which the instantiation occurs, since we're analyzing
-- based on the expansion.
if W_Scope = C_Scope then
if not Inter_Unit_Only then
Check_Internal_Call (N, Ent, Outer_Scope, E);
end if;
return;
end if;
-- Case of entity is not in current unit (i.e. with'ed unit case)
-- We are only interested in such calls if the outer call was from
-- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
return;
end if;
-- Nothing to do if some scope said that no checks were required
if Cunit_SC then
return;
end if;
-- Nothing to do for a generic instance, because a call to an instance
-- cannot fail the elaboration check, because the body of the instance
-- is always elaborated immediately after the spec.
if Call_To_Instance_From_Outside (Ent) then
return;
end if;
-- Nothing to do if subprogram with no separate spec. However, a call
-- to Deep_Initialize may result in a call to a user-defined Initialize
-- procedure, which imposes a body dependency. This happens only if the
-- type is controlled and the Initialize procedure is not inherited.
if Body_Acts_As_Spec then
if Is_TSS (Ent, TSS_Deep_Initialize) then
declare
Typ : constant Entity_Id := Etype (First_Formal (Ent));
Init : Entity_Id;
begin
if not Is_Controlled (Typ) then
return;
else
Init := Find_Prim_Op (Typ, Name_Initialize);
if Comes_From_Source (Init) then
Ent := Init;
else
return;
end if;
end if;
end;
else
return;
end if;
end if;
-- Check cases of internal units
Callee_Unit_Internal := In_Internal_Unit (E_Scope);
-- Do not give a warning if the with'ed unit is internal and this is
-- the generic instantiation case (this saves a lot of hassle dealing
-- with the Text_IO special child units)
if Callee_Unit_Internal and Inst_Case then
return;
end if;
if C_Scope = Standard_Standard then
Caller_Unit_Internal := False;
else
Caller_Unit_Internal := In_Internal_Unit (C_Scope);
end if;
-- Do not give a warning if the with'ed unit is internal and the caller
-- is not internal (since the binder always elaborates internal units
-- first).
if Callee_Unit_Internal and not Caller_Unit_Internal then
return;
end if;
-- For now, if debug flag -gnatdE is not set, do no checking for one
-- internal unit withing another. This fixes the problem with the sgi
-- build and storage errors. To be resolved later ???
if (Callee_Unit_Internal and Caller_Unit_Internal)
and not Debug_Flag_EE
then
return;
end if;
if Is_TSS (E, TSS_Deep_Initialize) then
Ent := E;
end if;
-- If the call is in an instance, and the called entity is not
-- defined in the same instance, then the elaboration issue focuses
-- around the unit containing the template, it is this unit that
-- requires an Elaborate_All.
-- However, if we are doing dynamic elaboration, we need to chase the
-- call in the usual manner.
-- We also need to chase the call in the usual manner if it is a call
-- to a generic formal parameter, since that case was not handled as
-- part of the processing of the template.
Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
if Inst_Caller = No_Location then
Unit_Caller := No_Unit;
else
Unit_Caller := Get_Source_Unit (N);
end if;
if Inst_Callee = No_Location then
Unit_Callee := No_Unit;
else
Unit_Callee := Get_Source_Unit (Ent);
end if;
if Unit_Caller /= No_Unit
and then Unit_Callee /= Unit_Caller
and then not Dynamic_Elaboration_Checks
and then not Is_Call_Of_Generic_Formal (N)
then
E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
-- If we don't get a spec entity, just ignore call. Not quite
-- clear why this check is necessary. ???
if No (E_Scope) then
return;
end if;
-- Otherwise step to enclosing compilation unit
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- For the case where N is not an instance, and is not a call within
-- instance to other than a generic formal, we recompute E_Scope
-- for the error message, since we do NOT want to go to the unit
-- that has the ultimate declaration in the case of renaming and
-- derivation and we also want to go to the generic unit in the
-- case of an instance, and no further.
else
-- Loop to carefully follow renamings and derivations one step
-- outside the current unit, but not further.
if not (Inst_Case or Variable_Case)
and then Present (Alias (Ent))
then
E_Scope := Alias (Ent);
else
E_Scope := Ent;
end if;
loop
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- If E_Scope is the same as C_Scope, it means that there
-- definitely was a local renaming or derivation, and we
-- are not yet out of the current unit.
exit when E_Scope /= C_Scope;
Ent := Alias (Ent);
E_Scope := Ent;
-- If no alias, there could be a previous error, but not if we've
-- already reached the outermost level (Standard).
if No (Ent) then
return;
end if;
end loop;
end if;
if Within_Elaborate_All (Current_Sem_Unit, E_Scope) then
return;
end if;
-- Determine whether the Default_Initial_Condition procedure of some
-- type is being invoked.
Is_DIC := Ekind (Ent) = E_Procedure and then Is_DIC_Procedure (Ent);
-- Checks related to Default_Initial_Condition fall under the SPARK
-- umbrella because this is a SPARK-specific annotation.
SPARK_Elab_Errors :=
SPARK_Mode = On and (Is_DIC or Dynamic_Elaboration_Checks);
-- Now check if an Elaborate_All (or dynamic check) is needed
if (Elab_Info_Messages or Elab_Warnings or SPARK_Elab_Errors)
and then Generate_Warnings
and then not Suppress_Elaboration_Warnings (Ent)
and then not Elaboration_Checks_Suppressed (Ent)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then not Elaboration_Checks_Suppressed (E_Scope)
then
-- Instantiation case
if Inst_Case then
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then
Error_Msg_NE
("instantiation of & during elaboration in SPARK", N, Ent);
else
Elab_Warning
("instantiation of & may raise Program_Error?l?",
"info: instantiation of & during elaboration?$?", Ent);
end if;
-- Indirect call case, info message only in static elaboration
-- case, because the attribute reference itself cannot raise an
-- exception. Note that SPARK does not permit indirect calls.
elsif Access_Case then
Elab_Warning ("", "info: access to & during elaboration?$?", Ent);
-- Variable reference in SPARK mode
elsif Variable_Case then
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then
Error_Msg_NE
("reference to & during elaboration in SPARK", N, Ent);
end if;
-- Subprogram call case
else
if Nkind (Name (N)) in N_Has_Entity
and then Is_Init_Proc (Entity (Name (N)))
and then Comes_From_Source (Ent)
then
Elab_Warning
("implicit call to & may raise Program_Error?l?",
"info: implicit call to & during elaboration?$?",
Ent);
elsif SPARK_Elab_Errors then
-- Emit a specialized error message when the elaboration of an
-- object of a private type evaluates the expression of pragma
-- Default_Initial_Condition. This prevents the internal name
-- of the procedure from appearing in the error message.
if Is_DIC then
Error_Msg_N
("call to Default_Initial_Condition during elaboration in "
& "SPARK", N);
else
Error_Msg_NE
("call to & during elaboration in SPARK", N, Ent);
end if;
else
Elab_Warning
("call to & may raise Program_Error?l?",
"info: call to & during elaboration?$?",
Ent);
end if;
end if;
Error_Msg_Qual_Level := Nat'Last;
-- Case of Elaborate_All not present and required, for SPARK this
-- is an error, so give an error message.
if SPARK_Elab_Errors then
Error_Msg_NE -- CODEFIX
("\Elaborate_All pragma required for&", N, W_Scope);
-- Otherwise we generate an implicit pragma. For a subprogram
-- instantiation, Elaborate is good enough, since no transitive
-- call is possible at elaboration time in this case.
elsif Nkind (N) in N_Subprogram_Instantiation then
Elab_Warning
("\missing pragma Elaborate for&?l?",
"\implicit pragma Elaborate for& generated?$?",
W_Scope);
-- For all other cases, we need an implicit Elaborate_All
else
Elab_Warning
("\missing pragma Elaborate_All for&?l?",
"\implicit pragma Elaborate_All for & generated?$?",
W_Scope);
end if;
Error_Msg_Qual_Level := 0;
-- Take into account the flags related to elaboration warning
-- messages when enumerating the various calls involved. This
-- ensures the proper pairing of the main warning and the
-- clarification messages generated by Output_Calls.
Output_Calls (N, Check_Elab_Flag => True);
-- Set flag to prevent further warnings for same unit unless in
-- All_Errors_Mode.
if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
Set_Suppress_Elaboration_Warnings (W_Scope);
end if;
end if;
-- Check for runtime elaboration check required
if Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Elaboration_Checks_Suppressed (W_Scope)
and then not Elaboration_Checks_Suppressed (E_Scope)
and then not Cunit_SC
then
-- Runtime elaboration check required. Generate check of the
-- elaboration Boolean for the unit containing the entity.
-- Note that for this case, we do check the real unit (the one
-- from following renamings, since that is the issue).
-- Could this possibly miss a useless but required PE???
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix =>
New_Occurrence_Of (Spec_Entity (E_Scope), Loc)));
-- Prevent duplicate elaboration checks on the same call, which
-- can happen if the body enclosing the call appears itself in a
-- call whose elaboration check is delayed.
if Nkind (N) in N_Subprogram_Call then
Set_No_Elaboration_Check (N);
end if;
end if;
-- Case of static elaboration model
else
-- Do not do anything if elaboration checks suppressed. Note that
-- we check Ent here, not E, since we want the real entity for the
-- body to see if checks are suppressed for it, not the dummy
-- entry for renamings or derivations.
if Elaboration_Checks_Suppressed (Ent)
or else Elaboration_Checks_Suppressed (E_Scope)
or else Elaboration_Checks_Suppressed (W_Scope)
then
null;
-- Do not generate an Elaborate_All for finalization routines
-- that perform partial clean up as part of initialization.
elsif In_Init_Proc and then Is_Finalization_Procedure (Ent) then
null;
-- Here we need to generate an implicit elaborate all
else
-- Generate Elaborate_All warning unless suppressed
if (Elab_Info_Messages and Generate_Warnings and not Inst_Case)
and then not Suppress_Elaboration_Warnings (Ent)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then not Suppress_Elaboration_Warnings (W_Scope)
then
Error_Msg_Node_2 := W_Scope;
Error_Msg_NE
("info: call to& in elaboration code requires pragma "
& "Elaborate_All on&?$?", N, E);
end if;
-- Set indication for binder to generate Elaborate_All
Set_Elaboration_Constraint (N, E, W_Scope);
end if;
end if;
end Check_A_Call;
-----------------------------
-- Check_Bad_Instantiation --
-----------------------------
procedure Check_Bad_Instantiation (N : Node_Id) is
Ent : Entity_Id;
begin
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
-- Nothing to do if serious errors detected (avoid cascaded errors)
elsif Serious_Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic then
return;
-- Nothing to do if a library level instantiation
elsif Nkind (Parent (N)) = N_Compilation_Unit then
return;
-- Nothing to do if we are compiling a proper body for semantic
-- purposes only. The generic body may be in another proper body.
elsif
Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
then
return;
end if;
Ent := Get_Generic_Entity (N);
-- The case we are interested in is when the generic spec is in the
-- current declarative part
if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
or else not In_Same_Extended_Unit (N, Ent)
then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately. Otherwise, we know that
-- the body we need appears as needed at the point of the instantiation.
-- If they are both at the same level but not within the same instance
-- then the body of the generic will be in the earlier instance.
declare
D1 : constant Nat := Instantiation_Depth (Sloc (Ent));
D2 : constant Nat := Instantiation_Depth (Sloc (N));
begin
if D1 > D2 then
return;
elsif D1 = D2
and then Is_Generic_Instance (Scope (Ent))
and then not In_Open_Scopes (Scope (Ent))
then
return;
end if;
end;
-- Now we can proceed, if the entity being called has a completion,
-- then we are definitely OK, since we have already seen the body.
if Has_Completion (Ent) then
return;
end if;
-- If there is no body, then nothing to do
if not Has_Generic_Body (N) then
return;
end if;
-- Here we definitely have a bad instantiation
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_NE ("cannot instantiate& before body seen<<", N, Ent);
Error_Msg_N ("\Program_Error [<<", N);
Insert_Elab_Check (N);
Set_Is_Known_Guaranteed_ABE (N);
end Check_Bad_Instantiation;
---------------------
-- Check_Elab_Call --
---------------------
procedure Check_Elab_Call
(N : Node_Id;
Outer_Scope : Entity_Id := Empty;
In_Init_Proc : Boolean := False)
is
Ent : Entity_Id;
P : Node_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- If the reference is not in the main unit, there is nothing to check.
-- Elaboration call from units in the context of the main unit will lead
-- to semantic dependencies when those units are compiled.
if not In_Extended_Main_Code_Unit (N) then
return;
end if;
-- For an entry call, check relevant restriction
if Nkind (N) = N_Entry_Call_Statement
and then not In_Subprogram_Or_Concurrent_Unit
then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
-- Nothing to do if this is not an expected type of reference (happens
-- in some error conditions, and in some cases where rewriting occurs).
elsif Nkind (N) not in N_Subprogram_Call
and then Nkind (N) /= N_Attribute_Reference
and then (SPARK_Mode /= On
or else Nkind (N) not in N_Has_Entity
or else No (Entity (N))
or else Ekind (Entity (N)) /= E_Variable)
then
return;
-- Nothing to do if this is a call already rewritten for elab checking.
-- Such calls appear as the targets of If_Expressions.
-- This check MUST be wrong, it catches far too much
elsif Nkind (Parent (N)) = N_If_Expression then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic
and then No (Enclosing_Generic_Body (N))
then
return;
-- Nothing to do if call is being preanalyzed, as when within a
-- pre/postcondition, a predicate, or an invariant.
elsif In_Spec_Expression then
return;
end if;
-- Nothing to do if this is a call to a postcondition, which is always
-- within a subprogram body, even though the current scope may be the
-- enclosing scope of the subprogram.
if Nkind (N) = N_Procedure_Call_Statement
and then Is_Entity_Name (Name (N))
and then Chars (Entity (Name (N))) = Name_uWrapped_Statements
then
return;
end if;
-- Here we have a reference at elaboration time that must be checked
if Debug_Flag_Underscore_LL then
Write_Str (" Check_Elab_Ref: ");
if Nkind (N) = N_Attribute_Reference then
if not Is_Entity_Name (Prefix (N)) then
Write_Str ("<<not entity name>>");
else
Write_Name (Chars (Entity (Prefix (N))));
end if;
Write_Str ("'Access");
elsif No (Name (N)) or else not Is_Entity_Name (Name (N)) then
Write_Str ("<<not entity name>> ");
else
Write_Name (Chars (Entity (Name (N))));
end if;
Write_Str (" reference at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Climb up the tree to make sure we are not inside default expression
-- of a parameter specification or a record component, since in both
-- these cases, we will be doing the actual reference later, not now,
-- and it is at the time of the actual reference (statically speaking)
-- that we must do our static check, not at the time of its initial
-- analysis).
-- However, we have to check references within component definitions
-- (e.g. a function call that determines an array component bound),
-- so we terminate the loop in that case.
P := Parent (N);
while Present (P) loop
if Nkind (P) in N_Parameter_Specification | N_Component_Declaration
then
return;
-- The reference occurs within the constraint of a component,
-- so it must be checked.
elsif Nkind (P) = N_Component_Definition then
exit;
else
P := Parent (P);
end if;
end loop;
-- Stuff that happens only at the outer level
if No (Outer_Scope) then
Elab_Visited.Set_Last (0);
-- Nothing to do if current scope is Standard (this is a bit odd, but
-- it happens in the case of generic instantiations).
C_Scope := Current_Scope;
if C_Scope = Standard_Standard then
return;
end if;
-- First case, we are in elaboration code
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
if From_Elab_Code then
-- Complain if ref that comes from source in preelaborated unit
-- and we are not inside a subprogram (i.e. we are in elab code).
-- Ada 2022 (AI12-0175): Calls to certain functions that are
-- essentially unchecked conversions are preelaborable.
if Comes_From_Source (N)
and then In_Preelaborated_Unit
and then not In_Inlined_Body
and then Nkind (N) /= N_Attribute_Reference
and then not (Ada_Version >= Ada_2022
and then Is_Preelaborable_Construct (N))
then
Error_Preelaborated_Call (N);
return;
end if;
-- Second case, we are inside a subprogram or concurrent unit, which
-- means we are not in elaboration code.
else
-- In this case, the issue is whether we are inside the
-- declarative part of the unit in which we live, or inside its
-- statements. In the latter case, there is no issue of ABE calls
-- at this level (a call from outside to the unit in which we live
-- might cause an ABE, but that will be detected when we analyze
-- that outer level call, as it recurses into the called unit).
-- Climb up the tree, doing this test, and also testing for being
-- inside a default expression, which, as discussed above, is not
-- checked at this stage.
declare
P : Node_Id;
L : List_Id;
begin
P := N;
loop
-- If we find a parentless subtree, it seems safe to assume
-- that we are not in a declarative part and that no
-- checking is required.
if No (P) then
return;
end if;
if Is_List_Member (P) then
L := List_Containing (P);
P := Parent (L);
else
L := No_List;
P := Parent (P);
end if;
exit when Nkind (P) = N_Subunit;
-- Filter out case of default expressions, where we do not
-- do the check at this stage.
if Nkind (P) in
N_Parameter_Specification | N_Component_Declaration
then
return;
end if;
-- A protected body has no elaboration code and contains
-- only other bodies.
if Nkind (P) = N_Protected_Body then
return;
elsif Nkind (P) in N_Subprogram_Body
| N_Task_Body
| N_Block_Statement
| N_Entry_Body
then
if L = Declarations (P) then
exit;
-- We are not in elaboration code, but we are doing
-- dynamic elaboration checks, in this case, we still
-- need to do the reference, since the subprogram we are
-- in could be called from another unit, also in dynamic
-- elaboration check mode, at elaboration time.
elsif Dynamic_Elaboration_Checks then
-- We provide a debug flag to disable this check. That
-- way we have an easy work around for regressions
-- that are caused by this new check. This debug flag
-- can be removed later.
if Debug_Flag_DD then
return;
end if;
-- Do the check in this case
exit;
elsif Nkind (P) = N_Task_Body then
-- The check is deferred until Check_Task_Activation
-- but we need to capture local suppress pragmas
-- that may inhibit checks on this call.
Ent := Get_Referenced_Ent (N);
if No (Ent) then
return;
elsif Elaboration_Checks_Suppressed (Current_Scope)
or else Elaboration_Checks_Suppressed (Ent)
or else Elaboration_Checks_Suppressed (Scope (Ent))
then
if Nkind (N) in N_Subprogram_Call then
Set_No_Elaboration_Check (N);
end if;
end if;
return;
-- Static model, call is not in elaboration code, we
-- never need to worry, because in the static model the
-- top-level caller always takes care of things.
else
return;
end if;
end if;
end loop;
end;
end if;
end if;
Ent := Get_Referenced_Ent (N);
if No (Ent) then
return;
end if;
-- Determine whether a prior call to the same subprogram was already
-- examined within the same context. If this is the case, then there is
-- no need to proceed with the various warnings and checks because the
-- work was already done for the previous call.
declare
Self : constant Visited_Element :=
(Subp_Id => Ent, Context => Parent (N));
begin
for Index in 1 .. Elab_Visited.Last loop
if Self = Elab_Visited.Table (Index) then
return;
end if;
end loop;
end;
-- See if we need to analyze this reference. We analyze it if either of
-- the following conditions is met:
-- It is an inner level call (since in this case it was triggered
-- by an outer level call from elaboration code), but only if the
-- call is within the scope of the original outer level call.
-- It is an outer level reference from elaboration code, or a call to
-- an entity is in the same elaboration scope.
-- And in these cases, we will check both inter-unit calls and
-- intra-unit (within a single unit) calls.
C_Scope := Current_Scope;
-- If not outer level reference, then we follow it if it is within the
-- original scope of the outer reference.
if Present (Outer_Scope)
and then Within (Scope (Ent), Outer_Scope)
then
Set_C_Scope;
Check_A_Call
(N => N,
E => Ent,
Outer_Scope => Outer_Scope,
Inter_Unit_Only => False,
In_Init_Proc => In_Init_Proc);
-- Nothing to do if elaboration checks suppressed for this scope.
-- However, an interesting exception, the fact that elaboration checks
-- are suppressed within an instance (because we can trace the body when
-- we process the template) does not extend to calls to generic formal
-- subprograms.
elsif Elaboration_Checks_Suppressed (Current_Scope)
and then not Is_Call_Of_Generic_Formal (N)
then
null;
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode
-- is set, then we will do the check, but only in the inter-unit case
-- (this is to accommodate unguarded elaboration calls from other units
-- in which this same mode is set). We don't want warnings in this case,
-- it would generate warnings having nothing to do with elaboration.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
-- Otherwise nothing to do
else
return;
end if;
-- A call to an Init_Proc in elaboration code may bring additional
-- dependencies, if some of the record components thereof have
-- initializations that are function calls that come from source. We
-- treat the current node as a call to each of these functions, to check
-- their elaboration impact.
if Is_Init_Proc (Ent) and then From_Elab_Code then
Process_Init_Proc : declare
Unit_Decl : constant Node_Id := Unit_Declaration_Node (Ent);
function Check_Init_Call (Nod : Node_Id) return Traverse_Result;
-- Find subprogram calls within body of Init_Proc for Traverse
-- instantiation below.
procedure Traverse_Body is new Traverse_Proc (Check_Init_Call);
-- Traversal procedure to find all calls with body of Init_Proc
---------------------
-- Check_Init_Call --
---------------------
function Check_Init_Call (Nod : Node_Id) return Traverse_Result is
Func : Entity_Id;
begin
if Nkind (Nod) in N_Subprogram_Call
and then Is_Entity_Name (Name (Nod))
then
Func := Entity (Name (Nod));
if Comes_From_Source (Func) then
Check_A_Call
(N, Func, Standard_Standard, Inter_Unit_Only => True);
end if;
return OK;
else
return OK;
end if;
end Check_Init_Call;
-- Start of processing for Process_Init_Proc
begin
if Nkind (Unit_Decl) = N_Subprogram_Body then
Traverse_Body (Handled_Statement_Sequence (Unit_Decl));
end if;
end Process_Init_Proc;
end if;
end Check_Elab_Call;
-----------------------
-- Check_Elab_Assign --
-----------------------
procedure Check_Elab_Assign (N : Node_Id) is
Ent : Entity_Id;
Scop : Entity_Id;
Pkg_Spec : Entity_Id;
Pkg_Body : Entity_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- For record or array component, check prefix. If it is an access type,
-- then there is nothing to do (we do not know what is being assigned),
-- but otherwise this is an assignment to the prefix.
if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then
if not Is_Access_Type (Etype (Prefix (N))) then
Check_Elab_Assign (Prefix (N));
end if;
return;
end if;
-- For type conversion, check expression
if Nkind (N) = N_Type_Conversion then
Check_Elab_Assign (Expression (N));
return;
end if;
-- Nothing to do if this is not an entity reference otherwise get entity
if Is_Entity_Name (N) then
Ent := Entity (N);
else
return;
end if;
-- What we are looking for is a reference in the body of a package that
-- modifies a variable declared in the visible part of the package spec.
if Present (Ent)
and then Comes_From_Source (N)
and then not Suppress_Elaboration_Warnings (Ent)
and then Ekind (Ent) = E_Variable
and then not In_Private_Part (Ent)
and then Is_Library_Level_Entity (Ent)
then
Scop := Current_Scope;
loop
if No (Scop) or else Scop = Standard_Standard then
return;
elsif Ekind (Scop) = E_Package
and then Is_Compilation_Unit (Scop)
then
exit;
else
Scop := Scope (Scop);
end if;
end loop;
-- Here Scop points to the containing library package
Pkg_Spec := Scop;
Pkg_Body := Body_Entity (Pkg_Spec);
-- All OK if the package has an Elaborate_Body pragma
if Has_Pragma_Elaborate_Body (Scop) then
return;
end if;
-- OK if entity being modified is not in containing package spec
if not In_Same_Source_Unit (Scop, Ent) then
return;
end if;
-- All OK if entity appears in generic package or generic instance.
-- We just get too messed up trying to give proper warnings in the
-- presence of generics. Better no message than a junk one.
Scop := Scope (Ent);
while Present (Scop) and then Scop /= Pkg_Spec loop
if Ekind (Scop) = E_Generic_Package then
return;
elsif Ekind (Scop) = E_Package
and then Is_Generic_Instance (Scop)
then
return;
end if;
Scop := Scope (Scop);
end loop;
-- All OK if in task, don't issue warnings there
if In_Task_Activation then
return;
end if;
-- OK if no package body
if No (Pkg_Body) then
return;
end if;
-- OK if reference is not in package body
if not In_Same_Source_Unit (Pkg_Body, N) then
return;
end if;
-- OK if package body has no handled statement sequence
declare
HSS : constant Node_Id :=
Handled_Statement_Sequence (Declaration_Node (Pkg_Body));
begin
if No (HSS) or else not Comes_From_Source (HSS) then
return;
end if;
end;
-- We definitely have a case of a modification of an entity in
-- the package spec from the elaboration code of the package body.
-- We may not give the warning (because there are some additional
-- checks to avoid too many false positives), but it would be a good
-- idea for the binder to try to keep the body elaboration close to
-- the spec elaboration.
Set_Elaborate_Body_Desirable (Pkg_Spec);
-- All OK in gnat mode (we know what we are doing)
if GNAT_Mode then
return;
end if;
-- All OK if all warnings suppressed
if Warning_Mode = Suppress then
return;
end if;
-- All OK if elaboration checks suppressed for entity
if Checks_May_Be_Suppressed (Ent)
and then Is_Check_Suppressed (Ent, Elaboration_Check)
then
return;
end if;
-- OK if the entity is initialized. Note that the No_Initialization
-- flag usually means that the initialization has been rewritten into
-- assignments, but that still counts for us.
declare
Decl : constant Node_Id := Declaration_Node (Ent);
begin
if Nkind (Decl) = N_Object_Declaration
and then (Present (Expression (Decl))
or else No_Initialization (Decl))
then
return;
end if;
end;
-- Here is where we give the warning
-- All OK if warnings suppressed on the entity
if not Has_Warnings_Off (Ent) then
Error_Msg_Sloc := Sloc (Ent);
Error_Msg_NE
("??& can be accessed by clients before this initialization",
N, Ent);
Error_Msg_NE
("\??add Elaborate_Body to spec to ensure & is initialized",
N, Ent);
end if;
if not All_Errors_Mode then
Set_Suppress_Elaboration_Warnings (Ent);
end if;
end if;
end Check_Elab_Assign;
----------------------
-- Check_Elab_Calls --
----------------------
-- WARNING: This routine manages SPARK regions
procedure Check_Elab_Calls is
Saved_SM : SPARK_Mode_Type;
Saved_SMP : Node_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- If expansion is disabled, do not generate any checks, unless we
-- are in GNATprove mode, so that errors are issued in GNATprove for
-- violations of static elaboration rules in SPARK code. Also skip
-- checks if any subunits are missing because in either case we lack the
-- full information that we need, and no object file will be created in
-- any case.
if (not Expander_Active and not GNATprove_Mode)
or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
or else Subunits_Missing
then
return;
end if;
-- Skip delayed calls if we had any errors
if Serious_Errors_Detected = 0 then
Delaying_Elab_Checks := False;
Expander_Mode_Save_And_Set (True);
for J in Delay_Check.First .. Delay_Check.Last loop
Push_Scope (Delay_Check.Table (J).Curscop);
From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
In_Task_Activation := Delay_Check.Table (J).In_Task_Activation;
Saved_SM := SPARK_Mode;
Saved_SMP := SPARK_Mode_Pragma;
-- Set appropriate value of SPARK_Mode
if Delay_Check.Table (J).From_SPARK_Code then
SPARK_Mode := On;
end if;
Check_Internal_Call_Continue
(N => Delay_Check.Table (J).N,
E => Delay_Check.Table (J).E,
Outer_Scope => Delay_Check.Table (J).Outer_Scope,
Orig_Ent => Delay_Check.Table (J).Orig_Ent);
Restore_SPARK_Mode (Saved_SM, Saved_SMP);
Pop_Scope;
end loop;
-- Set Delaying_Elab_Checks back on for next main compilation
Expander_Mode_Restore;
Delaying_Elab_Checks := True;
end if;
end Check_Elab_Calls;
------------------------------
-- Check_Elab_Instantiation --
------------------------------
procedure Check_Elab_Instantiation
(N : Node_Id;
Outer_Scope : Entity_Id := Empty)
is
Ent : Entity_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- Check for and deal with bad instantiation case. There is some
-- duplicated code here, but we will worry about this later ???
Check_Bad_Instantiation (N);
if Is_Known_Guaranteed_ABE (N) then
return;
end if;
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
end if;
-- Nothing to do if inside a generic template
if Inside_A_Generic then
return;
end if;
-- Nothing to do if the instantiation is not in the main unit
if not In_Extended_Main_Code_Unit (N) then
return;
end if;
Ent := Get_Generic_Entity (N);
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
-- See if we need to analyze this instantiation. We analyze it if
-- either of the following conditions is met:
-- It is an inner level instantiation (since in this case it was
-- triggered by an outer level call from elaboration code), but
-- only if the instantiation is within the scope of the original
-- outer level call.
-- It is an outer level instantiation from elaboration code, or the
-- instantiated entity is in the same elaboration scope.
-- And in these cases, we will check both the inter-unit case and
-- the intra-unit (within a single unit) case.
C_Scope := Current_Scope;
if Present (Outer_Scope) and then Within (Scope (Ent), Outer_Scope) then
Set_C_Scope;
Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode is
-- set, then we will do the check, but only in the inter-unit case (this
-- is to accommodate unguarded elaboration calls from other units in
-- which this same mode is set). We inhibit warnings in this case, since
-- this instantiation is not occurring in elaboration code.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
else
return;
end if;
end Check_Elab_Instantiation;
-------------------------
-- Check_Internal_Call --
-------------------------
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
function Within_Initial_Condition (Call : Node_Id) return Boolean;
-- Determine whether call Call occurs within pragma Initial_Condition or
-- pragma Check with check_kind set to Initial_Condition.
------------------------------
-- Within_Initial_Condition --
------------------------------
function Within_Initial_Condition (Call : Node_Id) return Boolean is
Args : List_Id;
Nam : Name_Id;
Par : Node_Id;
begin
-- Traverse the parent chain looking for an enclosing pragma
Par := Call;
while Present (Par) loop
if Nkind (Par) = N_Pragma then
Nam := Pragma_Name (Par);
-- Pragma Initial_Condition appears in its alternative from as
-- Check (Initial_Condition, ...).
if Nam = Name_Check then
Args := Pragma_Argument_Associations (Par);
-- Pragma Check should have at least two arguments
pragma Assert (Present (Args));
return
Chars (Expression (First (Args))) = Name_Initial_Condition;
-- Direct match
elsif Nam = Name_Initial_Condition then
return True;
-- Since pragmas are never nested within other pragmas, stop
-- the traversal.
else
return False;
end if;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
-- If assertions are not enabled, the check pragma is rewritten
-- as an if_statement in sem_prag, to generate various warnings
-- on boolean expressions. Retrieve the original pragma.
if Nkind (Original_Node (Par)) = N_Pragma then
Par := Original_Node (Par);
end if;
end loop;
return False;
end Within_Initial_Condition;
-- Local variables
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
-- Start of processing for Check_Internal_Call
begin
-- For P'Access, we want to warn if the -gnatw.f switch is set, and the
-- node comes from source.
if Nkind (N) = N_Attribute_Reference
and then ((not Warn_On_Elab_Access and then not Debug_Flag_Dot_O)
or else not Comes_From_Source (N))
then
return;
-- If not function or procedure call, instantiation, or 'Access, then
-- ignore call (this happens in some error cases and rewriting cases).
elsif Nkind (N) not in N_Attribute_Reference
| N_Function_Call
| N_Procedure_Call_Statement
and then not Inst_Case
then
return;
-- Nothing to do if this is a call or instantiation that has already
-- been found to be a sure ABE.
elsif Nkind (N) /= N_Attribute_Reference
and then Is_Known_Guaranteed_ABE (N)
then
return;
-- Nothing to do if errors already detected (avoid cascaded errors)
elsif Serious_Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if analyzing in special spec-expression mode, since the
-- call is not actually being made at this time.
elsif In_Spec_Expression then
return;
-- Nothing to do for call to intrinsic subprogram
elsif Is_Intrinsic_Subprogram (E) then
return;
-- Nothing to do if call is within a generic unit
elsif Inside_A_Generic then
return;
-- Nothing to do when the call appears within pragma Initial_Condition.
-- The pragma is part of the elaboration statements of a package body
-- and may only call external subprograms or subprograms whose body is
-- already available.
elsif Within_Initial_Condition (N) then
return;
end if;
-- Delay this call if we are still delaying calls
if Delaying_Elab_Checks then
Delay_Check.Append
((N => N,
E => E,
Orig_Ent => Orig_Ent,
Curscop => Current_Scope,
Outer_Scope => Outer_Scope,
From_Elab_Code => From_Elab_Code,
In_Task_Activation => In_Task_Activation,
From_SPARK_Code => SPARK_Mode = On));
return;
-- Otherwise, call phase 2 continuation right now
else
Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
end if;
end Check_Internal_Call;
----------------------------------
-- Check_Internal_Call_Continue --
----------------------------------
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
function Find_Elab_Reference (N : Node_Id) return Traverse_Result;
-- Function applied to each node as we traverse the body. Checks for
-- call or entity reference that needs checking, and if so checks it.
-- Always returns OK, so entire tree is traversed, except that as
-- described below subprogram bodies are skipped for now.
procedure Traverse is new Atree.Traverse_Proc (Find_Elab_Reference);
-- Traverse procedure using above Find_Elab_Reference function
-------------------------
-- Find_Elab_Reference --
-------------------------
function Find_Elab_Reference (N : Node_Id) return Traverse_Result is
Actual : Node_Id;
begin
-- If user has specified that there are no entry calls in elaboration
-- code, do not trace past an accept statement, because the rendez-
-- vous will happen after elaboration.
if Nkind (Original_Node (N)) in
N_Accept_Statement | N_Selective_Accept
and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
then
return Abandon;
-- If we have a function call, check it
elsif Nkind (N) = N_Function_Call then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- If we have a procedure call, check the call, and also check
-- arguments that are assignments (OUT or IN OUT mode formals).
elsif Nkind (N) = N_Procedure_Call_Statement then
Check_Elab_Call (N, Outer_Scope, In_Init_Proc => Is_Init_Proc (E));
Actual := First_Actual (N);
while Present (Actual) loop
if Known_To_Be_Assigned (Actual) then
Check_Elab_Assign (Actual);
end if;
Next_Actual (Actual);
end loop;
return OK;
-- If we have an access attribute for a subprogram, check it.
-- Suppress this behavior under debug flag.
elsif not Debug_Flag_Dot_UU
and then Nkind (N) = N_Attribute_Reference
and then
Attribute_Name (N) in Name_Access | Name_Unrestricted_Access
and then Is_Entity_Name (Prefix (N))
and then Is_Subprogram (Entity (Prefix (N)))
then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- In SPARK mode, if we have an entity reference to a variable, then
-- check it. For now we consider any reference.
elsif SPARK_Mode = On
and then Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable
then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- If we have a generic instantiation, check it
elsif Nkind (N) in N_Generic_Instantiation then
Check_Elab_Instantiation (N, Outer_Scope);
return OK;
-- Skip subprogram bodies that come from source (wait for call to
-- analyze these). The reason for the come from source test is to
-- avoid catching task bodies.
-- For task bodies, we should really avoid these too, waiting for the
-- task activation, but that's too much trouble to catch for now, so
-- we go in unconditionally. This is not so terrible, it means the
-- error backtrace is not quite complete, and we are too eager to
-- scan bodies of tasks that are unused, but this is hardly very
-- significant.
elsif Nkind (N) = N_Subprogram_Body
and then Comes_From_Source (N)
then
return Skip;
elsif Nkind (N) = N_Assignment_Statement
and then Comes_From_Source (N)
then
Check_Elab_Assign (Name (N));
return OK;
else
return OK;
end if;
end Find_Elab_Reference;
Inst_Case : constant Boolean := Is_Generic_Unit (E);
Loc : constant Source_Ptr := Sloc (N);
Ebody : Entity_Id;
Sbody : Node_Id;
-- Start of processing for Check_Internal_Call_Continue
begin
-- Save outer level call if at outer level
if Elab_Call.Last = 0 then
Outer_Level_Sloc := Loc;
end if;
-- If the call is to a function that renames a literal, no check needed
if Ekind (E) = E_Enumeration_Literal then
return;
end if;
-- Register the subprogram as examined within this particular context.
-- This ensures that calls to the same subprogram but in different
-- contexts receive warnings and checks of their own since the calls
-- may be reached through different flow paths.
Elab_Visited.Append ((Subp_Id => E, Context => Parent (N)));
Sbody := Unit_Declaration_Node (E);
if Nkind (Sbody) not in N_Subprogram_Body | N_Package_Body then
Ebody := Corresponding_Body (Sbody);
if No (Ebody) then
return;
else
Sbody := Unit_Declaration_Node (Ebody);
end if;
end if;
-- If the body appears after the outer level call or instantiation then
-- we have an error case handled below.
if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
and then not In_Task_Activation
then
null;
-- If we have the instantiation case we are done, since we now know that
-- the body of the generic appeared earlier.
elsif Inst_Case then
return;
-- Otherwise we have a call, so we trace through the called body to see
-- if it has any problems.
else
pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
Elab_Call.Append ((Cloc => Loc, Ent => E));
if Debug_Flag_Underscore_LL then
Write_Str ("Elab_Call.Last = ");
Write_Int (Int (Elab_Call.Last));
Write_Str (" Ent = ");
Write_Name (Chars (E));
Write_Str (" at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Now traverse declarations and statements of subprogram body. Note
-- that we cannot simply Traverse (Sbody), since traverse does not
-- normally visit subprogram bodies.
declare
Decl : Node_Id;
begin
Decl := First (Declarations (Sbody));
while Present (Decl) loop
Traverse (Decl);
Next (Decl);
end loop;
end;
Traverse (Handled_Statement_Sequence (Sbody));
Elab_Call.Decrement_Last;
return;
end if;
-- Here is the case of calling a subprogram where the body has not yet
-- been encountered. A warning message is needed, except if this is the
-- case of appearing within an aspect specification that results in
-- a check call, we do not really have such a situation, so no warning
-- is needed (e.g. the case of a precondition, where the call appears
-- textually before the body, but in actual fact is moved to the
-- appropriate subprogram body and so does not need a check).
declare
P : Node_Id;
O : Node_Id;
begin
P := Parent (N);
loop
-- Keep looking at parents if we are still in the subexpression
if Nkind (P) in N_Subexpr then
P := Parent (P);
-- Here P is the parent of the expression, check for special case
else
O := Original_Node (P);
-- Definitely not the special case if orig node is not a pragma
exit when Nkind (O) /= N_Pragma;
-- Check we have an If statement or a null statement (happens
-- when the If has been expanded to be True).
exit when Nkind (P) not in N_If_Statement | N_Null_Statement;
-- Our special case will be indicated either by the pragma
-- coming from an aspect ...
if Present (Corresponding_Aspect (O)) then
return;
-- Or, in the case of an initial condition, specifically by a
-- Check pragma specifying an Initial_Condition check.
elsif Pragma_Name (O) = Name_Check
and then
Chars
(Expression (First (Pragma_Argument_Associations (O)))) =
Name_Initial_Condition
then
return;
-- For anything else, we have an error
else
exit;
end if;
end if;
end loop;
end;
-- Not that special case, warning and dynamic check is required
-- If we have nothing in the call stack, then this is at the outer
-- level, and the ABE is bound to occur, unless it's a 'Access, or
-- it's a renaming.
if Elab_Call.Last = 0 then
Error_Msg_Warn := SPARK_Mode /= On;
declare
Insert_Check : Boolean := True;
-- This flag is set to True if an elaboration check should be
-- inserted.
begin
if In_Task_Activation then
Insert_Check := False;
elsif Inst_Case then
Error_Msg_NE
("cannot instantiate& before body seen<<", N, Orig_Ent);
elsif Nkind (N) = N_Attribute_Reference then
Error_Msg_NE
("Access attribute of & before body seen<<", N, Orig_Ent);
Error_Msg_N
("\possible Program_Error on later references<<", N);
Insert_Check := False;
elsif Nkind (Unit_Declaration_Node (Orig_Ent)) /=
N_Subprogram_Renaming_Declaration
or else Is_Generic_Actual_Subprogram (Orig_Ent)
then
Error_Msg_NE
("cannot call& before body seen<<", N, Orig_Ent);
else
Insert_Check := False;
end if;
if Insert_Check then
Error_Msg_N ("\Program_Error [<<", N);
Insert_Elab_Check (N);
end if;
end;
-- Call is not at outer level
else
-- Do not generate elaboration checks in GNATprove mode because the
-- elaboration counter and the check are both forms of expansion.
if GNATprove_Mode then
null;
-- Generate an elaboration check
elsif not Elaboration_Checks_Suppressed (E) then
Set_Elaboration_Entity_Required (E);
-- Create a declaration of the elaboration entity, and insert it
-- prior to the subprogram or the generic unit, within the same
-- scope. Since the subprogram may be overloaded, create a unique
-- entity.
if No (Elaboration_Entity (E)) then
declare
Loce : constant Source_Ptr := Sloc (E);
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (E), 'E', -1));
begin
Set_Elaboration_Entity (E, Ent);
Push_Scope (Scope (E));
Insert_Action (Declaration_Node (E),
Make_Object_Declaration (Loce,
Defining_Identifier => Ent,
Object_Definition =>
New_Occurrence_Of (Standard_Short_Integer, Loce),
Expression =>
Make_Integer_Literal (Loc, Uint_0)));
-- Set elaboration flag at the point of the body
Set_Elaboration_Flag (Sbody, E);
-- Kill current value indication. This is necessary because
-- the tests of this flag are inserted out of sequence and
-- must not pick up bogus indications of the wrong constant
-- value. Also, this is never a true constant, since one way
-- or another, it gets reset.
Set_Current_Value (Ent, Empty);
Set_Last_Assignment (Ent, Empty);
Set_Is_True_Constant (Ent, False);
Pop_Scope;
end;
end if;
-- Generate:
-- if Enn = 0 then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix => New_Occurrence_Of (E, Loc)));
end if;
-- Generate the warning
if not Suppress_Elaboration_Warnings (E)
and then not Elaboration_Checks_Suppressed (E)
-- Suppress this warning if we have a function call that occurred
-- within an assertion expression, since we can get false warnings
-- in this case, due to the out of order handling in this case.
and then
(Nkind (Original_Node (N)) /= N_Function_Call
or else not In_Assertion_Expression_Pragma (Original_Node (N)))
then
Error_Msg_Warn := SPARK_Mode /= On;
if Inst_Case then
Error_Msg_NE
("instantiation of& may occur before body is seen<l<",
N, Orig_Ent);
else
-- A rather specific check. For Finalize/Adjust/Initialize, if
-- the type has Warnings_Off set, suppress the warning.
if Chars (E) in Name_Adjust
| Name_Finalize
| Name_Initialize
and then Present (First_Formal (E))
then
declare
T : constant Entity_Id := Etype (First_Formal (E));
begin
if Is_Controlled (T) then
if Has_Warnings_Off (T)
or else (Ekind (T) = E_Private_Type
and then Has_Warnings_Off (Full_View (T)))
then
goto Output;
end if;
end if;
end;
end if;
-- Go ahead and give warning if not this special case
Error_Msg_NE
("call to& may occur before body is seen<l<", N, Orig_Ent);
end if;
Error_Msg_N ("\Program_Error ]<l<", N);
-- There is no need to query the elaboration warning message flags
-- because the main message is an error, not a warning, therefore
-- all the clarification messages produces by Output_Calls must be
-- emitted unconditionally.
<<Output>>
Output_Calls (N, Check_Elab_Flag => False);
end if;
end if;
end Check_Internal_Call_Continue;
---------------------------
-- Check_Task_Activation --
---------------------------
procedure Check_Task_Activation (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Inter_Procs : constant Elist_Id := New_Elmt_List;
Intra_Procs : constant Elist_Id := New_Elmt_List;
Ent : Entity_Id;
P : Entity_Id;
Task_Scope : Entity_Id;
Cunit_SC : Boolean := False;
Decl : Node_Id;
Elmt : Elmt_Id;
Enclosing : Entity_Id;
procedure Add_Task_Proc (Typ : Entity_Id);
-- Add to Task_Procs the task body procedure(s) of task types in Typ.
-- For record types, this procedure recurses over component types.
procedure Collect_Tasks (Decls : List_Id);
-- Collect the types of the tasks that are to be activated in the given
-- list of declarations, in order to perform elaboration checks on the
-- corresponding task procedures that are called implicitly here.
function Outer_Unit (E : Entity_Id) return Entity_Id;
-- find enclosing compilation unit of Entity, ignoring subunits, or
-- else enclosing subprogram. If E is not a package, there is no need
-- for inter-unit elaboration checks.
-------------------
-- Add_Task_Proc --
-------------------
procedure Add_Task_Proc (Typ : Entity_Id) is
Comp : Entity_Id;
Proc : Entity_Id := Empty;
begin
if Is_Task_Type (Typ) then
Proc := Get_Task_Body_Procedure (Typ);
elsif Is_Array_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Add_Task_Proc (Component_Type (Typ));
elsif Is_Record_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Comp := First_Component (Typ);
while Present (Comp) loop
Add_Task_Proc (Etype (Comp));
Next_Component (Comp);
end loop;
end if;
-- If the task type is another unit, we will perform the usual
-- elaboration check on its enclosing unit. If the type is in the
-- same unit, we can trace the task body as for an internal call,
-- but we only need to examine other external calls, because at
-- the point the task is activated, internal subprogram bodies
-- will have been elaborated already. We keep separate lists for
-- each kind of task.
-- Skip this test if errors have occurred, since in this case
-- we can get false indications.
if Serious_Errors_Detected /= 0 then
return;
end if;
if Present (Proc) then
if Outer_Unit (Scope (Proc)) = Enclosing then
if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
and then
(not Is_Generic_Instance (Scope (Proc))
or else Scope (Proc) = Scope (Defining_Identifier (Decl)))
then
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N
("task will be activated before elaboration of its body<<",
Decl);
Error_Msg_N ("\Program_Error [<<", Decl);
elsif Present
(Corresponding_Body (Unit_Declaration_Node (Proc)))
then
Append_Elmt (Proc, Intra_Procs);
end if;
else
-- No need for multiple entries of the same type
Elmt := First_Elmt (Inter_Procs);
while Present (Elmt) loop
if Node (Elmt) = Proc then
return;
end if;
Next_Elmt (Elmt);
end loop;
Append_Elmt (Proc, Inter_Procs);
end if;
end if;
end Add_Task_Proc;
-------------------
-- Collect_Tasks --
-------------------
procedure Collect_Tasks (Decls : List_Id) is
begin
Decl := First (Decls);
while Present (Decl) loop
if Nkind (Decl) = N_Object_Declaration
and then Has_Task (Etype (Defining_Identifier (Decl)))
then
Add_Task_Proc (Etype (Defining_Identifier (Decl)));
end if;
Next (Decl);
end loop;
end Collect_Tasks;
----------------
-- Outer_Unit --
----------------
function Outer_Unit (E : Entity_Id) return Entity_Id is
Outer : Entity_Id;
begin
Outer := E;
while Present (Outer) loop
if Elaboration_Checks_Suppressed (Outer) then
Cunit_SC := True;
end if;
exit when Is_Child_Unit (Outer)
or else Scope (Outer) = Standard_Standard
or else Ekind (Outer) /= E_Package;
Outer := Scope (Outer);
end loop;
return Outer;
end Outer_Unit;
-- Start of processing for Check_Task_Activation
begin
pragma Assert (Legacy_Elaboration_Checks);
Enclosing := Outer_Unit (Current_Scope);
-- Find all tasks declared in the current unit
if Nkind (N) = N_Package_Body then
P := Unit_Declaration_Node (Corresponding_Spec (N));
Collect_Tasks (Declarations (N));
Collect_Tasks (Visible_Declarations (Specification (P)));
Collect_Tasks (Private_Declarations (Specification (P)));
elsif Nkind (N) = N_Package_Declaration then
Collect_Tasks (Visible_Declarations (Specification (N)));
Collect_Tasks (Private_Declarations (Specification (N)));
else
Collect_Tasks (Declarations (N));
end if;
-- We only perform detailed checks in all tasks that are library level
-- entities. If the master is a subprogram or task, activation will
-- depend on the activation of the master itself.
-- Should dynamic checks be added in the more general case???
if Ekind (Enclosing) /= E_Package then
return;
end if;
-- For task types defined in other units, we want the unit containing
-- the task body to be elaborated before the current one.
Elmt := First_Elmt (Inter_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Task_Scope := Outer_Unit (Scope (Ent));
if not Is_Compilation_Unit (Task_Scope) then
null;
elsif Suppress_Elaboration_Warnings (Task_Scope)
or else Elaboration_Checks_Suppressed (Task_Scope)
then
null;
elsif Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Cunit_SC
and then not Restriction_Active
(No_Entry_Calls_In_Elaboration_Code)
then
-- Runtime elaboration check required. Generate check of the
-- elaboration counter for the unit containing the entity.
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Spec_Entity (Task_Scope), Loc),
Attribute_Name => Name_Elaborated));
end if;
else
-- Force the binder to elaborate other unit first
if Elab_Info_Messages
and then not Suppress_Elaboration_Warnings (Ent)
and then not Elaboration_Checks_Suppressed (Ent)
and then not Suppress_Elaboration_Warnings (Task_Scope)
and then not Elaboration_Checks_Suppressed (Task_Scope)
then
Error_Msg_Node_2 := Task_Scope;
Error_Msg_NE
("info: activation of an instance of task type & requires "
& "pragma Elaborate_All on &?$?", N, Ent);
end if;
Activate_Elaborate_All_Desirable (N, Task_Scope);
Set_Suppress_Elaboration_Warnings (Task_Scope);
end if;
Next_Elmt (Elmt);
end loop;
-- For tasks declared in the current unit, trace other calls within the
-- task procedure bodies, which are available.
if not Debug_Flag_Dot_Y then
In_Task_Activation := True;
Elmt := First_Elmt (Intra_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
Next_Elmt (Elmt);
end loop;
In_Task_Activation := False;
end if;
end Check_Task_Activation;
------------------------
-- Get_Referenced_Ent --
------------------------
function Get_Referenced_Ent (N : Node_Id) return Entity_Id is
Nam : Node_Id;
begin
if Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable
then
return Entity (N);
end if;
if Nkind (N) = N_Attribute_Reference then
Nam := Prefix (N);
else
Nam := Name (N);
end if;
if No (Nam) then
return Empty;
elsif Nkind (Nam) = N_Selected_Component then
return Entity (Selector_Name (Nam));
elsif not Is_Entity_Name (Nam) then
return Empty;
else
return Entity (Nam);
end if;
end Get_Referenced_Ent;
----------------------
-- Has_Generic_Body --
----------------------
function Has_Generic_Body (N : Node_Id) return Boolean is
Ent : constant Entity_Id := Get_Generic_Entity (N);
Decl : constant Node_Id := Unit_Declaration_Node (Ent);
Scop : Entity_Id;
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
-- Determine if the list of nodes headed by N and linked by Next
-- contains a package body for the package spec entity E, and if so
-- return the package body. If not, then returns Empty.
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
-- This procedure is called load the unit whose name is given by Nam.
-- This unit is being loaded to see whether it contains an optional
-- generic body. The returned value is the loaded unit, which is always
-- a package body (only package bodies can contain other entities in the
-- sense in which Has_Generic_Body is interested). We only attempt to
-- load bodies if we are generating code. If we are in semantics check
-- only mode, then it would be wrong to load bodies that are not
-- required from a semantic point of view, so in this case we return
-- Empty. The result is that the caller may incorrectly decide that a
-- generic spec does not have a body when in fact it does, but the only
-- harm in this is that some warnings on elaboration problems may be
-- lost in semantic checks only mode, which is not big loss. We also
-- return Empty if we go for a body and it is not there.
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
-- PE is the entity for a package spec. This function locates the
-- corresponding package body, returning Empty if none is found. The
-- package body returned is fully parsed but may not yet be analyzed,
-- so only syntactic fields should be referenced.
------------------
-- Find_Body_In --
------------------
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
Nod : Node_Id;
begin
Nod := N;
while Present (Nod) loop
-- If we found the package body we are looking for, return it
if Nkind (Nod) = N_Package_Body
and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
then
return Nod;
-- If we found the stub for the body, go after the subunit,
-- loading it if necessary.
elsif Nkind (Nod) = N_Package_Body_Stub
and then Chars (Defining_Identifier (Nod)) = Chars (E)
then
if Present (Library_Unit (Nod)) then
return Unit (Library_Unit (Nod));
else
return Load_Package_Body (Get_Unit_Name (Nod));
end if;
-- If neither package body nor stub, keep looking on chain
else
Next (Nod);
end if;
end loop;
return Empty;
end Find_Body_In;
-----------------------
-- Load_Package_Body --
-----------------------
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
U : Unit_Number_Type;
begin
if Operating_Mode /= Generate_Code then
return Empty;
else
U :=
Load_Unit
(Load_Name => Nam,
Required => False,
Subunit => False,
Error_Node => N);
if U = No_Unit then
return Empty;
else
return Unit (Cunit (U));
end if;
end if;
end Load_Package_Body;
-------------------------------
-- Locate_Corresponding_Body --
-------------------------------
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
Spec : constant Node_Id := Declaration_Node (PE);
Decl : constant Node_Id := Parent (Spec);
Scop : constant Entity_Id := Scope (PE);
PBody : Node_Id;
begin
if Is_Library_Level_Entity (PE) then
-- If package is a library unit that requires a body, we have no
-- choice but to go after that body because it might contain an
-- optional body for the original generic package.
if Unit_Requires_Body (PE) then
-- Load the body. Note that we are a little careful here to use
-- Spec to get the unit number, rather than PE or Decl, since
-- in the case where the package is itself a library level
-- instantiation, Spec will properly reference the generic
-- template, which is what we really want.
return
Load_Package_Body
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
-- But if the package is a library unit that does NOT require
-- a body, then no body is permitted, so we are sure that there
-- is no body for the original generic package.
else
return Empty;
end if;
-- Otherwise look and see if we are embedded in a further package
elsif Is_Package_Or_Generic_Package (Scop) then
-- If so, get the body of the enclosing package, and look in
-- its package body for the package body we are looking for.
PBody := Locate_Corresponding_Body (Scop);
if No (PBody) then
return Empty;
else
return Find_Body_In (PE, First (Declarations (PBody)));
end if;
-- If we are not embedded in a further package, then the body
-- must be in the same declarative part as we are.
else
return Find_Body_In (PE, Next (Decl));
end if;
end Locate_Corresponding_Body;
-- Start of processing for Has_Generic_Body
begin
if Present (Corresponding_Body (Decl)) then
return True;
elsif Unit_Requires_Body (Ent) then
return True;
-- Compilation units cannot have optional bodies
elsif Is_Compilation_Unit (Ent) then
return False;
-- Otherwise look at what scope we are in
else
Scop := Scope (Ent);
-- Case of entity is in other than a package spec, in this case
-- the body, if present, must be in the same declarative part.
if not Is_Package_Or_Generic_Package (Scop) then
declare
P : Node_Id;
begin
-- Declaration node may get us a spec, so if so, go to
-- the parent declaration.
P := Declaration_Node (Ent);
while not Is_List_Member (P) loop
P := Parent (P);
end loop;
return Present (Find_Body_In (Ent, Next (P)));
end;
-- If the entity is in a package spec, then we have to locate
-- the corresponding package body, and look there.
else
declare
PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
begin
if No (PBody) then
return False;
else
return
Present
(Find_Body_In (Ent, (First (Declarations (PBody)))));
end if;
end;
end if;
end if;
end Has_Generic_Body;
-----------------------
-- Insert_Elab_Check --
-----------------------
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
Nod : Node_Id;
Loc : constant Source_Ptr := Sloc (N);
Chk : Node_Id;
-- The check (N_Raise_Program_Error) node to be inserted
begin
-- If expansion is disabled, do not generate any checks. Also
-- skip checks if any subunits are missing because in either
-- case we lack the full information that we need, and no object
-- file will be created in any case.
if not Expander_Active or else Subunits_Missing then
return;
end if;
-- If we have a generic instantiation, where Instance_Spec is set,
-- then this field points to a generic instance spec that has
-- been inserted before the instantiation node itself, so that
-- is where we want to insert a check.
if Nkind (N) in N_Generic_Instantiation
and then Present (Instance_Spec (N))
then
Nod := Instance_Spec (N);
else
Nod := N;
end if;
-- Build check node, possibly with condition
Chk :=
Make_Raise_Program_Error (Loc, Reason => PE_Access_Before_Elaboration);
if Present (C) then
Set_Condition (Chk, Make_Op_Not (Loc, Right_Opnd => C));
end if;
-- If we are inserting at the top level, insert in Aux_Decls
if Nkind (Parent (Nod)) = N_Compilation_Unit then
declare
ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
begin
if No (Declarations (ADN)) then
Set_Declarations (ADN, New_List (Chk));
else
Append_To (Declarations (ADN), Chk);
end if;
Analyze (Chk);
end;
-- Otherwise just insert as an action on the node in question
else
Insert_Action (Nod, Chk);
end if;
end Insert_Elab_Check;
-------------------------------
-- Is_Call_Of_Generic_Formal --
-------------------------------
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean is
begin
return Nkind (N) in N_Subprogram_Call
-- Always return False if debug flag -gnatd.G is set
and then not Debug_Flag_Dot_GG
-- For now, we detect this by looking for the strange identifier
-- node, whose Chars reflect the name of the generic formal, but
-- the Chars of the Entity references the generic actual.
and then Nkind (Name (N)) = N_Identifier
and then Chars (Name (N)) /= Chars (Entity (Name (N)));
end Is_Call_Of_Generic_Formal;
-------------------------------
-- Is_Finalization_Procedure --
-------------------------------
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean is
begin
-- Check whether Id is a procedure with at least one parameter
if Ekind (Id) = E_Procedure and then Present (First_Formal (Id)) then
declare
Typ : constant Entity_Id := Etype (First_Formal (Id));
Deep_Fin : Entity_Id := Empty;
Fin : Entity_Id := Empty;
begin
-- If the type of the first formal does not require finalization
-- actions, then this is definitely not [Deep_]Finalize.
if not Needs_Finalization (Typ) then
return False;
end if;
-- At this point we have the following scenario:
-- procedure Name (Param1 : [in] [out] Ctrl[; Param2 : ...]);
-- Recover the two possible versions of [Deep_]Finalize using the
-- type of the first parameter and compare with the input.
Deep_Fin := TSS (Typ, TSS_Deep_Finalize);
if Is_Controlled (Typ) then
Fin := Find_Prim_Op (Typ, Name_Finalize);
end if;
return (Present (Deep_Fin) and then Id = Deep_Fin)
or else (Present (Fin) and then Id = Fin);
end;
end if;
return False;
end Is_Finalization_Procedure;
------------------
-- Output_Calls --
------------------
procedure Output_Calls
(N : Node_Id;
Check_Elab_Flag : Boolean)
is
function Emit (Flag : Boolean) return Boolean;
-- Determine whether to emit an error message based on the combination
-- of flags Check_Elab_Flag and Flag.
function Is_Printable_Error_Name return Boolean;
-- An internal function, used to determine if a name, stored in the
-- Name_Buffer, is either a non-internal name, or is an internal name
-- that is printable by the error message circuits (i.e. it has a single
-- upper case letter at the end).
----------
-- Emit --
----------
function Emit (Flag : Boolean) return Boolean is
begin
if Check_Elab_Flag then
return Flag;
else
return True;
end if;
end Emit;
-----------------------------
-- Is_Printable_Error_Name --
-----------------------------
function Is_Printable_Error_Name return Boolean is
begin
if not Is_Internal_Name then
return True;
elsif Name_Len = 1 then
return False;
else
Name_Len := Name_Len - 1;
return not Is_Internal_Name;
end if;
end Is_Printable_Error_Name;
-- Local variables
Ent : Entity_Id;
-- Start of processing for Output_Calls
begin
for J in reverse 1 .. Elab_Call.Last loop
Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
Ent := Elab_Call.Table (J).Ent;
Get_Name_String (Chars (Ent));
-- Dynamic elaboration model, warnings controlled by -gnatwl
if Dynamic_Elaboration_Checks then
if Emit (Elab_Warnings) then
if Is_Generic_Unit (Ent) then
Error_Msg_NE ("\\?l?& instantiated #", N, Ent);
elsif Is_Init_Proc (Ent) then
Error_Msg_N ("\\?l?initialization procedure called #", N);
elsif Is_Printable_Error_Name then
Error_Msg_NE ("\\?l?& called #", N, Ent);
else
Error_Msg_N ("\\?l?called #", N);
end if;
end if;
-- Static elaboration model, info messages controlled by -gnatel
else
if Emit (Elab_Info_Messages) then
if Is_Generic_Unit (Ent) then
Error_Msg_NE ("\\?$?& instantiated #", N, Ent);
elsif Is_Init_Proc (Ent) then
Error_Msg_N ("\\?$?initialization procedure called #", N);
elsif Is_Printable_Error_Name then
Error_Msg_NE ("\\?$?& called #", N, Ent);
else
Error_Msg_N ("\\?$?called #", N);
end if;
end if;
end if;
end loop;
end Output_Calls;
----------------------------
-- Same_Elaboration_Scope --
----------------------------
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
S1 : Entity_Id;
S2 : Entity_Id;
begin
-- Find elaboration scope for Scop1
-- This is either a subprogram or a compilation unit.
S1 := Scop1;
while S1 /= Standard_Standard
and then not Is_Compilation_Unit (S1)
and then Ekind (S1) in E_Package | E_Protected_Type | E_Block
loop
S1 := Scope (S1);
end loop;
-- Find elaboration scope for Scop2
S2 := Scop2;
while S2 /= Standard_Standard
and then not Is_Compilation_Unit (S2)
and then Ekind (S2) in E_Package | E_Protected_Type | E_Block
loop
S2 := Scope (S2);
end loop;
return S1 = S2;
end Same_Elaboration_Scope;
-----------------
-- Set_C_Scope --
-----------------
procedure Set_C_Scope is
begin
while not Is_Compilation_Unit (C_Scope) loop
C_Scope := Scope (C_Scope);
end loop;
end Set_C_Scope;
--------------------------------
-- Set_Elaboration_Constraint --
--------------------------------
procedure Set_Elaboration_Constraint
(Call : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id)
is
Elab_Unit : Entity_Id;
-- Check whether this is a call to an Initialize subprogram for a
-- controlled type. Note that Call can also be a 'Access attribute
-- reference, which now generates an elaboration check.
Init_Call : constant Boolean :=
Nkind (Call) = N_Procedure_Call_Statement
and then Chars (Subp) = Name_Initialize
and then Comes_From_Source (Subp)
and then Present (Parameter_Associations (Call))
and then Is_Controlled (Etype (First_Actual (Call)));
begin
-- If the unit is mentioned in a with_clause of the current unit, it is
-- visible, and we can set the elaboration flag.
if Is_Immediately_Visible (Scop)
or else (Is_Child_Unit (Scop) and then Is_Visible_Lib_Unit (Scop))
then
Activate_Elaborate_All_Desirable (Call, Scop);
Set_Suppress_Elaboration_Warnings (Scop);
return;
end if;
-- If this is not an initialization call or a call using object notation
-- we know that the unit of the called entity is in the context, and we
-- can set the flag as well. The unit need not be visible if the call
-- occurs within an instantiation.
if Is_Init_Proc (Subp)
or else Init_Call
or else Nkind (Original_Node (Call)) = N_Selected_Component
then
null; -- detailed processing follows.
else
Activate_Elaborate_All_Desirable (Call, Scop);
Set_Suppress_Elaboration_Warnings (Scop);
return;
end if;
-- If the unit is not in the context, there must be an intermediate unit
-- that is, on which we need to place to elaboration flag. This happens
-- with init proc calls.
if Is_Init_Proc (Subp) or else Init_Call then
-- The initialization call is on an object whose type is not declared
-- in the same scope as the subprogram. The type of the object must
-- be a subtype of the type of operation. This object is the first
-- actual in the call.
declare
Typ : constant Entity_Id :=
Etype (First (Parameter_Associations (Call)));
begin
Elab_Unit := Scope (Typ);
while Present (Elab_Unit)
and then not Is_Compilation_Unit (Elab_Unit)
loop
Elab_Unit := Scope (Elab_Unit);
end loop;
end;
-- If original node uses selected component notation, the prefix is
-- visible and determines the scope that must be elaborated. After
-- rewriting, the prefix is the first actual in the call.
elsif Nkind (Original_Node (Call)) = N_Selected_Component then
Elab_Unit := Scope (Etype (First (Parameter_Associations (Call))));
-- Not one of special cases above
else
-- Using previously computed scope. If the elaboration check is
-- done after analysis, the scope is not visible any longer, but
-- must still be in the context.
Elab_Unit := Scop;
end if;
Activate_Elaborate_All_Desirable (Call, Elab_Unit);
Set_Suppress_Elaboration_Warnings (Elab_Unit);
end Set_Elaboration_Constraint;
-----------------
-- Spec_Entity --
-----------------
function Spec_Entity (E : Entity_Id) return Entity_Id is
Decl : Node_Id;
begin
-- Check for case of body entity
-- Why is the check for E_Void needed???
if Ekind (E) in E_Void | E_Subprogram_Body | E_Package_Body then
Decl := E;
loop
Decl := Parent (Decl);
exit when Nkind (Decl) in N_Proper_Body;
end loop;
return Corresponding_Spec (Decl);
else
return E;
end if;
end Spec_Entity;
------------
-- Within --
------------
function Within (E1, E2 : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := E1;
loop
if Scop = E2 then
return True;
elsif Scop = Standard_Standard then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
end Within;
--------------------------
-- Within_Elaborate_All --
--------------------------
function Within_Elaborate_All
(Unit : Unit_Number_Type;
E : Entity_Id) return Boolean
is
type Unit_Number_Set is array (Main_Unit .. Last_Unit) of Boolean;
pragma Pack (Unit_Number_Set);
Seen : Unit_Number_Set := (others => False);
-- Seen (X) is True after we have seen unit X in the walk. This is used
-- to prevent processing the same unit more than once.
Result : Boolean := False;
procedure Helper (Unit : Unit_Number_Type);
-- This helper procedure does all the work for Within_Elaborate_All. It
-- walks the dependency graph, and sets Result to True if it finds an
-- appropriate Elaborate_All.
------------
-- Helper --
------------
procedure Helper (Unit : Unit_Number_Type) is
CU : constant Node_Id := Cunit (Unit);
Item : Node_Id;
Item2 : Node_Id;
Elab_Id : Entity_Id;
Par : Node_Id;
begin
if Seen (Unit) then
return;
else
Seen (Unit) := True;
end if;
-- First, check for Elaborate_Alls on this unit
Item := First (Context_Items (CU));
while Present (Item) loop
if Nkind (Item) = N_Pragma
and then Pragma_Name (Item) = Name_Elaborate_All
then
-- Return if some previous error on the pragma itself. The
-- pragma may be unanalyzed, because of a previous error, or
-- if it is the context of a subunit, inherited by its parent.
if Error_Posted (Item) or else not Analyzed (Item) then
return;
end if;
Elab_Id :=
Entity
(Expression (First (Pragma_Argument_Associations (Item))));
if E = Elab_Id then
Result := True;
return;
end if;
Par := Parent (Unit_Declaration_Node (Elab_Id));
Item2 := First (Context_Items (Par));
while Present (Item2) loop
if Nkind (Item2) = N_With_Clause
and then Entity (Name (Item2)) = E
and then not Limited_Present (Item2)
then
Result := True;
return;
end if;
Next (Item2);
end loop;
end if;
Next (Item);
end loop;
-- Second, recurse on with's. We could do this as part of the above
-- loop, but it's probably more efficient to have two loops, because
-- the relevant Elaborate_All is likely to be on the initial unit. In
-- other words, we're walking the with's breadth-first. This part is
-- only necessary in the dynamic elaboration model.
if Dynamic_Elaboration_Checks then
Item := First (Context_Items (CU));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Limited_Present (Item)
then
-- Note: the following call to Get_Cunit_Unit_Number does a
-- linear search, which could be slow, but it's OK because
-- we're about to give a warning anyway. Also, there might
-- be hundreds of units, but not millions. If it turns out
-- to be a problem, we could store the Get_Cunit_Unit_Number
-- in each N_Compilation_Unit node, but that would involve
-- rearranging N_Compilation_Unit_Aux to make room.
Helper (Get_Cunit_Unit_Number (Library_Unit (Item)));
if Result then
return;
end if;
end if;
Next (Item);
end loop;
end if;
end Helper;
-- Start of processing for Within_Elaborate_All
begin
Helper (Unit);
return Result;
end Within_Elaborate_All;
end Sem_Elab;
|