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
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P A R . C H 3 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Style_Checks (All_Checks);
-- Turn off subprogram body ordering check. Subprograms are in order
-- by RM section rather than alphabetical.
with Sinfo.CN; use Sinfo.CN;
separate (Par)
---------
-- Ch3 --
---------
package body Ch3 is
-----------------------
-- Local Subprograms --
-----------------------
function P_Component_List return Node_Id;
function P_Defining_Character_Literal return Node_Id;
function P_Delta_Constraint return Node_Id;
function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id;
function P_Digits_Constraint return Node_Id;
function P_Discriminant_Association return Node_Id;
function P_Enumeration_Literal_Specification return Node_Id;
function P_Enumeration_Type_Definition return Node_Id;
function P_Fixed_Point_Definition return Node_Id;
function P_Floating_Point_Definition return Node_Id;
function P_Index_Or_Discriminant_Constraint return Node_Id;
function P_Real_Range_Specification_Opt return Node_Id;
function P_Subtype_Declaration return Node_Id;
function P_Type_Declaration return Node_Id;
function P_Modular_Type_Definition return Node_Id;
function P_Variant return Node_Id;
function P_Variant_Part return Node_Id;
procedure Check_Restricted_Expression (N : Node_Id);
-- Check that the expression N meets the Restricted_Expression syntax.
-- The syntax is as follows:
--
-- RESTRICTED_EXPRESSION ::=
-- RESTRICTED_RELATION {and RESTRICTED_RELATION}
-- | RESTRICTED_RELATION {and then RESTRICTED_RELATION}
-- | RESTRICTED_RELATION {or RESTRICTED_RELATION}
-- | RESTRICTED_RELATION {or else RESTRICTED_RELATION}
-- | RESTRICTED_RELATION {xor RESTRICTED_RELATION}
--
-- RESTRICTED_RELATION ::=
-- SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION]
--
-- This syntax is used for choices when extensions (and set notations)
-- are enabled, to remove the ambiguity of "when X in A | B". We consider
-- it very unlikely that this will ever arise in practice.
procedure P_Declarative_Item
(Decls : List_Id;
Done : out Boolean;
Declare_Expression : Boolean;
In_Spec : Boolean;
In_Statements : Boolean);
-- Parses a single declarative item. The parameters have the same meaning
-- as for P_Declarative_Items. If the declarative item has multiple
-- identifiers, as in "X, Y, Z : ...", then one declaration is appended to
-- Decls for each of the identifiers.
procedure P_Identifier_Declarations
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean;
In_Statements : Boolean);
-- Parses a sequence of declarations for an identifier or list of
-- identifiers, and appends them to the given list. The parameters
-- have the same meaning as for P_Declarative_Items.
procedure Statement_When_Declaration_Expected
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean);
-- Called when a statement is found at a point where a declaration was
-- expected. The parameters have the same meaning as for
-- P_Declarative_Items.
procedure Set_Declaration_Expected;
-- Posts a "declaration expected" error messages at the start of the
-- current token, and if this is the first such message issued, saves
-- the message id in Missing_Begin_Msg, for possible later replacement.
---------------------------------
-- Check_Restricted_Expression --
---------------------------------
procedure Check_Restricted_Expression (N : Node_Id) is
begin
if Nkind (N) in N_Op_And | N_Op_Or | N_Op_Xor | N_And_Then | N_Or_Else
then
Check_Restricted_Expression (Left_Opnd (N));
Check_Restricted_Expression (Right_Opnd (N));
elsif Nkind (N) in N_In | N_Not_In
and then Paren_Count (N) = 0
then
Error_Msg_N ("|this expression must be parenthesized!", N);
end if;
end Check_Restricted_Expression;
-------------------
-- Init_Expr_Opt --
-------------------
function Init_Expr_Opt (P : Boolean := False) return Node_Id is
begin
-- For colon, assume it means := unless it is at the end of
-- a line, in which case guess that it means a semicolon.
if Token = Tok_Colon then
if Token_Is_At_End_Of_Line then
T_Semicolon;
return Empty;
end if;
-- Here if := or something that we will take as equivalent
elsif Token in Tok_Colon_Equal | Tok_Equal | Tok_Is then
null;
-- Another possibility. If we have a literal followed by a semicolon,
-- we assume that we have a missing colon-equal.
elsif Token in Token_Class_Literal then
declare
Scan_State : Saved_Scan_State;
begin
Save_Scan_State (Scan_State);
Scan; -- past literal or identifier
if Token = Tok_Semicolon then
Restore_Scan_State (Scan_State);
else
Restore_Scan_State (Scan_State);
return Empty;
end if;
end;
-- Otherwise we definitely have no initialization expression
else
return Empty;
end if;
-- Merge here if we have an initialization expression
T_Colon_Equal;
if P then
return P_Expression;
else
return P_Expression_No_Right_Paren;
end if;
end Init_Expr_Opt;
----------------------------
-- 3.1 Basic Declaration --
----------------------------
-- Parsed by P_Basic_Declarative_Items (3.9)
------------------------------
-- 3.1 Defining Identifier --
------------------------------
-- DEFINING_IDENTIFIER ::= IDENTIFIER
-- Error recovery: can raise Error_Resync
function P_Defining_Identifier (C : Id_Check := None) return Node_Id is
Ident_Node : Node_Id := P_Identifier (C, True);
begin
-- If we already have a defining identifier, clean it out and make
-- a new clean identifier. This situation arises in some error cases
-- and we need to fix it.
if Nkind (Ident_Node) = N_Defining_Identifier then
Ident_Node := Make_Identifier (Sloc (Ident_Node), Chars (Ident_Node));
end if;
-- Change identifier to defining identifier if not in error
if Ident_Node /= Error then
Change_Identifier_To_Defining_Identifier (Ident_Node);
-- Warn if standard redefinition, except that we never warn on a
-- record field definition (since this is always a harmless case).
if not Inside_Record_Definition then
Warn_If_Standard_Redefinition (Ident_Node);
end if;
end if;
return Ident_Node;
end P_Defining_Identifier;
-----------------------------
-- 3.2.1 Type Declaration --
-----------------------------
-- TYPE_DECLARATION ::=
-- FULL_TYPE_DECLARATION
-- | INCOMPLETE_TYPE_DECLARATION
-- | PRIVATE_TYPE_DECLARATION
-- | PRIVATE_EXTENSION_DECLARATION
-- FULL_TYPE_DECLARATION ::=
-- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION
-- [ASPECT_SPECIFICATIONS];
-- | CONCURRENT_TYPE_DECLARATION
-- INCOMPLETE_TYPE_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
-- PRIVATE_TYPE_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
-- is [abstract] [tagged] [limited] private
-- [ASPECT_SPECIFICATIONS];
-- PRIVATE_EXTENSION_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
-- [abstract] [limited | synchronized]
-- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
-- with private [ASPECT_SPECIFICATIONS];
-- TYPE_DEFINITION ::=
-- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
-- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
-- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
-- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
-- INTEGER_TYPE_DEFINITION ::=
-- SIGNED_INTEGER_TYPE_DEFINITION
-- MODULAR_TYPE_DEFINITION
-- INTERFACE_TYPE_DEFINITION ::=
-- [limited | task | protected | synchronized ] interface
-- [and INTERFACE_LIST]
-- Error recovery: can raise Error_Resync
-- The processing for full type declarations, incomplete type declarations,
-- private type declarations and type definitions is included in this
-- function. The processing for concurrent type declarations is NOT here,
-- but rather in chapter 9 (this function handles only declarations
-- starting with TYPE).
function P_Type_Declaration return Node_Id is
Abstract_Present : Boolean := False;
Abstract_Loc : Source_Ptr := No_Location;
Decl_Node : Node_Id;
Discr_List : List_Id;
Discr_Sloc : Source_Ptr;
End_Labl : Node_Id;
Ident_Node : Node_Id;
Is_Derived_Iface : Boolean := False;
Type_Loc : Source_Ptr;
Type_Start_Col : Column_Number;
Unknown_Dis : Boolean;
Typedef_Node : Node_Id;
-- Normally holds type definition, except in the case of a private
-- extension declaration, in which case it holds the declaration itself
begin
Type_Loc := Token_Ptr;
Type_Start_Col := Start_Column;
-- If we have TYPE, then proceed ahead and scan identifier
if Token = Tok_Type then
Type_Token_Location := Type_Loc;
Scan; -- past TYPE
Ident_Node := P_Defining_Identifier (C_Is);
-- Otherwise this is an error case
else
T_Type;
Type_Token_Location := Type_Loc;
Ident_Node := P_Defining_Identifier (C_Is);
end if;
Discr_Sloc := Token_Ptr;
if P_Unknown_Discriminant_Part_Opt then
Unknown_Dis := True;
Discr_List := No_List;
else
Unknown_Dis := False;
Discr_List := P_Known_Discriminant_Part_Opt;
end if;
-- Incomplete type declaration. We complete the processing for this
-- case here and return the resulting incomplete type declaration node
if Token = Tok_Semicolon then
Scan; -- past ;
Decl_Node := New_Node (N_Incomplete_Type_Declaration, Type_Loc);
Set_Defining_Identifier (Decl_Node, Ident_Node);
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
Set_Discriminant_Specifications (Decl_Node, Discr_List);
return Decl_Node;
else
Decl_Node := Empty;
end if;
-- Full type declaration or private type declaration, must have IS
if Token = Tok_Equal then
TF_Is;
Scan; -- past = used in place of IS
elsif Token = Tok_Renames then
Error_Msg_SC -- CODEFIX
("RENAMES should be IS");
Scan; -- past RENAMES used in place of IS
else
TF_Is;
end if;
-- First an error check, if we have two identifiers in a row, a likely
-- possibility is that the first of the identifiers is an incorrectly
-- spelled keyword.
if Token = Tok_Identifier then
declare
SS : Saved_Scan_State;
I2 : Boolean;
begin
Save_Scan_State (SS);
Scan; -- past initial identifier
I2 := (Token = Tok_Identifier);
Restore_Scan_State (SS);
if I2
and then
(Bad_Spelling_Of (Tok_Abstract) or else
Bad_Spelling_Of (Tok_Access) or else
Bad_Spelling_Of (Tok_Aliased) or else
Bad_Spelling_Of (Tok_Constant))
then
null;
end if;
end;
end if;
-- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
if Token_Name = Name_Abstract then
Check_95_Keyword (Tok_Abstract, Tok_Tagged);
Check_95_Keyword (Tok_Abstract, Tok_New);
end if;
-- Check cases of misuse of ABSTRACT
if Token = Tok_Abstract then
Abstract_Present := True;
Abstract_Loc := Token_Ptr;
Scan; -- past ABSTRACT
-- Ada 2005 (AI-419): AARM 3.4 (2/2)
if (Ada_Version < Ada_2005 and then Token = Tok_Limited)
or else Token in Tok_Private | Tok_Record | Tok_Null
then
Error_Msg_AP ("TAGGED expected");
end if;
end if;
-- Check for misuse of Ada 95 keyword Tagged
if Token_Name = Name_Tagged then
Check_95_Keyword (Tok_Tagged, Tok_Private);
Check_95_Keyword (Tok_Tagged, Tok_Limited);
Check_95_Keyword (Tok_Tagged, Tok_Record);
end if;
-- Special check for misuse of Aliased
if Token = Tok_Aliased or else Token_Name = Name_Aliased then
Error_Msg_SC ("ALIASED not allowed in type definition");
Scan; -- past ALIASED
end if;
-- The following processing deals with either a private type declaration
-- or a full type declaration. In the private type case, we build the
-- N_Private_Type_Declaration node, setting its Tagged_Present and
-- Limited_Present flags, on encountering the Private keyword, and
-- leave Typedef_Node set to Empty. For the full type declaration
-- case, Typedef_Node gets set to the type definition.
Typedef_Node := Empty;
-- Switch on token following the IS. The loop normally runs once. It
-- only runs more than once if an error is detected, to try again after
-- detecting and fixing up the error.
loop
case Token is
when Tok_Access
| Tok_Not -- Ada 2005 (AI-231)
=>
Typedef_Node := P_Access_Type_Definition;
exit;
when Tok_Array =>
Typedef_Node := P_Array_Type_Definition;
exit;
when Tok_Delta =>
Typedef_Node := P_Fixed_Point_Definition;
exit;
when Tok_Digits =>
Typedef_Node := P_Floating_Point_Definition;
exit;
when Tok_In =>
Ignore (Tok_In);
when Tok_Integer_Literal =>
T_Range;
Typedef_Node := P_Signed_Integer_Type_Definition;
exit;
when Tok_Null =>
Typedef_Node := P_Record_Definition;
exit;
when Tok_Left_Paren =>
Typedef_Node := P_Enumeration_Type_Definition;
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
exit;
when Tok_Mod =>
Typedef_Node := P_Modular_Type_Definition;
exit;
when Tok_New =>
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
if Nkind (Typedef_Node) = N_Derived_Type_Definition
and then Present (Record_Extension_Part (Typedef_Node))
then
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label
(Record_Extension_Part (Typedef_Node), End_Labl);
end if;
exit;
when Tok_Range =>
Typedef_Node := P_Signed_Integer_Type_Definition;
exit;
when Tok_Record =>
Typedef_Node := P_Record_Definition;
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
exit;
when Tok_Tagged =>
Scan; -- past TAGGED
-- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
-- is a tagged incomplete type.
if Ada_Version >= Ada_2005
and then Token = Tok_Semicolon
then
Scan; -- past ;
Decl_Node :=
New_Node (N_Incomplete_Type_Declaration, Type_Loc);
Set_Defining_Identifier (Decl_Node, Ident_Node);
Set_Tagged_Present (Decl_Node);
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
Set_Discriminant_Specifications (Decl_Node, Discr_List);
return Decl_Node;
end if;
if Token = Tok_Abstract then
Error_Msg_SC -- CODEFIX
("ABSTRACT must come before TAGGED");
Abstract_Present := True;
Abstract_Loc := Token_Ptr;
Scan; -- past ABSTRACT
end if;
if Token = Tok_Limited then
Scan; -- past LIMITED
-- TAGGED LIMITED PRIVATE case
if Token = Tok_Private then
Decl_Node :=
New_Node (N_Private_Type_Declaration, Type_Loc);
Set_Tagged_Present (Decl_Node, True);
Set_Limited_Present (Decl_Node, True);
Scan; -- past PRIVATE
-- TAGGED LIMITED RECORD
else
Typedef_Node := P_Record_Definition;
Set_Tagged_Present (Typedef_Node, True);
Set_Limited_Present (Typedef_Node, True);
End_Labl :=
Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
end if;
else
-- TAGGED PRIVATE
if Token = Tok_Private then
Decl_Node :=
New_Node (N_Private_Type_Declaration, Type_Loc);
Set_Tagged_Present (Decl_Node, True);
Scan; -- past PRIVATE
-- TAGGED RECORD
else
Typedef_Node := P_Record_Definition;
Set_Tagged_Present (Typedef_Node, True);
End_Labl :=
Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
end if;
end if;
exit;
when Tok_Limited =>
Scan; -- past LIMITED
loop
if Token = Tok_Tagged then
Error_Msg_SC -- CODEFIX
("TAGGED must come before LIMITED");
Scan; -- past TAGGED
elsif Token = Tok_Abstract then
Error_Msg_SC -- CODEFIX
("ABSTRACT must come before LIMITED");
Scan; -- past ABSTRACT
else
exit;
end if;
end loop;
-- LIMITED RECORD or LIMITED NULL RECORD
if Token in Tok_Record | Tok_Null then
if Ada_Version = Ada_83 then
Error_Msg_SP
("(Ada 83) limited record declaration not allowed!");
-- In Ada 2005, "abstract limited" can appear before "new",
-- but it cannot be part of an untagged record declaration.
elsif Abstract_Present
and then Prev_Token /= Tok_Tagged
then
Error_Msg_SP ("TAGGED expected");
end if;
Typedef_Node := P_Record_Definition;
Set_Limited_Present (Typedef_Node, True);
End_Labl := Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
-- Ada 2005 (AI-251): LIMITED INTERFACE
-- If we are compiling in Ada 83 or Ada 95 mode, "interface"
-- is not a reserved word but we force its analysis to
-- generate the corresponding usage error.
elsif Token = Tok_Interface
or else (Token = Tok_Identifier
and then Chars (Token_Node) = Name_Interface)
then
Typedef_Node :=
P_Interface_Type_Definition (Abstract_Present);
Abstract_Present := True;
Set_Limited_Present (Typedef_Node);
if Nkind (Typedef_Node) = N_Derived_Type_Definition then
Is_Derived_Iface := True;
end if;
-- Ada 2005 (AI-419): LIMITED NEW
elsif Token = Tok_New then
Error_Msg_Ada_2005_Extension ("LIMITED in derived type");
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
Set_Limited_Present (Typedef_Node);
if Nkind (Typedef_Node) = N_Derived_Type_Definition
and then Present (Record_Extension_Part (Typedef_Node))
then
End_Labl :=
Make_Identifier (Token_Ptr, Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label
(Record_Extension_Part (Typedef_Node), End_Labl);
end if;
-- LIMITED PRIVATE is the only remaining possibility here
else
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
Set_Limited_Present (Decl_Node, True);
T_Private; -- past PRIVATE (or complain if not there)
end if;
exit;
-- Here we have an identifier after the IS, which is certainly
-- wrong and which might be one of several different mistakes.
when Tok_Identifier =>
-- First case, if identifier is on same line, then probably we
-- have something like "type X is Integer .." and the best
-- diagnosis is a missing NEW. Note: the missing new message
-- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
if not Token_Is_At_Start_Of_Line then
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
-- If the identifier is at the start of the line, and is in the
-- same column as the type declaration itself then we consider
-- that we had a missing type definition on the previous line
elsif Start_Column <= Type_Start_Col then
Error_Msg_AP ("type definition expected");
Typedef_Node := Error;
-- If the identifier is at the start of the line, and is in
-- a column to the right of the type declaration line, then we
-- may have something like:
-- type x is
-- r : integer
-- and the best diagnosis is a missing record keyword
else
Typedef_Node := P_Record_Definition;
end if;
exit;
-- Ada 2005 (AI-251): INTERFACE
when Tok_Interface =>
Typedef_Node := P_Interface_Type_Definition (Abstract_Present);
Abstract_Present := True;
exit;
when Tok_Private =>
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
Scan; -- past PRIVATE
-- Check error cases of private [abstract] tagged
if Token = Tok_Abstract then
Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
Scan; -- past ABSTRACT
if Token = Tok_Tagged then
Scan; -- past TAGGED
end if;
elsif Token = Tok_Tagged then
Error_Msg_SC ("TAGGED must come before PRIVATE");
Scan; -- past TAGGED
end if;
exit;
-- Ada 2005 (AI-345): Protected, synchronized or task interface
-- or Ada 2005 (AI-443): Synchronized private extension.
when Tok_Protected
| Tok_Synchronized
| Tok_Task
=>
declare
Saved_Token : constant Token_Type := Token;
begin
Scan; -- past TASK, PROTECTED or SYNCHRONIZED
-- Synchronized private extension
if Token = Tok_New then
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
if Saved_Token = Tok_Synchronized then
if Nkind (Typedef_Node) =
N_Derived_Type_Definition
then
Error_Msg_N
("SYNCHRONIZED not allowed for record extension",
Typedef_Node);
else
Set_Synchronized_Present (Typedef_Node);
end if;
else
Error_Msg_SC ("invalid kind of private extension");
end if;
-- Interface
else
if Token /= Tok_Interface then
Error_Msg_SC ("NEW or INTERFACE expected");
end if;
Typedef_Node :=
P_Interface_Type_Definition (Abstract_Present);
Abstract_Present := True;
case Saved_Token is
when Tok_Task =>
Set_Task_Present (Typedef_Node);
when Tok_Protected =>
Set_Protected_Present (Typedef_Node);
when Tok_Synchronized =>
Set_Synchronized_Present (Typedef_Node);
when others =>
pragma Assert (False);
null;
end case;
end if;
end;
exit;
-- Anything else is an error
when others =>
if Bad_Spelling_Of (Tok_Access)
or else
Bad_Spelling_Of (Tok_Array)
or else
Bad_Spelling_Of (Tok_Delta)
or else
Bad_Spelling_Of (Tok_Digits)
or else
Bad_Spelling_Of (Tok_Limited)
or else
Bad_Spelling_Of (Tok_Private)
or else
Bad_Spelling_Of (Tok_Range)
or else
Bad_Spelling_Of (Tok_Record)
or else
Bad_Spelling_Of (Tok_Tagged)
then
null;
else
Error_Msg_AP ("type definition expected");
raise Error_Resync;
end if;
end case;
end loop;
-- For the private type declaration case, the private type declaration
-- node has been built, with the Tagged_Present and Limited_Present
-- flags set as needed, and Typedef_Node is left set to Empty.
if No (Typedef_Node) then
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
Set_Abstract_Present (Decl_Node, Abstract_Present);
-- For a private extension declaration, Typedef_Node contains the
-- N_Private_Extension_Declaration node, which we now complete. Note
-- that the private extension declaration, unlike a full type
-- declaration, does permit unknown discriminants.
elsif Nkind (Typedef_Node) = N_Private_Extension_Declaration then
Decl_Node := Typedef_Node;
Set_Sloc (Decl_Node, Type_Loc);
Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
Set_Abstract_Present (Typedef_Node, Abstract_Present);
-- In the full type declaration case, Typedef_Node has the type
-- definition and here is where we build the full type declaration
-- node. This is also where we check for improper use of an unknown
-- discriminant part (not allowed for full type declaration).
else
if Nkind (Typedef_Node) = N_Record_Definition
or else (Nkind (Typedef_Node) = N_Derived_Type_Definition
and then Present (Record_Extension_Part (Typedef_Node)))
or else Is_Derived_Iface
then
Set_Abstract_Present (Typedef_Node, Abstract_Present);
elsif Abstract_Present then
Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc);
end if;
Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc);
Set_Type_Definition (Decl_Node, Typedef_Node);
if Unknown_Dis then
Error_Msg
("full type declaration cannot have unknown discriminants",
Discr_Sloc);
end if;
end if;
-- Remaining processing is common for all three cases
Set_Defining_Identifier (Decl_Node, Ident_Node);
Set_Discriminant_Specifications (Decl_Node, Discr_List);
P_Aspect_Specifications (Decl_Node);
return Decl_Node;
end P_Type_Declaration;
----------------------------------
-- 3.2.1 Full Type Declaration --
----------------------------------
-- Parsed by P_Type_Declaration (3.2.1)
----------------------------
-- 3.2.1 Type Definition --
----------------------------
-- Parsed by P_Type_Declaration (3.2.1)
--------------------------------
-- 3.2.2 Subtype Declaration --
--------------------------------
-- SUBTYPE_DECLARATION ::=
-- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION
-- [ASPECT_SPECIFICATIONS];
-- The caller has checked that the initial token is SUBTYPE
-- Error recovery: can raise Error_Resync
function P_Subtype_Declaration return Node_Id is
Decl_Node : Node_Id;
Not_Null_Present : Boolean := False;
begin
Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr);
Scan; -- past SUBTYPE
Set_Defining_Identifier (Decl_Node, P_Defining_Identifier (C_Is));
TF_Is;
if Token = Tok_New then
Error_Msg_SC -- CODEFIX
("NEW ignored (only allowed in type declaration)");
Scan; -- past NEW
end if;
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
Set_Subtype_Indication
(Decl_Node, P_Subtype_Indication (Not_Null_Present));
P_Aspect_Specifications (Decl_Node);
return Decl_Node;
end P_Subtype_Declaration;
-------------------------------
-- 3.2.2 Subtype Indication --
-------------------------------
-- SUBTYPE_INDICATION ::=
-- [not null] SUBTYPE_MARK [CONSTRAINT]
-- Error recovery: can raise Error_Resync
function P_Null_Exclusion
(Allow_Anonymous_In_95 : Boolean := False) return Boolean
is
Not_Loc : constant Source_Ptr := Token_Ptr;
-- Source position of "not", if present
begin
if Token /= Tok_Not then
return False;
else
Scan; -- past NOT
if Token = Tok_Null then
Scan; -- past NULL
-- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
-- except in the case of anonymous access types.
-- Allow_Anonymous_In_95 will be True if we're parsing a formal
-- parameter or discriminant, which are the only places where
-- anonymous access types occur in Ada 95. "Formal : not null
-- access ..." is legal in Ada 95, whereas "Formal : not null
-- Named_Access_Type" is not.
if Ada_Version >= Ada_2005
or else (Ada_Version >= Ada_95
and then Allow_Anonymous_In_95
and then Token = Tok_Access)
then
null; -- OK
else
Error_Msg
("`NOT NULL` access type is an Ada 2005 extension", Not_Loc);
Error_Msg
("\unit should be compiled with -gnat05 switch", Not_Loc);
end if;
else
Error_Msg_SP ("NULL expected");
end if;
if Token = Tok_New then
Error_Msg ("`NOT NULL` comes after NEW, not before", Not_Loc);
end if;
return True;
end if;
end P_Null_Exclusion;
function P_Subtype_Indication
(Not_Null_Present : Boolean := False) return Node_Id
is
Type_Node : Node_Id;
begin
if Token in Tok_Identifier | Tok_Operator_Symbol then
Type_Node := P_Subtype_Mark;
return P_Subtype_Indication (Type_Node, Not_Null_Present);
else
-- Check for error of using record definition and treat it nicely,
-- otherwise things are really messed up, so resynchronize.
if Token = Tok_Record then
Error_Msg_SC ("anonymous record definition not permitted");
Discard_Junk_Node (P_Record_Definition);
return Error;
else
Error_Msg_AP ("subtype indication expected");
raise Error_Resync;
end if;
end if;
end P_Subtype_Indication;
-- The following function is identical except that it is called with
-- the subtype mark already scanned out, and it scans out the constraint
-- Error recovery: can raise Error_Resync
function P_Subtype_Indication
(Subtype_Mark : Node_Id;
Not_Null_Present : Boolean := False) return Node_Id
is
Indic_Node : Node_Id;
Constr_Node : Node_Id;
begin
Constr_Node := P_Constraint_Opt;
if No (Constr_Node)
or else
(Nkind (Constr_Node) = N_Range_Constraint
and then Nkind (Range_Expression (Constr_Node)) = N_Error)
then
return Subtype_Mark;
else
if Not_Null_Present then
Error_Msg_SP ("`NOT NULL` not allowed if constraint given");
end if;
Indic_Node := New_Node (N_Subtype_Indication, Sloc (Subtype_Mark));
Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark));
Set_Constraint (Indic_Node, Constr_Node);
return Indic_Node;
end if;
end P_Subtype_Indication;
-------------------------
-- 3.2.2 Subtype Mark --
-------------------------
-- SUBTYPE_MARK ::= subtype_NAME;
-- Note: The subtype mark which appears after an IN or NOT IN
-- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
-- Error recovery: cannot raise Error_Resync
function P_Subtype_Mark return Node_Id is
begin
return P_Subtype_Mark_Resync;
exception
when Error_Resync =>
return Error;
end P_Subtype_Mark;
-- This routine differs from P_Subtype_Mark in that it insists that an
-- identifier be present, and if it is not, it raises Error_Resync.
-- Error recovery: can raise Error_Resync
function P_Subtype_Mark_Resync return Node_Id is
Type_Node : Node_Id;
begin
if Token = Tok_Access then
Error_Msg_SC ("anonymous access type definition not allowed here");
Scan; -- past ACCESS
end if;
if Token = Tok_Array then
Error_Msg_SC ("anonymous array definition not allowed here");
Discard_Junk_Node (P_Array_Type_Definition);
return Error;
else
Type_Node := P_Qualified_Simple_Name_Resync;
-- Check for a subtype mark attribute. The only valid possibilities
-- are 'CLASS and 'BASE. Anything else is a definite error. We may
-- as well catch it here.
if Token = Tok_Apostrophe then
return P_Subtype_Mark_Attribute (Type_Node);
else
return Type_Node;
end if;
end if;
end P_Subtype_Mark_Resync;
-- The following function is called to scan out a subtype mark attribute.
-- The caller has already scanned out the subtype mark, which is passed in
-- as the argument, and has checked that the current token is apostrophe.
-- Only a special subclass of attributes, called type attributes
-- (see Snames package) are allowed in this syntactic position.
-- Note: if the apostrophe is followed by other than an identifier, then
-- the input expression is returned unchanged, and the scan pointer is
-- left pointing to the apostrophe.
-- Error recovery: can raise Error_Resync
function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id is
Attr_Node : Node_Id := Empty;
Scan_State : Saved_Scan_State;
Prefix : Node_Id;
begin
Prefix := Check_Subtype_Mark (Type_Node);
if Prefix = Error then
raise Error_Resync;
end if;
-- Loop through attributes appearing (more than one can appear as for
-- for example in X'Base'Class). We are at an apostrophe on entry to
-- this loop, and it runs once for each attribute parsed, with
-- Prefix being the current possible prefix if it is an attribute.
loop
Save_Scan_State (Scan_State); -- at Apostrophe
Scan; -- past apostrophe
if Token /= Tok_Identifier then
Restore_Scan_State (Scan_State); -- to apostrophe
return Prefix; -- no attribute after all
elsif not Is_Type_Attribute_Name (Token_Name) then
Error_Msg_N
("attribute & may not be used in a subtype mark", Token_Node);
raise Error_Resync;
else
Attr_Node :=
Make_Attribute_Reference (Prev_Token_Ptr,
Prefix => Prefix,
Attribute_Name => Token_Name);
Scan; -- past type attribute identifier
end if;
exit when Token /= Tok_Apostrophe;
Prefix := Attr_Node;
end loop;
-- Fall through here after scanning type attribute
return Attr_Node;
end P_Subtype_Mark_Attribute;
-----------------------
-- 3.2.2 Constraint --
-----------------------
-- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
-- SCALAR_CONSTRAINT ::=
-- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
-- COMPOSITE_CONSTRAINT ::=
-- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
-- If no constraint is present, this function returns Empty
-- Error recovery: can raise Error_Resync
function P_Constraint_Opt return Node_Id is
begin
if Token = Tok_Range or else Bad_Spelling_Of (Tok_Range) then
return P_Range_Constraint;
elsif Token = Tok_Digits or else Bad_Spelling_Of (Tok_Digits) then
return P_Digits_Constraint;
elsif Token = Tok_Delta or else Bad_Spelling_Of (Tok_Delta) then
return P_Delta_Constraint;
elsif Token = Tok_Left_Paren then
return P_Index_Or_Discriminant_Constraint;
elsif Token = Tok_In then
Ignore (Tok_In);
return P_Constraint_Opt;
-- One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword)
elsif Token = Tok_Identifier or else
Token = Tok_Integer_Literal or else
Token = Tok_Real_Literal
then
declare
Scan_State : Saved_Scan_State;
begin
Save_Scan_State (Scan_State); -- at identifier or literal
Scan; -- past identifier or literal
if Token = Tok_Dot_Dot then
Restore_Scan_State (Scan_State);
Error_Msg_BC ("missing RANGE keyword");
return P_Range_Constraint;
else
Restore_Scan_State (Scan_State);
return Empty;
end if;
end;
-- Nothing worked, no constraint there
else
return Empty;
end if;
end P_Constraint_Opt;
------------------------------
-- 3.2.2 Scalar Constraint --
------------------------------
-- Parsed by P_Constraint_Opt (3.2.2)
---------------------------------
-- 3.2.2 Composite Constraint --
---------------------------------
-- Parsed by P_Constraint_Opt (3.2.2)
--------------------------------------------------------
-- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
--------------------------------------------------------
-- This routine scans out a declaration starting with an identifier:
-- OBJECT_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- ACCESS_DEFINITION [:= EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- ARRAY_TYPE_DEFINITION [:= EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- NUMBER_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
-- OBJECT_RENAMING_DECLARATION ::=
-- DEFINING_IDENTIFIER :
-- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
-- [ASPECT_SPECIFICATIONS];
-- | DEFINING_IDENTIFIER :
-- ACCESS_DEFINITION renames object_NAME
-- [ASPECT_SPECIFICATIONS];
-- EXCEPTION_RENAMING_DECLARATION ::=
-- DEFINING_IDENTIFIER : exception renames exception_NAME
-- [ASPECT_SPECIFICATIONS];
-- EXCEPTION_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : exception
-- [ASPECT_SPECIFICATIONS];
-- Note that the ALIASED indication in an object declaration is
-- marked by a flag in the parent node.
-- The caller has checked that the initial token is an identifier
-- The value returned is a list of declarations, one for each identifier
-- in the list (as described in Sinfo, we always split up multiple
-- declarations into the equivalent sequence of single declarations
-- using the More_Ids and Prev_Ids flags to preserve the source).
-- If the identifier turns out to be a probable statement rather than
-- an identifier, then the scan is left pointing to the identifier and
-- No_List is returned.
-- Error recovery: can raise Error_Resync
procedure P_Identifier_Declarations
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean;
In_Statements : Boolean)
is
Acc_Node : Node_Id;
Decl_Node : Node_Id;
Type_Node : Node_Id;
Ident_Sloc : Source_Ptr;
Scan_State : Saved_Scan_State;
List_OK : Boolean := True;
Ident : Nat;
Init_Expr : Node_Id;
Init_Loc : Source_Ptr;
Con_Loc : Source_Ptr;
Not_Null_Present : Boolean := False;
Idents : array (Int range 1 .. 4096) of Entity_Id;
-- Used to save identifiers in the identifier list. The upper bound
-- of 4096 is expected to be infinite in practice, and we do not even
-- bother to check if this upper bound is exceeded.
Num_Idents : Nat := 1;
-- Number of identifiers stored in Idents
function Identifier_Starts_Statement return Boolean;
-- Called with Token being an identifier that might start a declaration
-- or a statement. True if we are parsing declarations in a sequence of
-- statements, and this identifier is the start of a statement. If this
-- is true, we quit parsing declarations, and return Done = True so the
-- caller will switch to parsing statements.
procedure No_List;
-- This procedure is called in renames cases to make sure that we do
-- not have more than one identifier. If we do have more than one
-- then an error message is issued (and the declaration is split into
-- multiple declarations)
function Token_Is_Renames return Boolean;
-- Checks if current token is RENAMES, and if so, scans past it and
-- returns True, otherwise returns False. Includes checking for some
-- common error cases.
---------------------------------
-- Identifier_Starts_Statement --
---------------------------------
function Identifier_Starts_Statement return Boolean is
pragma Assert (Token = Tok_Identifier);
Scan_State : Saved_Scan_State;
Result : Boolean := False;
begin
if not In_Statements then
return False;
end if;
Save_Scan_State (Scan_State);
Scan;
case Token is
when Tok_Comma => -- "X, ..." is a declaration
null;
when Tok_Colon =>
-- "X : ..." is usually a declaration, but "X : begin..." is
-- not. We return true for things like "X : Y : begin...",
-- which is a syntax error, because that gives better error
-- recovery for some ACATS.
Scan;
if Token in Token_Class_Labeled_Stmt then
Result := True;
elsif Token = Tok_Identifier then
Scan;
if Token = Tok_Colon then
Scan;
if Token in Token_Class_Labeled_Stmt then
Result := True;
end if;
end if;
end if;
when others =>
Result := True;
end case;
Restore_Scan_State (Scan_State);
return Result;
end Identifier_Starts_Statement;
-------------
-- No_List --
-------------
procedure No_List is
begin
if Num_Idents > 1 then
Error_Msg_N
("identifier list not allowed for RENAMES",
Idents (2));
end if;
List_OK := False;
end No_List;
----------------------
-- Token_Is_Renames --
----------------------
function Token_Is_Renames return Boolean is
At_Colon : Saved_Scan_State;
begin
if Token = Tok_Colon then
Save_Scan_State (At_Colon);
Scan; -- past colon
Check_Misspelling_Of (Tok_Renames);
if Token = Tok_Renames then
Error_Msg_SP -- CODEFIX
("|extra "":"" ignored");
Scan; -- past RENAMES
return True;
else
Restore_Scan_State (At_Colon);
return False;
end if;
else
Check_Misspelling_Of (Tok_Renames);
if Token = Tok_Renames then
Scan; -- past RENAMES
return True;
else
return False;
end if;
end if;
end Token_Is_Renames;
-- Start of processing for P_Identifier_Declarations
begin
if Identifier_Starts_Statement then
Done := True;
return;
end if;
Ident_Sloc := Token_Ptr;
Save_Scan_State (Scan_State); -- at first identifier
Idents (1) := P_Defining_Identifier (C_Comma_Colon);
-- If we have a colon after the identifier, then we can assume that
-- this is in fact a valid identifier declaration and can steam ahead.
if Token = Tok_Colon then
Scan; -- past colon
-- If we have a comma, then scan out the list of identifiers
elsif Token = Tok_Comma then
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
end loop;
Save_Scan_State (Scan_State); -- at colon
T_Colon;
-- If we have an identifier followed by := then we assume that what is
-- really meant is an assignment statement. The assignment statement
-- is scanned out and added to the list of declarations. An exception
-- occurs if the := is followed by the keyword constant, in which case
-- we assume it was meant to be a colon.
elsif Token = Tok_Colon_Equal then
Scan; -- past :=
if Token = Tok_Constant then
Error_Msg_SP ("colon expected");
else
Restore_Scan_State (Scan_State);
-- Reset Token_Node, because it already got changed from an
-- Identifier to a Defining_Identifier, and we don't want that
-- for a statement!
Token_Node :=
Make_Identifier (Sloc (Token_Node), Chars (Token_Node));
-- And now scan out one or more statements
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
return;
end if;
-- If we have an IS keyword, then assume the TYPE keyword was missing
elsif Token = Tok_Is then
Restore_Scan_State (Scan_State);
Append_To (Decls, P_Type_Declaration);
Done := False;
return;
-- AI12-0275: Object renaming declaration without subtype_mark or
-- access_definition
elsif Token = Tok_Renames then
Error_Msg_Ada_2022_Feature
("object renaming without subtype", Token_Ptr);
Scan; -- past renames
Decl_Node :=
New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
Set_Name (Decl_Node, P_Name);
Set_Defining_Identifier (Decl_Node, Idents (1));
P_Aspect_Specifications (Decl_Node, Semicolon => False);
T_Semicolon;
Append (Decl_Node, Decls);
Done := False;
return;
-- Otherwise we have an error situation
else
Restore_Scan_State (Scan_State);
-- First case is possible misuse of PROTECTED in Ada 83 mode. If
-- so, fix the keyword and return to scan the protected declaration.
if Token_Name = Name_Protected then
Check_95_Keyword (Tok_Protected, Tok_Identifier);
Check_95_Keyword (Tok_Protected, Tok_Type);
Check_95_Keyword (Tok_Protected, Tok_Body);
if Token = Tok_Protected then
Done := False;
return;
end if;
-- Check misspelling possibilities. If so, correct the misspelling
-- and return to scan out the resulting declaration.
elsif Bad_Spelling_Of (Tok_Function)
or else Bad_Spelling_Of (Tok_Procedure)
or else Bad_Spelling_Of (Tok_Package)
or else Bad_Spelling_Of (Tok_Pragma)
or else Bad_Spelling_Of (Tok_Protected)
or else Bad_Spelling_Of (Tok_Generic)
or else Bad_Spelling_Of (Tok_Subtype)
or else Bad_Spelling_Of (Tok_Type)
or else Bad_Spelling_Of (Tok_Task)
or else Bad_Spelling_Of (Tok_Use)
or else Bad_Spelling_Of (Tok_For)
then
Done := False;
return;
-- Otherwise we definitely have an ordinary identifier with a junk
-- token after it.
elsif In_Statements then
Done := True;
return;
else
-- If in -gnatd.2 mode, try for statements
if Debug_Flag_Dot_2 then
Restore_Scan_State (Scan_State);
-- Reset Token_Node, because it already got changed from an
-- Identifier to a Defining_Identifier, and we don't want that
-- for a statement!
Token_Node :=
Make_Identifier (Sloc (Token_Node), Chars (Token_Node));
-- And now scan out one or more statements
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
return;
-- Normal case, just complain and skip to semicolon
else
Set_Declaration_Expected;
Resync_Past_Semicolon;
Done := False;
return;
end if;
end if;
end if;
-- Come here with an identifier list and colon scanned out. We now
-- build the nodes for the declarative items. One node is built for
-- each identifier in the list, with the type information being
-- repeated by rescanning the appropriate section of source.
-- First an error check, if we have two identifiers in a row, a likely
-- possibility is that the first of the identifiers is an incorrectly
-- spelled keyword.
if Token = Tok_Identifier then
declare
SS : Saved_Scan_State;
I2 : Boolean;
begin
Save_Scan_State (SS);
Scan; -- past initial identifier
I2 := (Token = Tok_Identifier);
Restore_Scan_State (SS);
if I2
and then
(Bad_Spelling_Of (Tok_Access) or else
Bad_Spelling_Of (Tok_Aliased) or else
Bad_Spelling_Of (Tok_Constant))
then
null;
end if;
end;
end if;
-- Loop through identifiers
Ident := 1;
Ident_Loop : loop
-- Check for some cases of misused Ada 95 keywords
if Token_Name = Name_Aliased then
Check_95_Keyword (Tok_Aliased, Tok_Array);
Check_95_Keyword (Tok_Aliased, Tok_Identifier);
Check_95_Keyword (Tok_Aliased, Tok_Constant);
end if;
-- Constant cases
if Token = Tok_Constant then
Con_Loc := Token_Ptr;
Scan; -- past CONSTANT
-- Number declaration, initialization required
Init_Expr := Init_Expr_Opt;
if Present (Init_Expr) then
if Not_Null_Present then
Error_Msg_SP
("`NOT NULL` not allowed in numeric expression");
end if;
Decl_Node := New_Node (N_Number_Declaration, Ident_Sloc);
Set_Expression (Decl_Node, Init_Expr);
-- Constant object declaration
else
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Constant_Present (Decl_Node, True);
if Token_Name = Name_Aliased then
Check_95_Keyword (Tok_Aliased, Tok_Array);
Check_95_Keyword (Tok_Aliased, Tok_Identifier);
end if;
if Token = Tok_Aliased then
Error_Msg_SC -- CODEFIX
("ALIASED should be before CONSTANT");
Scan; -- past ALIASED
Set_Aliased_Present (Decl_Node, True);
end if;
if Token = Tok_Array then
Set_Object_Definition
(Decl_Node, P_Array_Type_Definition);
else
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
Set_Object_Definition
(Decl_Node, P_Access_Definition (Not_Null_Present));
else
Set_Object_Definition
(Decl_Node, P_Subtype_Indication (Not_Null_Present));
end if;
end if;
if Token = Tok_Renames then
Error_Msg
("CONSTANT not permitted in renaming declaration",
Con_Loc);
Scan; -- Past renames
Discard_Junk_Node (P_Name);
end if;
end if;
-- Exception cases
elsif Token = Tok_Exception then
Scan; -- past EXCEPTION
if Token_Is_Renames then
No_List;
Decl_Node :=
New_Node (N_Exception_Renaming_Declaration, Ident_Sloc);
Set_Name (Decl_Node, P_Qualified_Simple_Name_Resync);
No_Constraint;
else
Decl_Node := New_Node (N_Exception_Declaration, Prev_Token_Ptr);
end if;
-- Aliased case (note that an object definition is required)
elsif Token = Tok_Aliased then
Scan; -- past ALIASED
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Aliased_Present (Decl_Node, True);
if Token = Tok_Constant then
Scan; -- past CONSTANT
Set_Constant_Present (Decl_Node, True);
end if;
if Token = Tok_Array then
Set_Object_Definition
(Decl_Node, P_Array_Type_Definition);
else
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
-- Access definition (AI-406) or subtype indication
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
Set_Object_Definition
(Decl_Node, P_Access_Definition (Not_Null_Present));
else
Set_Object_Definition
(Decl_Node, P_Subtype_Indication (Not_Null_Present));
end if;
end if;
-- Array case
elsif Token = Tok_Array then
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Object_Definition (Decl_Node, P_Array_Type_Definition);
-- Ada 2005 (AI-254, AI-406)
elsif Token = Tok_Not then
-- OBJECT_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- ACCESS_DEFINITION [:= EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- OBJECT_RENAMING_DECLARATION ::=
-- DEFINING_IDENTIFIER :
-- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
-- [ASPECT_SPECIFICATIONS];
-- | DEFINING_IDENTIFIER :
-- ACCESS_DEFINITION renames object_NAME
-- [ASPECT_SPECIFICATIONS];
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/423)
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
Acc_Node := P_Access_Definition (Not_Null_Present);
if Token /= Tok_Renames then
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Object_Definition (Decl_Node, Acc_Node);
else
Scan; -- past renames
No_List;
Decl_Node :=
New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
Set_Access_Definition (Decl_Node, Acc_Node);
Set_Name (Decl_Node, P_Name);
end if;
else
Type_Node := P_Subtype_Mark;
-- Object renaming declaration
if Token_Is_Renames then
if Ada_Version < Ada_2005 then
Error_Msg_SP
("`NOT NULL` not allowed in object renaming");
raise Error_Resync;
-- Ada 2005 (AI-423): Object renaming declaration with
-- a null exclusion.
else
No_List;
Decl_Node :=
New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
Set_Subtype_Mark (Decl_Node, Type_Node);
Set_Name (Decl_Node, P_Name);
end if;
-- Object declaration
else
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
Set_Object_Definition
(Decl_Node,
P_Subtype_Indication (Type_Node, Not_Null_Present));
-- RENAMES at this point means that we had the combination
-- of a constraint on the Type_Node and renames, which is
-- illegal
if Token_Is_Renames then
Error_Msg_N
("constraint not allowed in object renaming "
& "declaration",
Constraint (Object_Definition (Decl_Node)));
raise Error_Resync;
end if;
end if;
end if;
-- Ada 2005 (AI-230): Access Definition case
elsif Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
Acc_Node := P_Access_Definition (Null_Exclusion_Present => False);
-- Object declaration with access definition, or renaming
if Token /= Tok_Renames then
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Object_Definition (Decl_Node, Acc_Node);
else
Scan; -- past renames
No_List;
Decl_Node :=
New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
Set_Access_Definition (Decl_Node, Acc_Node);
Set_Name (Decl_Node, P_Name);
end if;
-- Subtype indication case
else
Type_Node := P_Subtype_Mark;
-- Object renaming declaration
if Token_Is_Renames then
No_List;
Decl_Node :=
New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
Set_Subtype_Mark (Decl_Node, Type_Node);
Set_Name (Decl_Node, P_Name);
-- Object declaration
else
Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
Set_Object_Definition
(Decl_Node,
P_Subtype_Indication (Type_Node, Not_Null_Present));
-- RENAMES at this point means that we had the combination of
-- a constraint on the Type_Node and renames, which is illegal
if Token_Is_Renames then
Error_Msg_N
("constraint not allowed in object renaming declaration",
Constraint (Object_Definition (Decl_Node)));
raise Error_Resync;
end if;
end if;
end if;
-- Scan out initialization, allowed only for object declaration
Init_Loc := Token_Ptr;
Init_Expr := Init_Expr_Opt;
if Present (Init_Expr) then
if Nkind (Decl_Node) = N_Object_Declaration then
Set_Expression (Decl_Node, Init_Expr);
Set_Has_Init_Expression (Decl_Node);
else
Error_Msg ("initialization not allowed here", Init_Loc);
end if;
end if;
Set_Defining_Identifier (Decl_Node, Idents (Ident));
P_Aspect_Specifications (Decl_Node, Semicolon => False);
-- Allow initialization expression to follow aspects (note that in
-- this case P_Aspect_Specifications already issued an error msg).
if Token = Tok_Colon_Equal then
if Is_Non_Empty_List (Aspect_Specifications (Decl_Node)) then
Error_Msg
("aspect specifications must come after initialization "
& "expression",
Sloc (First (Aspect_Specifications (Decl_Node))));
else
-- In any case, the assignment symbol doesn't belong.
Error_Msg ("misplaced assignment symbol", Scan_Ptr);
end if;
Set_Expression (Decl_Node, Init_Expr_Opt);
Set_Has_Init_Expression (Decl_Node);
end if;
-- Now scan out the semicolon, which we deferred above
T_Semicolon;
if List_OK then
if Ident < Num_Idents then
Set_More_Ids (Decl_Node, True);
end if;
if Ident > 1 then
Set_Prev_Ids (Decl_Node, True);
end if;
end if;
Append (Decl_Node, Decls);
exit Ident_Loop when Ident = Num_Idents;
Restore_Scan_State (Scan_State);
T_Colon;
Ident := Ident + 1;
end loop Ident_Loop;
Done := False;
end P_Identifier_Declarations;
-------------------------------
-- 3.3.1 Object Declaration --
-------------------------------
-- OBJECT DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- SUBTYPE_INDICATION [:= EXPRESSION];
-- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
-- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
-- | SINGLE_TASK_DECLARATION
-- | SINGLE_PROTECTED_DECLARATION
-- Cases starting with TASK are parsed by P_Task (9.1)
-- Cases starting with PROTECTED are parsed by P_Protected (9.4)
-- All other cases are parsed by P_Identifier_Declarations (3.3)
-------------------------------------
-- 3.3.1 Defining Identifier List --
-------------------------------------
-- DEFINING_IDENTIFIER_LIST ::=
-- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
-- Always parsed by the construct in which it appears. See special
-- section on "Handling of Defining Identifier Lists" in this unit.
-------------------------------
-- 3.3.2 Number Declaration --
-------------------------------
-- Parsed by P_Identifier_Declarations (3.3)
-------------------------------------------------------------------------
-- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
-------------------------------------------------------------------------
-- DERIVED_TYPE_DEFINITION ::=
-- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
-- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
-- PRIVATE_EXTENSION_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
-- [abstract] [limited | synchronized]
-- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
-- with private [ASPECT_SPECIFICATIONS];
-- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
-- The caller has already scanned out the part up to the NEW, and Token
-- either contains Tok_New (or ought to, if it doesn't this procedure
-- will post an appropriate "NEW expected" message).
-- Note: the caller is responsible for filling in the Sloc field of
-- the returned node in the private extension declaration case as
-- well as the stuff relating to the discriminant part.
-- Error recovery: can raise Error_Resync;
function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id is
Typedef_Node : Node_Id;
Typedecl_Node : Node_Id;
Not_Null_Present : Boolean := False;
begin
Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
if Ada_Version < Ada_2005
and then Token = Tok_Identifier
and then Token_Name = Name_Interface
then
Error_Msg_SP
("abstract interface is an Ada 2005 extension");
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
else
T_New;
end if;
if Token = Tok_Abstract then
Error_Msg_SC -- CODEFIX
("ABSTRACT must come before NEW, not after");
Scan;
end if;
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
Set_Null_Exclusion_Present (Typedef_Node, Not_Null_Present);
Set_Subtype_Indication (Typedef_Node,
P_Subtype_Indication (Not_Null_Present));
-- Ada 2005 (AI-251): Deal with interfaces
if Token = Tok_And then
Scan; -- past AND
Error_Msg_Ada_2005_Extension ("abstract interface");
Set_Interface_List (Typedef_Node, New_List);
loop
Append (P_Qualified_Simple_Name, Interface_List (Typedef_Node));
exit when Token /= Tok_And;
Scan; -- past AND
end loop;
if Token /= Tok_With then
Error_Msg_SC ("WITH expected");
raise Error_Resync;
end if;
end if;
-- Deal with record extension, note that we assume that a WITH is
-- missing in the case of "type X is new Y record ..." or in the
-- case of "type X is new Y null record".
-- First make sure we don't have an aspect specification. If we do
-- return now, so that our caller can check it (the WITH here is not
-- part of a type extension).
if Aspect_Specifications_Present then
return Typedef_Node;
-- OK, not an aspect specification, so continue test for extension
elsif Token in Tok_With | Tok_Record | Tok_Null then
T_With; -- past WITH or give error message
if Token = Tok_Limited then
Error_Msg_SC ("LIMITED keyword not allowed in private extension");
Scan; -- ignore LIMITED
end if;
-- Private extension declaration
if Token = Tok_Private then
Scan; -- past PRIVATE
-- Throw away the type definition node and build the type
-- declaration node. Note the caller must set the Sloc,
-- Discriminant_Specifications, Unknown_Discriminants_Present,
-- and Defined_Identifier fields in the returned node.
Typedecl_Node :=
Make_Private_Extension_Declaration (No_Location,
Defining_Identifier => Empty,
Subtype_Indication => Subtype_Indication (Typedef_Node),
Abstract_Present => Abstract_Present (Typedef_Node),
Interface_List => Interface_List (Typedef_Node));
return Typedecl_Node;
-- Derived type definition with record extension part
else
Set_Record_Extension_Part (Typedef_Node, P_Record_Definition);
return Typedef_Node;
end if;
-- Derived type definition with no record extension part
else
return Typedef_Node;
end if;
end P_Derived_Type_Def_Or_Private_Ext_Decl;
---------------------------
-- 3.5 Range Constraint --
---------------------------
-- RANGE_CONSTRAINT ::= range RANGE
-- The caller has checked that the initial token is RANGE or some
-- misspelling of it, or it may be absent completely (and a message
-- has already been issued).
-- Error recovery: cannot raise Error_Resync
function P_Range_Constraint return Node_Id is
Range_Node : Node_Id;
begin
Range_Node := New_Node (N_Range_Constraint, Token_Ptr);
-- Skip range keyword if present
if Token = Tok_Range or else Bad_Spelling_Of (Tok_Range) then
Scan; -- past RANGE
end if;
Set_Range_Expression (Range_Node, P_Range);
return Range_Node;
end P_Range_Constraint;
----------------
-- 3.5 Range --
----------------
-- RANGE ::=
-- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
-- Note: the range that appears in a membership test is parsed by
-- P_Range_Or_Subtype_Mark (3.5).
-- Error recovery: cannot raise Error_Resync
function P_Range return Node_Id is
Expr_Node : Node_Id;
Range_Node : Node_Id;
begin
Expr_Node := P_Simple_Expression_Or_Range_Attribute;
if Expr_Form = EF_Range_Attr then
return Expr_Node;
elsif Token = Tok_Dot_Dot then
Range_Node := New_Node (N_Range, Token_Ptr);
Set_Low_Bound (Range_Node, Expr_Node);
Scan; -- past ..
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Range_Node, Expr_Node);
return Range_Node;
-- Anything else is an error
else
T_Dot_Dot; -- force missing .. message
return Error;
end if;
end P_Range;
----------------------------------
-- 3.5 P_Range_Or_Subtype_Mark --
----------------------------------
-- RANGE ::=
-- RANGE_ATTRIBUTE_REFERENCE
-- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
-- This routine scans out the range or subtype mark that forms the right
-- operand of a membership test (it is not used in any other contexts, and
-- error messages are specialized with this knowledge in mind).
-- Note: as documented in the Sinfo interface, although the syntax only
-- allows a subtype mark, we in fact allow any simple expression to be
-- returned from this routine. The semantics is responsible for issuing
-- an appropriate message complaining if the argument is not a name.
-- This simplifies the coding and error recovery processing in the
-- parser, and in any case it is preferable not to consider this a
-- syntax error and to continue with the semantic analysis.
-- Error recovery: cannot raise Error_Resync
function P_Range_Or_Subtype_Mark
(Allow_Simple_Expression : Boolean := False) return Node_Id
is
Expr_Node : Node_Id;
Range_Node : Node_Id;
Save_Loc : Source_Ptr;
-- Start of processing for P_Range_Or_Subtype_Mark
begin
-- Save location of possible junk parentheses
Save_Loc := Token_Ptr;
-- Scan out either a simple expression or a range (this accepts more
-- than is legal here, but as explained above, we like to allow more
-- with a proper diagnostic, and in the case of a membership operation
-- where sets are allowed, a simple expression is permissible anyway.
Expr_Node := P_Simple_Expression_Or_Range_Attribute;
-- Range attribute
if Expr_Form = EF_Range_Attr then
return Expr_Node;
-- Simple_Expression .. Simple_Expression
elsif Token = Tok_Dot_Dot then
Check_Simple_Expression (Expr_Node);
Range_Node := New_Node (N_Range, Token_Ptr);
Set_Low_Bound (Range_Node, Expr_Node);
Scan; -- past ..
Set_High_Bound (Range_Node, P_Simple_Expression);
return Range_Node;
-- Case of subtype mark (optionally qualified simple name or an
-- attribute whose prefix is an optionally qualified simple name)
elsif Expr_Form = EF_Simple_Name
or else Nkind (Expr_Node) = N_Attribute_Reference
then
-- Check for error of range constraint after a subtype mark
if Token = Tok_Range then
Error_Msg_SC ("range constraint not allowed in membership test");
Scan; -- past RANGE
raise Error_Resync;
-- Check for error of DIGITS or DELTA after a subtype mark
elsif Token in Tok_Digits | Tok_Delta then
Error_Msg_SC
("accuracy definition not allowed in membership test");
Scan; -- past DIGITS or DELTA
raise Error_Resync;
-- Attribute reference, may or may not be OK, but in any case we
-- will scan it out
elsif Token = Tok_Apostrophe then
return P_Subtype_Mark_Attribute (Expr_Node);
-- OK case of simple name, just return it
else
return Expr_Node;
end if;
-- Simple expression case
elsif Expr_Form = EF_Simple and then Allow_Simple_Expression then
return Expr_Node;
-- Here we have some kind of error situation. Check for junk parens
-- then return what we have, caller will deal with other errors.
else
if Nkind (Expr_Node) in N_Subexpr
and then Paren_Count (Expr_Node) /= 0
then
Error_Msg ("|parentheses not allowed for subtype mark", Save_Loc);
Set_Paren_Count (Expr_Node, 0);
end if;
return Expr_Node;
end if;
end P_Range_Or_Subtype_Mark;
----------------------------------------
-- 3.5.1 Enumeration Type Definition --
----------------------------------------
-- ENUMERATION_TYPE_DEFINITION ::=
-- (ENUMERATION_LITERAL_SPECIFICATION
-- {, ENUMERATION_LITERAL_SPECIFICATION})
-- The caller has already scanned out the TYPE keyword
-- Error recovery: can raise Error_Resync;
function P_Enumeration_Type_Definition return Node_Id is
Typedef_Node : Node_Id;
begin
Typedef_Node := New_Node (N_Enumeration_Type_Definition, Token_Ptr);
Set_Literals (Typedef_Node, New_List);
T_Left_Paren;
loop
Append (P_Enumeration_Literal_Specification, Literals (Typedef_Node));
exit when not Comma_Present;
end loop;
T_Right_Paren;
return Typedef_Node;
end P_Enumeration_Type_Definition;
----------------------------------------------
-- 3.5.1 Enumeration Literal Specification --
----------------------------------------------
-- ENUMERATION_LITERAL_SPECIFICATION ::=
-- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
-- Error recovery: can raise Error_Resync
function P_Enumeration_Literal_Specification return Node_Id is
begin
if Token = Tok_Char_Literal then
return P_Defining_Character_Literal;
else
return P_Defining_Identifier (C_Comma_Right_Paren);
end if;
end P_Enumeration_Literal_Specification;
---------------------------------------
-- 3.5.1 Defining_Character_Literal --
---------------------------------------
-- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
-- Error recovery: cannot raise Error_Resync
-- The caller has checked that the current token is a character literal
function P_Defining_Character_Literal return Node_Id is
Literal_Node : Node_Id;
begin
Literal_Node := Token_Node;
Change_Character_Literal_To_Defining_Character_Literal (Literal_Node);
Scan; -- past character literal
return Literal_Node;
end P_Defining_Character_Literal;
------------------------------------
-- 3.5.4 Integer Type Definition --
------------------------------------
-- Parsed by P_Type_Declaration (3.2.1)
-------------------------------------------
-- 3.5.4 Signed Integer Type Definition --
-------------------------------------------
-- SIGNED_INTEGER_TYPE_DEFINITION ::=
-- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
-- Normally the initial token on entry is RANGE, but in some
-- error conditions, the range token was missing and control is
-- passed with Token pointing to first token of the first expression.
-- Error recovery: cannot raise Error_Resync
function P_Signed_Integer_Type_Definition return Node_Id is
Typedef_Node : Node_Id;
Expr_Node : Node_Id;
begin
Typedef_Node := New_Node (N_Signed_Integer_Type_Definition, Token_Ptr);
if Token = Tok_Range then
Scan; -- past RANGE
end if;
Expr_Node := P_Expression_Or_Range_Attribute;
-- Range case (not permitted by the grammar, this is surprising but
-- the grammar in the RM is as quoted above, and does not allow Range).
if Expr_Form = EF_Range_Attr then
Error_Msg_N
("Range attribute not allowed here, use First .. Last", Expr_Node);
Set_Low_Bound (Typedef_Node, Expr_Node);
Set_Attribute_Name (Expr_Node, Name_First);
Set_High_Bound (Typedef_Node, Copy_Separate_Tree (Expr_Node));
Set_Attribute_Name (High_Bound (Typedef_Node), Name_Last);
-- Normal case of explicit range
else
Check_Simple_Expression (Expr_Node);
Set_Low_Bound (Typedef_Node, Expr_Node);
T_Dot_Dot;
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Typedef_Node, Expr_Node);
end if;
return Typedef_Node;
end P_Signed_Integer_Type_Definition;
------------------------------------
-- 3.5.4 Modular Type Definition --
------------------------------------
-- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
-- The caller has checked that the initial token is MOD
-- Error recovery: cannot raise Error_Resync
function P_Modular_Type_Definition return Node_Id is
Typedef_Node : Node_Id;
begin
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) modular types not allowed");
end if;
Typedef_Node := New_Node (N_Modular_Type_Definition, Token_Ptr);
Scan; -- past MOD
Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
-- Handle mod L..R cleanly
if Token = Tok_Dot_Dot then
Error_Msg_SC ("range not allowed for modular type");
Scan; -- past ..
Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
end if;
return Typedef_Node;
end P_Modular_Type_Definition;
---------------------------------
-- 3.5.6 Real Type Definition --
---------------------------------
-- Parsed by P_Type_Declaration (3.2.1)
--------------------------------------
-- 3.5.7 Floating Point Definition --
--------------------------------------
-- FLOATING_POINT_DEFINITION ::=
-- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
-- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
-- The caller has checked that the initial token is DIGITS
-- Error recovery: cannot raise Error_Resync
function P_Floating_Point_Definition return Node_Id is
Digits_Loc : constant Source_Ptr := Token_Ptr;
Def_Node : Node_Id;
Expr_Node : Node_Id;
begin
Scan; -- past DIGITS
Expr_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression_In_Ada_83 (Expr_Node);
-- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
if Token = Tok_Delta then
Error_Msg_SC -- CODEFIX
("|DELTA must come before DIGITS");
Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Digits_Loc);
Scan; -- past DELTA
Set_Delta_Expression (Def_Node, P_Expression_No_Right_Paren);
-- OK floating-point definition
else
Def_Node := New_Node (N_Floating_Point_Definition, Digits_Loc);
end if;
Set_Digits_Expression (Def_Node, Expr_Node);
Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
return Def_Node;
end P_Floating_Point_Definition;
-------------------------------------
-- 3.5.7 Real Range Specification --
-------------------------------------
-- REAL_RANGE_SPECIFICATION ::=
-- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
-- Error recovery: cannot raise Error_Resync
function P_Real_Range_Specification_Opt return Node_Id is
Specification_Node : Node_Id;
Expr_Node : Node_Id;
begin
if Token = Tok_Range then
Specification_Node :=
New_Node (N_Real_Range_Specification, Token_Ptr);
Scan; -- past RANGE
Expr_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression (Expr_Node);
Set_Low_Bound (Specification_Node, Expr_Node);
T_Dot_Dot;
Expr_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Specification_Node, Expr_Node);
return Specification_Node;
else
return Empty;
end if;
end P_Real_Range_Specification_Opt;
-----------------------------------
-- 3.5.9 Fixed Point Definition --
-----------------------------------
-- FIXED_POINT_DEFINITION ::=
-- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
-- ORDINARY_FIXED_POINT_DEFINITION ::=
-- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
-- DECIMAL_FIXED_POINT_DEFINITION ::=
-- delta static_EXPRESSION
-- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
-- The caller has checked that the initial token is DELTA
-- Error recovery: cannot raise Error_Resync
function P_Fixed_Point_Definition return Node_Id is
Delta_Node : Node_Id;
Delta_Loc : Source_Ptr;
Def_Node : Node_Id;
Expr_Node : Node_Id;
begin
Delta_Loc := Token_Ptr;
Scan; -- past DELTA
Delta_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression_In_Ada_83 (Delta_Node);
if Token = Tok_Digits then
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) decimal fixed type not allowed!");
end if;
Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Delta_Loc);
Scan; -- past DIGITS
Expr_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression_In_Ada_83 (Expr_Node);
Set_Digits_Expression (Def_Node, Expr_Node);
else
Def_Node := New_Node (N_Ordinary_Fixed_Point_Definition, Delta_Loc);
-- Range is required in ordinary fixed point case
if Token /= Tok_Range then
Error_Msg_AP ("range must be given for fixed-point type");
T_Range;
end if;
end if;
Set_Delta_Expression (Def_Node, Delta_Node);
Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
return Def_Node;
end P_Fixed_Point_Definition;
--------------------------------------------
-- 3.5.9 Ordinary Fixed Point Definition --
--------------------------------------------
-- Parsed by P_Fixed_Point_Definition (3.5.9)
-------------------------------------------
-- 3.5.9 Decimal Fixed Point Definition --
-------------------------------------------
-- Parsed by P_Decimal_Point_Definition (3.5.9)
------------------------------
-- 3.5.9 Digits Constraint --
------------------------------
-- DIGITS_CONSTRAINT ::=
-- digits static_EXPRESSION [RANGE_CONSTRAINT]
-- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
-- The caller has checked that the initial token is DIGITS
function P_Digits_Constraint return Node_Id is
Constraint_Node : Node_Id;
Expr_Node : Node_Id;
begin
Constraint_Node := New_Node (N_Digits_Constraint, Token_Ptr);
Scan; -- past DIGITS
Expr_Node := P_Expression;
Check_Simple_Expression_In_Ada_83 (Expr_Node);
Set_Digits_Expression (Constraint_Node, Expr_Node);
if Token = Tok_Range then
Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
end if;
return Constraint_Node;
end P_Digits_Constraint;
-----------------------------
-- 3.5.9 Delta Constraint --
-----------------------------
-- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
-- Note: this is an obsolescent feature in Ada 95 (I.3)
-- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
-- (also true in formal modes).
-- The caller has checked that the initial token is DELTA
-- Error recovery: cannot raise Error_Resync
function P_Delta_Constraint return Node_Id is
Constraint_Node : Node_Id;
Expr_Node : Node_Id;
begin
Constraint_Node := New_Node (N_Delta_Constraint, Token_Ptr);
Scan; -- past DELTA
Expr_Node := P_Expression;
Check_Simple_Expression_In_Ada_83 (Expr_Node);
Set_Delta_Expression (Constraint_Node, Expr_Node);
if Token = Tok_Range then
Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
end if;
return Constraint_Node;
end P_Delta_Constraint;
--------------------------------
-- 3.6 Array Type Definition --
--------------------------------
-- ARRAY_TYPE_DEFINITION ::=
-- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
-- UNCONSTRAINED_ARRAY_DEFINITION ::=
-- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
-- COMPONENT_DEFINITION
-- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
-- CONSTRAINED_ARRAY_DEFINITION ::=
-- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
-- COMPONENT_DEFINITION
-- DISCRETE_SUBTYPE_DEFINITION ::=
-- DISCRETE_SUBTYPE_INDICATION | RANGE
-- COMPONENT_DEFINITION ::=
-- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
-- The caller has checked that the initial token is ARRAY
-- Error recovery: can raise Error_Resync
function P_Array_Type_Definition return Node_Id is
Array_Loc : Source_Ptr;
CompDef_Node : Node_Id;
Def_Node : Node_Id;
Not_Null_Present : Boolean := False;
Subs_List : List_Id;
Scan_State : Saved_Scan_State;
Aliased_Present : Boolean := False;
procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark : Node_Id);
-- Parse an unconstrained index range with a fixed lower bound:
-- subtype_mark range <expression> .. <>
-- This procedure creates a subtype_indication node for the index.
--------------------------------------------
-- P_Index_Range_With_Fixed_Lower_Bound --
--------------------------------------------
procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark : Node_Id)
is
Low_Expr_Node : constant Node_Id := P_Expression;
High_Expr_Node : Node_Id;
Indic_Node : Node_Id;
Constr_Node : Node_Id;
Range_Node : Node_Id;
begin
T_Dot_Dot; -- Error if no ..
-- A box is required at this point, and we'll set the upper bound to
-- the same expression as the lower bound (see further below), to
-- avoid problems with trying to analyze an Empty node. Analysis can
-- still tell that this is a fixed-lower-bound range because the
-- index is represented by a subtype_indication in an unconstrained
-- array type definition.
if Token = Tok_Box then
Scan;
High_Expr_Node := Low_Expr_Node;
-- Error if no <> was found, and try to parse an expression since
-- it's likely one was given in place of the <>.
else
Error_Msg_AP -- CODEFIX
("missing ""'<'>""");
High_Expr_Node := P_Expression;
end if;
Constr_Node := New_Node (N_Range_Constraint, Token_Ptr);
Range_Node := New_Node (N_Range, Token_Ptr);
Set_Range_Expression (Constr_Node, Range_Node);
Check_Simple_Expression (Low_Expr_Node);
Set_Low_Bound (Range_Node, Low_Expr_Node);
Set_High_Bound (Range_Node, High_Expr_Node);
Indic_Node :=
New_Node (N_Subtype_Indication, Sloc (Subtype_Mark));
Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark));
Set_Constraint (Indic_Node, Constr_Node);
Append (Indic_Node, Subs_List);
end P_Index_Subtype_Def_With_Fixed_Lower_Bound;
-- Local variables
Is_Constrained_Array_Def : Boolean := True;
Subtype_Mark_Node : Node_Id;
-- Start of processing for P_Array_Type_Definition
begin
Array_Loc := Token_Ptr;
Scan; -- past ARRAY
Subs_List := New_List;
T_Left_Paren;
-- It's quite tricky to disentangle these two possibilities, so we do
-- a prescan to determine which case we have and then reset the scan.
-- The prescan skips past possible subtype mark tokens.
Save_Scan_State (Scan_State); -- just after paren
while Token in Token_Class_Desig or else
Token = Tok_Dot or else
Token = Tok_Apostrophe -- because of 'BASE, 'CLASS
loop
Scan;
end loop;
-- If we end up on RANGE <> then we have the unconstrained case. We
-- will also allow the RANGE to be omitted, just to improve error
-- handling for a case like array (integer <>) of integer;
Scan; -- past possible RANGE or <>
if (Prev_Token = Tok_Range and then Token = Tok_Box) or else
Prev_Token = Tok_Box
then
Def_Node := New_Node (N_Unconstrained_Array_Definition, Array_Loc);
Restore_Scan_State (Scan_State); -- to first subtype mark
Is_Constrained_Array_Def := False;
-- Now parse a sequence of indexes where each is either of form:
-- <subtype_mark> range <>
-- or
-- <subtype_mark> range <expr> .. <>
--
-- The latter syntax indicates an index with a fixed lower bound,
-- and only applies when extensions are enabled (-gnatX).
loop
Subtype_Mark_Node := P_Subtype_Mark_Resync;
T_Range;
-- Normal "subtype_mark range <>" form, so simply append
-- the subtype reference.
if Token = Tok_Box then
Append (Subtype_Mark_Node, Subs_List);
Scan;
-- Fixed-lower-bound form ("subtype_mark range <expr> .. <>")
else
P_Index_Subtype_Def_With_Fixed_Lower_Bound (Subtype_Mark_Node);
Error_Msg_GNAT_Extension ("fixed-lower-bound array", Token_Ptr,
Is_Core_Extension => True);
end if;
exit when Token in Tok_Right_Paren | Tok_Of;
T_Comma;
end loop;
Set_Subtype_Marks (Def_Node, Subs_List);
-- If we don't have "range <>", then "range" will be followed by an
-- expression, for either a normal range or a fixed-lower-bound range
-- ("<exp> .. <>"), and we have to know which, in order to determine
-- whether to parse the indexes for an unconstrained or constrained
-- array definition. So we look ahead to see if "<>" follows the "..".
-- If not, then this must be a discrete_subtype_indication for a
-- constrained_array_definition, which will be processed further below.
elsif Prev_Token = Tok_Range
and then Token not in Tok_Right_Paren | Tok_Comma
then
-- If we have an expression followed by "..", then scan farther
-- and check for "<>" to see if we have a fixed-lower-bound range.
if P_Expression_Or_Range_Attribute /= Error
and then Expr_Form /= EF_Range_Attr
and then Token = Tok_Dot_Dot
then
Scan;
-- If there's a "<>", then we know we have a fixed-lower-bound
-- index, so we can proceed with parsing an unconstrained array
-- definition.
if Token = Tok_Box then
Is_Constrained_Array_Def := False;
Def_Node :=
New_Node (N_Unconstrained_Array_Definition, Array_Loc);
Restore_Scan_State (Scan_State); -- to first subtype mark
-- Now parse a sequence of indexes where each is either of
-- form:
-- <subtype_mark> range <>
-- or
-- <subtype_mark> range <expr> .. <>
--
-- The latter indicates an index with a fixed lower bound,
-- and only applies when extensions are enabled (-gnatX).
loop
Subtype_Mark_Node := P_Subtype_Mark_Resync;
T_Range;
-- Normal "subtype_mark range <>" form, so simply append
-- the subtype reference.
if Token = Tok_Box then
Append (Subtype_Mark_Node, Subs_List);
Scan;
-- This must be an index of form:
-- <subtype_mark> range <expr> .. <>"
else
P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark_Node);
Error_Msg_GNAT_Extension
("fixed-lower-bound array", Token_Ptr,
Is_Core_Extension => True);
end if;
exit when Token in Tok_Right_Paren | Tok_Of;
T_Comma;
end loop;
Set_Subtype_Marks (Def_Node, Subs_List);
end if;
end if;
end if;
if Is_Constrained_Array_Def then
Def_Node := New_Node (N_Constrained_Array_Definition, Array_Loc);
Restore_Scan_State (Scan_State); -- to first discrete range
loop
Append (P_Discrete_Subtype_Definition, Subs_List);
exit when not Comma_Present;
end loop;
Set_Discrete_Subtype_Definitions (Def_Node, Subs_List);
end if;
T_Right_Paren;
T_Of;
CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
if Token_Name = Name_Aliased then
Check_95_Keyword (Tok_Aliased, Tok_Identifier);
end if;
if Token = Tok_Aliased then
Aliased_Present := True;
Scan; -- past ALIASED
end if;
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
-- Ada 2005 (AI-230): Access Definition case
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
-- AI95-406 makes "aliased" legal (and useless) in this context so
-- followintg code which used to be needed is commented out.
-- if Aliased_Present then
-- Error_Msg_SP ("ALIASED not allowed here");
-- end if;
Set_Subtype_Indication (CompDef_Node, Empty);
Set_Aliased_Present (CompDef_Node, Aliased_Present);
Set_Access_Definition (CompDef_Node,
P_Access_Definition (Not_Null_Present));
else
Set_Access_Definition (CompDef_Node, Empty);
Set_Aliased_Present (CompDef_Node, Aliased_Present);
Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
Set_Subtype_Indication (CompDef_Node,
P_Subtype_Indication (Not_Null_Present));
end if;
Set_Component_Definition (Def_Node, CompDef_Node);
return Def_Node;
end P_Array_Type_Definition;
-----------------------------------------
-- 3.6 Unconstrained Array Definition --
-----------------------------------------
-- Parsed by P_Array_Type_Definition (3.6)
---------------------------------------
-- 3.6 Constrained Array Definition --
---------------------------------------
-- Parsed by P_Array_Type_Definition (3.6)
--------------------------------------
-- 3.6 Discrete Subtype Definition --
--------------------------------------
-- DISCRETE_SUBTYPE_DEFINITION ::=
-- discrete_SUBTYPE_INDICATION | RANGE
-- Note: the discrete subtype definition appearing in a constrained
-- array definition is parsed by P_Array_Type_Definition (3.6)
-- Error recovery: cannot raise Error_Resync
function P_Discrete_Subtype_Definition return Node_Id is
begin
-- The syntax of a discrete subtype definition is identical to that
-- of a discrete range, so we simply share the same parsing code.
return P_Discrete_Range;
end P_Discrete_Subtype_Definition;
-------------------------------
-- 3.6 Component Definition --
-------------------------------
-- For the array case, parsed by P_Array_Type_Definition (3.6)
-- For the record case, parsed by P_Component_Declaration (3.8)
-----------------------------
-- 3.6.1 Index Constraint --
-----------------------------
-- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
---------------------------
-- 3.6.1 Discrete Range --
---------------------------
-- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
-- The possible forms for a discrete range are:
-- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
-- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
-- Range_Attribute (RANGE, 3.5)
-- Simple_Expression .. Simple_Expression (RANGE, 3.5)
-- Error recovery: cannot raise Error_Resync
function P_Discrete_Range return Node_Id is
Expr_Node : Node_Id;
Range_Node : Node_Id;
begin
Expr_Node := P_Simple_Expression_Or_Range_Attribute;
if Expr_Form = EF_Range_Attr then
return Expr_Node;
elsif Token = Tok_Range then
if Expr_Form /= EF_Simple_Name then
Error_Msg_SC ("range must be preceded by subtype mark");
end if;
return P_Subtype_Indication (Expr_Node);
-- Check Expression .. Expression case
elsif Token = Tok_Dot_Dot then
Range_Node := New_Node (N_Range, Token_Ptr);
Set_Low_Bound (Range_Node, Expr_Node);
if Style_Check then
Style.Check_Xtra_Parens (Expr_Node);
end if;
Scan; -- past ..
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Range_Node, Expr_Node);
-- If Expr_Node (ignoring parentheses) is not a simple expression
-- then emit a style check.
if Style_Check
and then Nkind (Expr_Node) not in N_Op_Boolean | N_Subexpr
then
Style.Check_Xtra_Parens (Expr_Node);
end if;
return Range_Node;
-- Otherwise we must have a subtype mark, or an Ada 2012 iterator
elsif Expr_Form = EF_Simple_Name then
return Expr_Node;
-- The domain of iteration must be a name. Semantics will determine that
-- the expression has the proper form.
elsif Ada_Version >= Ada_2012 then
return Expr_Node;
-- If incorrect, complain that we expect ..
else
T_Dot_Dot;
return Expr_Node;
end if;
end P_Discrete_Range;
----------------------------
-- 3.7 Discriminant Part --
----------------------------
-- DISCRIMINANT_PART ::=
-- UNKNOWN_DISCRIMINANT_PART
-- | KNOWN_DISCRIMINANT_PART
-- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
-- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
------------------------------------
-- 3.7 Unknown Discriminant Part --
------------------------------------
-- UNKNOWN_DISCRIMINANT_PART ::= (<>)
-- If no unknown discriminant part is present, then False is returned,
-- otherwise the unknown discriminant is scanned out and True is returned.
-- Error recovery: cannot raise Error_Resync
function P_Unknown_Discriminant_Part_Opt return Boolean is
Scan_State : Saved_Scan_State;
begin
-- If <> right now, then this is missing left paren
if Token = Tok_Box then
U_Left_Paren;
-- If not <> or left paren, then definitely no box
elsif Token /= Tok_Left_Paren then
return False;
-- Left paren, so might be a box after it
else
Save_Scan_State (Scan_State);
Scan; -- past the left paren
if Token /= Tok_Box then
Restore_Scan_State (Scan_State);
return False;
end if;
end if;
-- We are now pointing to the box
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!");
end if;
Scan; -- past the box
U_Right_Paren; -- must be followed by right paren
return True;
end P_Unknown_Discriminant_Part_Opt;
----------------------------------
-- 3.7 Known Discriminant Part --
----------------------------------
-- KNOWN_DISCRIMINANT_PART ::=
-- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
-- DISCRIMINANT_SPECIFICATION ::=
-- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
-- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
-- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
-- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
-- If no known discriminant part is present, then No_List is returned
-- Error recovery: cannot raise Error_Resync
function P_Known_Discriminant_Part_Opt return List_Id is
Specification_Node : Node_Id;
Specification_List : List_Id;
Ident_Sloc : Source_Ptr;
Scan_State : Saved_Scan_State;
Num_Idents : Nat;
Not_Null_Present : Boolean;
Ident : Nat;
Idents : array (Int range 1 .. 4096) of Entity_Id;
-- This array holds the list of defining identifiers. The upper bound
-- of 4096 is intended to be essentially infinite, and we do not even
-- bother to check for it being exceeded.
begin
if Token = Tok_Left_Paren then
Specification_List := New_List;
Scan; -- past (
P_Pragmas_Misplaced;
Specification_Loop : loop
Ident_Sloc := Token_Ptr;
Idents (1) := P_Defining_Identifier (C_Comma_Colon);
Num_Idents := 1;
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
end loop;
-- If there are multiple identifiers, we repeatedly scan the
-- type and initialization expression information by resetting
-- the scan pointer (so that we get completely separate trees
-- for each occurrence).
if Num_Idents > 1 then
Save_Scan_State (Scan_State);
end if;
T_Colon;
-- Loop through defining identifiers in list
Ident := 1;
Ident_Loop : loop
Specification_Node :=
New_Node (N_Discriminant_Specification, Ident_Sloc);
Set_Defining_Identifier (Specification_Node, Idents (Ident));
Not_Null_Present := -- Ada 2005 (AI-231, AI-447)
P_Null_Exclusion (Allow_Anonymous_In_95 => True);
if Token = Tok_Access then
if Ada_Version = Ada_83 then
Error_Msg_SC
("(Ada 83) access discriminant not allowed!");
end if;
Set_Discriminant_Type
(Specification_Node,
P_Access_Definition (Not_Null_Present));
-- Catch ouf-of-order keywords
elsif Token = Tok_Constant then
Scan;
if Token = Tok_Access then
Error_Msg_SC -- CODEFIX
("ACCESS must come before CONSTANT");
Set_Discriminant_Type
(Specification_Node,
P_Access_Definition (Not_Null_Present));
else
Error_Msg_SC ("misplaced CONSTANT");
end if;
else
Set_Discriminant_Type
(Specification_Node, P_Subtype_Mark);
No_Constraint;
Set_Null_Exclusion_Present -- Ada 2005 (AI-231)
(Specification_Node, Not_Null_Present);
end if;
Set_Expression
(Specification_Node, Init_Expr_Opt (True));
if Token = Tok_With then
P_Aspect_Specifications (Specification_Node, False);
end if;
if Ident > 1 then
Set_Prev_Ids (Specification_Node, True);
end if;
if Ident < Num_Idents then
Set_More_Ids (Specification_Node, True);
end if;
Append (Specification_Node, Specification_List);
exit Ident_Loop when Ident = Num_Idents;
Ident := Ident + 1;
Restore_Scan_State (Scan_State);
T_Colon;
end loop Ident_Loop;
exit Specification_Loop when Token /= Tok_Semicolon;
Scan; -- past ;
P_Pragmas_Misplaced;
end loop Specification_Loop;
T_Right_Paren;
return Specification_List;
else
return No_List;
end if;
end P_Known_Discriminant_Part_Opt;
-------------------------------------
-- 3.7 Discriminant Specification --
-------------------------------------
-- Parsed by P_Known_Discriminant_Part_Opt (3.7)
-----------------------------
-- 3.7 Default Expression --
-----------------------------
-- Always parsed (simply as an Expression) by the parent construct
------------------------------------
-- 3.7.1 Discriminant Constraint --
------------------------------------
-- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
--------------------------------------------------------
-- 3.7.1 Index or Discriminant Constraint (also 3.6) --
--------------------------------------------------------
-- DISCRIMINANT_CONSTRAINT ::=
-- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
-- DISCRIMINANT_ASSOCIATION ::=
-- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
-- EXPRESSION
-- This routine parses either an index or a discriminant constraint. As
-- is clear from the above grammar, it is often possible to clearly
-- determine which of the two possibilities we have, but there are
-- cases (those in which we have a series of expressions of the same
-- syntactic form as subtype indications), where we cannot tell. Since
-- this means that in any case the semantic phase has to distinguish
-- between the two, there is not much point in the parser trying to
-- distinguish even those cases where the difference is clear. In any
-- case, if we have a situation like:
-- (A => 123, 235 .. 500)
-- it is not clear which of the two items is the wrong one, better to
-- let the semantic phase give a clear message. Consequently, this
-- routine in general returns a list of items which can be either
-- discrete ranges or discriminant associations.
-- The caller has checked that the initial token is a left paren
-- Error recovery: can raise Error_Resync
function P_Index_Or_Discriminant_Constraint return Node_Id is
Scan_State : Saved_Scan_State;
Constr_Node : Node_Id;
Constr_List : List_Id;
Expr_Node : Node_Id;
Result_Node : Node_Id;
begin
Result_Node := New_Node (N_Index_Or_Discriminant_Constraint, Token_Ptr);
Scan; -- past (
Constr_List := New_List;
Set_Constraints (Result_Node, Constr_List);
-- The two syntactic forms are a little mixed up, so what we are doing
-- here is looking at the first entry to determine which case we have
-- A discriminant constraint is a list of discriminant associations,
-- which have one of the following possible forms:
-- Expression
-- Id => Expression
-- Id | Id | .. | Id => Expression
-- An index constraint is a list of discrete ranges which have one
-- of the following possible forms:
-- Subtype_Mark
-- Subtype_Mark range Range
-- Range_Attribute
-- Simple_Expression .. Simple_Expression
-- Loop through discriminants in list
loop
-- Check cases of Id => Expression or Id | Id => Expression
if Token = Tok_Identifier then
Save_Scan_State (Scan_State); -- at Id
Scan; -- past Id
if Token in Tok_Arrow | Tok_Vertical_Bar then
Restore_Scan_State (Scan_State); -- to Id
Append (P_Discriminant_Association, Constr_List);
goto Loop_Continue;
else
Restore_Scan_State (Scan_State); -- to Id
end if;
end if;
-- Otherwise scan out an expression and see what we have got
Expr_Node := P_Expression_Or_Range_Attribute;
if Expr_Form = EF_Range_Attr then
Append (Expr_Node, Constr_List);
elsif Token = Tok_Range then
if Expr_Form /= EF_Simple_Name then
Error_Msg_SC ("subtype mark required before RANGE");
end if;
Append (P_Subtype_Indication (Expr_Node), Constr_List);
goto Loop_Continue;
-- Check Simple_Expression .. Simple_Expression case
elsif Token = Tok_Dot_Dot then
Check_Simple_Expression (Expr_Node);
Constr_Node := New_Node (N_Range, Token_Ptr);
Set_Low_Bound (Constr_Node, Expr_Node);
Scan; -- past ..
-- If the upper bound is given by "<>", this is an index for
-- a fixed-lower-bound subtype, so set the expression to Empty
-- for now (it will be set to the ranges maximum upper bound
-- later during analysis), and scan to the next token.
if Token = Tok_Box then
Error_Msg_GNAT_Extension ("fixed-lower-bound array", Token_Ptr,
Is_Core_Extension => True);
Expr_Node := Empty;
Scan;
-- Otherwise parse the range's upper bound expression
else
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
end if;
Set_High_Bound (Constr_Node, Expr_Node);
Append (Constr_Node, Constr_List);
goto Loop_Continue;
-- Case of an expression which could be either form
else
Append (Expr_Node, Constr_List);
goto Loop_Continue;
end if;
-- Here with a single entry scanned
<<Loop_Continue>>
exit when not Comma_Present;
end loop;
T_Right_Paren;
return Result_Node;
end P_Index_Or_Discriminant_Constraint;
-------------------------------------
-- 3.7.1 Discriminant Association --
-------------------------------------
-- DISCRIMINANT_ASSOCIATION ::=
-- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
-- EXPRESSION
-- This routine is used only when the name list is present and the caller
-- has already checked this (by scanning ahead and repositioning the
-- scan).
-- Error_Recovery: cannot raise Error_Resync;
function P_Discriminant_Association return Node_Id is
Discr_Node : Node_Id;
Names_List : List_Id;
Ident_Sloc : Source_Ptr;
begin
Ident_Sloc := Token_Ptr;
Names_List := New_List;
loop
Append (P_Identifier (C_Vertical_Bar_Arrow), Names_List);
exit when Token /= Tok_Vertical_Bar;
Scan; -- past |
end loop;
Discr_Node := New_Node (N_Discriminant_Association, Ident_Sloc);
Set_Selector_Names (Discr_Node, Names_List);
TF_Arrow;
Set_Expression (Discr_Node, P_Expression);
return Discr_Node;
end P_Discriminant_Association;
---------------------------------
-- 3.8 Record Type Definition --
---------------------------------
-- RECORD_TYPE_DEFINITION ::=
-- [[abstract] tagged] [limited] RECORD_DEFINITION
-- There is no node in the tree for a record type definition. Instead
-- a record definition node appears, with possible Abstract_Present,
-- Tagged_Present, and Limited_Present flags set appropriately.
----------------------------
-- 3.8 Record Definition --
----------------------------
-- RECORD_DEFINITION ::=
-- record
-- COMPONENT_LIST
-- end record
-- | null record
-- Note: in the case where a record definition node is used to represent
-- a record type definition, the caller sets the Tagged_Present and
-- Limited_Present flags in the resulting N_Record_Definition node as
-- required.
-- Note that the RECORD token at the start may be missing in certain
-- error situations, so this function is expected to post the error
-- Error recovery: can raise Error_Resync
function P_Record_Definition return Node_Id is
procedure Catch_Out_Of_Order_Keywords (Keyword : String);
-- Catch ouf-of-order keywords in a record definition
---------------------------------
-- Catch_Out_Of_Order_Keywords --
---------------------------------
procedure Catch_Out_Of_Order_Keywords (Keyword : String) is
begin
loop
if Token = Tok_Abstract then
Error_Msg_SC -- CODEFIX
("ABSTRACT must come before " & Keyword);
Scan; -- past ABSTRACT
elsif Token = Tok_Tagged then
Error_Msg_SC -- CODEFIX
("TAGGED must come before " & Keyword);
Scan; -- past TAGGED
elsif Token = Tok_Limited then
Error_Msg_SC -- CODEFIX
("LIMITED must come before " & Keyword);
Scan; -- past LIMITED
else
exit;
end if;
end loop;
end Catch_Out_Of_Order_Keywords;
Rec_Node : Node_Id;
-- Start of processing for P_Record_Definition
begin
Inside_Record_Definition := True;
Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
-- Null record case
if Token = Tok_Null then
Scan; -- past NULL
Catch_Out_Of_Order_Keywords ("NULL");
T_Record;
Set_Null_Present (Rec_Node, True);
Catch_Out_Of_Order_Keywords ("RECORD");
-- Catch incomplete declaration to prevent cascaded errors, see
-- ACATS B393002 for an example.
elsif Token = Tok_Semicolon then
Error_Msg_AP ("missing record definition");
-- Case starting with RECORD keyword. Build scope stack entry. For the
-- column, we use the first non-blank character on the line, to deal
-- with situations such as:
-- type X is record
-- ...
-- end record;
-- which is not official RM indentation, but is not uncommon usage, and
-- in particular is standard GNAT coding style, so handle it nicely.
else
Push_Scope_Stack;
Scopes (Scope.Last).Etyp := E_Record;
Scopes (Scope.Last).Ecol := Start_Column;
Scopes (Scope.Last).Sloc := Token_Ptr;
Scopes (Scope.Last).Labl := Error;
Scopes (Scope.Last).Junk := (Token /= Tok_Record);
T_Record;
Catch_Out_Of_Order_Keywords ("RECORD");
Set_Component_List (Rec_Node, P_Component_List);
loop
exit when Check_End;
Discard_Junk_Node (P_Component_List);
end loop;
end if;
Inside_Record_Definition := False;
return Rec_Node;
end P_Record_Definition;
-------------------------
-- 3.8 Component List --
-------------------------
-- COMPONENT_LIST ::=
-- COMPONENT_ITEM {COMPONENT_ITEM}
-- | {COMPONENT_ITEM} VARIANT_PART
-- | null;
-- Error recovery: cannot raise Error_Resync
function P_Component_List return Node_Id is
Component_List_Node : Node_Id;
Decls_List : List_Id;
Scan_State : Saved_Scan_State;
Null_Loc : Source_Ptr;
begin
Component_List_Node := New_Node (N_Component_List, Token_Ptr);
Decls_List := New_List;
-- Handle null
if Token = Tok_Null then
Null_Loc := Token_Ptr;
Scan; -- past NULL
TF_Semicolon;
P_Pragmas_Opt (Decls_List);
-- If we have an END or WHEN now, everything is fine, otherwise we
-- complain about the null, ignore it, and scan for more components.
if Token in Tok_End | Tok_When then
Set_Null_Present (Component_List_Node, True);
return Component_List_Node;
else
Error_Msg ("NULL component only allowed in null record", Null_Loc);
end if;
end if;
-- Scan components for non-null record
P_Pragmas_Opt (Decls_List);
if Token /= Tok_Case then
loop
P_Component_Items (Decls_List);
P_Pragmas_Opt (Decls_List);
exit when Token in Tok_End | Tok_Case | Tok_When;
-- We are done if we do not have an identifier. However, if we
-- have a misspelled reserved identifier that is in a column to
-- the right of the record definition, we will treat it as an
-- identifier. It turns out to be too dangerous in practice to
-- accept such a mis-spelled identifier which does not have this
-- additional clue that confirms the incorrect spelling.
if Token /= Tok_Identifier then
if Start_Column > Scopes (Scope.Last).Ecol
and then Is_Reserved_Identifier
then
Save_Scan_State (Scan_State); -- at reserved id
Scan; -- possible reserved id
if Token in Tok_Comma | Tok_Colon then
Restore_Scan_State (Scan_State);
Scan_Reserved_Identifier (Force_Msg => True);
-- Note reserved identifier used as field name after all
-- because not followed by colon or comma.
else
Restore_Scan_State (Scan_State);
exit;
end if;
-- Non-identifier that definitely was not reserved id
else
exit;
end if;
end if;
end loop;
end if;
if Token = Tok_Case then
Set_Variant_Part (Component_List_Node, P_Variant_Part);
-- Check for junk after variant part
if Token = Tok_Identifier then
Save_Scan_State (Scan_State);
Scan; -- past identifier
if Token = Tok_Colon then
Restore_Scan_State (Scan_State);
Error_Msg_SC ("component may not follow variant part");
Discard_Junk_Node (P_Component_List);
elsif Token = Tok_Case then
Restore_Scan_State (Scan_State);
Error_Msg_SC ("only one variant part allowed in a record");
Discard_Junk_Node (P_Component_List);
else
Restore_Scan_State (Scan_State);
end if;
end if;
end if;
Set_Component_Items (Component_List_Node, Decls_List);
return Component_List_Node;
end P_Component_List;
-------------------------
-- 3.8 Component Item --
-------------------------
-- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
-- COMPONENT_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
-- [:= DEFAULT_EXPRESSION]
-- [ASPECT_SPECIFICATIONS];
-- COMPONENT_DEFINITION ::=
-- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
-- Error recovery: cannot raise Error_Resync, if an error occurs,
-- the scan is positioned past the following semicolon.
-- Note: we do not yet allow representation clauses to appear as component
-- items, do we need to add this capability sometime in the future ???
procedure P_Component_Items (Decls : List_Id) is
Aliased_Present : Boolean := False;
CompDef_Node : Node_Id;
Decl_Node : Node_Id := Empty; -- initialize to prevent warning
Scan_State : Saved_Scan_State;
Not_Null_Present : Boolean := False;
Num_Idents : Nat;
Ident : Nat;
Ident_Sloc : Source_Ptr;
Idents : array (Int range 1 .. 4096) of Entity_Id;
-- This array holds the list of defining identifiers. The upper bound
-- of 4096 is intended to be essentially infinite, and we do not even
-- bother to check for it being exceeded.
begin
if Token /= Tok_Identifier then
Error_Msg_SC ("component declaration expected");
Resync_Past_Semicolon;
return;
end if;
Ident_Sloc := Token_Ptr;
Check_Bad_Layout;
Idents (1) := P_Defining_Identifier (C_Comma_Colon);
Num_Idents := 1;
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
end loop;
-- If there are multiple identifiers, we repeatedly scan the
-- type and initialization expression information by resetting
-- the scan pointer (so that we get completely separate trees
-- for each occurrence).
if Num_Idents > 1 then
Save_Scan_State (Scan_State);
end if;
T_Colon;
-- Loop through defining identifiers in list
Ident := 1;
Ident_Loop : loop
-- The following block is present to catch Error_Resync
-- which causes the parse to be reset past the semicolon
begin
Decl_Node := New_Node (N_Component_Declaration, Ident_Sloc);
Set_Defining_Identifier (Decl_Node, Idents (Ident));
if Token = Tok_Constant then
Error_Msg_SC ("constant component not permitted");
Scan;
end if;
CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
if Token_Name = Name_Aliased then
Check_95_Keyword (Tok_Aliased, Tok_Identifier);
end if;
if Token = Tok_Aliased then
Aliased_Present := True;
Scan; -- past ALIASED
end if;
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
-- Ada 2005 (AI-230): Access Definition case
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension
("generalized use of anonymous access types");
-- AI95-406 makes "aliased" legal (and useless) here, so the
-- following code which used to be required is commented out.
-- if Aliased_Present then
-- Error_Msg_SP ("ALIASED not allowed here");
-- end if;
Set_Subtype_Indication (CompDef_Node, Empty);
Set_Aliased_Present (CompDef_Node, False);
Set_Access_Definition (CompDef_Node,
P_Access_Definition (Not_Null_Present));
else
Set_Access_Definition (CompDef_Node, Empty);
Set_Aliased_Present (CompDef_Node, Aliased_Present);
Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
if Token = Tok_Array then
Error_Msg_SC ("anonymous array not allowed as component");
raise Error_Resync;
end if;
Set_Subtype_Indication (CompDef_Node,
P_Subtype_Indication (Not_Null_Present));
end if;
Set_Component_Definition (Decl_Node, CompDef_Node);
Set_Expression (Decl_Node, Init_Expr_Opt);
if Ident > 1 then
Set_Prev_Ids (Decl_Node, True);
end if;
if Ident < Num_Idents then
Set_More_Ids (Decl_Node, True);
end if;
Append (Decl_Node, Decls);
exception
when Error_Resync =>
if Token /= Tok_End then
Resync_Past_Semicolon;
end if;
end;
exit Ident_Loop when Ident = Num_Idents;
Ident := Ident + 1;
Restore_Scan_State (Scan_State);
T_Colon;
end loop Ident_Loop;
P_Aspect_Specifications (Decl_Node);
end P_Component_Items;
--------------------------------
-- 3.8 Component Declaration --
--------------------------------
-- Parsed by P_Component_Items (3.8)
-------------------------
-- 3.8.1 Variant Part --
-------------------------
-- VARIANT_PART ::=
-- case discriminant_DIRECT_NAME is
-- VARIANT
-- {VARIANT}
-- end case;
-- The caller has checked that the initial token is CASE
-- Error recovery: cannot raise Error_Resync
function P_Variant_Part return Node_Id is
Variant_Part_Node : Node_Id;
Variants_List : List_Id;
Case_Node : Node_Id;
begin
Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr);
Push_Scope_Stack;
Scopes (Scope.Last).Etyp := E_Case;
Scopes (Scope.Last).Sloc := Token_Ptr;
Scopes (Scope.Last).Ecol := Start_Column;
Scan; -- past CASE
Case_Node := P_Expression;
Set_Name (Variant_Part_Node, Case_Node);
if Nkind (Case_Node) /= N_Identifier then
Set_Name (Variant_Part_Node, Error);
Error_Msg ("discriminant name expected", Sloc (Case_Node));
elsif Paren_Count (Case_Node) /= 0 then
Error_Msg
("|discriminant name may not be parenthesized",
Sloc (Case_Node));
Set_Paren_Count (Case_Node, 0);
end if;
TF_Is;
Variants_List := New_List;
P_Pragmas_Opt (Variants_List);
-- Test missing variant
if Token = Tok_End then
Error_Msg_BC ("WHEN expected (must have at least one variant)");
else
Append (P_Variant, Variants_List);
end if;
-- Loop through variants, note that we allow if in place of when,
-- this error will be detected and handled in P_Variant.
loop
P_Pragmas_Opt (Variants_List);
if Token not in Tok_When | Tok_If | Tok_Others then
exit when Check_End;
end if;
Append (P_Variant, Variants_List);
end loop;
Set_Variants (Variant_Part_Node, Variants_List);
return Variant_Part_Node;
end P_Variant_Part;
--------------------
-- 3.8.1 Variant --
--------------------
-- VARIANT ::=
-- when DISCRETE_CHOICE_LIST =>
-- COMPONENT_LIST
-- Error recovery: cannot raise Error_Resync
-- The initial token on entry is either WHEN, IF or OTHERS
function P_Variant return Node_Id is
Variant_Node : Node_Id;
begin
-- Special check to recover nicely from use of IF in place of WHEN
if Token = Tok_If then
T_When;
Scan; -- past IF
else
T_When;
end if;
Variant_Node := New_Node (N_Variant, Prev_Token_Ptr);
Set_Discrete_Choices (Variant_Node, P_Discrete_Choice_List);
TF_Arrow;
Set_Component_List (Variant_Node, P_Component_List);
return Variant_Node;
end P_Variant;
---------------------------------
-- 3.8.1 Discrete Choice List --
---------------------------------
-- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
-- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
-- Note: in Ada 83, the expression must be a simple expression
-- Error recovery: cannot raise Error_Resync
function P_Discrete_Choice_List return List_Id is
Choices : List_Id;
Expr_Node : Node_Id := Empty; -- initialize to prevent warning
Choice_Node : Node_Id;
begin
Choices := New_List;
loop
if Token = Tok_Others then
Append (New_Node (N_Others_Choice, Token_Ptr), Choices);
Scan; -- past OTHERS
else
begin
-- Scan out expression or range attribute
Expr_Node := P_Expression_Or_Range_Attribute;
Ignore (Tok_Right_Paren);
if Token = Tok_Colon
and then Nkind (Expr_Node) = N_Identifier
then
Error_Msg_SP ("label not permitted in this context");
Scan; -- past colon
-- Range attribute
elsif Expr_Form = EF_Range_Attr then
Append (Expr_Node, Choices);
-- Explicit range
elsif Token = Tok_Dot_Dot then
Check_Simple_Expression (Expr_Node);
Choice_Node := New_Node (N_Range, Token_Ptr);
Set_Low_Bound (Choice_Node, Expr_Node);
Scan; -- past ..
Expr_Node := P_Expression_No_Right_Paren;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Choice_Node, Expr_Node);
Append (Choice_Node, Choices);
-- Simple name, must be subtype, so range allowed
elsif Expr_Form = EF_Simple_Name then
if Token = Tok_Range then
Append (P_Subtype_Indication (Expr_Node), Choices);
elsif Token in Token_Class_Consk then
Error_Msg_SC
("the only constraint allowed here " &
"is a range constraint");
Discard_Junk_Node (P_Constraint_Opt);
Append (Expr_Node, Choices);
else
Append (Expr_Node, Choices);
end if;
-- Expression
else
-- In Ada 2012 mode, the expression must be a simple
-- expression. The reason for this restriction (i.e. going
-- back to the Ada 83 rule) is to avoid ambiguities when set
-- membership operations are allowed, consider the
-- following:
-- when A in 1 .. 10 | 12 =>
-- This is ambiguous without parentheses, so we require one
-- of the following two parenthesized forms to disambiguate:
-- one of the following:
-- when (A in 1 .. 10 | 12) =>
-- when (A in 1 .. 10) | 12 =>
-- To solve this, in Ada 2012 mode, we disallow the use of
-- membership operations in expressions in choices.
-- Technically in the grammar, the expression must match the
-- grammar for restricted expression.
if Ada_Version >= Ada_2012 then
Check_Restricted_Expression (Expr_Node);
-- In Ada 83 mode, the syntax required a simple expression
else
Check_Simple_Expression_In_Ada_83 (Expr_Node);
end if;
Append (Expr_Node, Choices);
end if;
exception
when Error_Resync =>
Resync_Choice;
return Error_List;
end;
end if;
if Token = Tok_Comma then
if Nkind (Expr_Node) = N_Iterated_Component_Association then
return Choices;
end if;
Scan; -- past comma
if Token = Tok_Vertical_Bar then
Error_Msg_SP -- CODEFIX
("|extra "","" ignored");
Scan; -- past |
else
Error_Msg_SP -- CODEFIX
(""","" should be ""'|""");
end if;
else
exit when Token /= Tok_Vertical_Bar;
Scan; -- past |
end if;
end loop;
return Choices;
end P_Discrete_Choice_List;
----------------------------
-- 3.8.1 Discrete Choice --
----------------------------
-- Parsed by P_Discrete_Choice_List (3.8.1)
----------------------------------
-- 3.9.1 Record Extension Part --
----------------------------------
-- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
-- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
--------------------------------------
-- 3.9.4 Interface Type Definition --
--------------------------------------
-- INTERFACE_TYPE_DEFINITION ::=
-- [limited | task | protected | synchronized] interface
-- [and INTERFACE_LIST]
-- Error recovery: cannot raise Error_Resync
function P_Interface_Type_Definition
(Abstract_Present : Boolean) return Node_Id
is
Typedef_Node : Node_Id;
begin
Error_Msg_Ada_2005_Extension ("abstract interface");
if Abstract_Present then
Error_Msg_SP
("ABSTRACT not allowed in interface type definition " &
"(RM 3.9.4(2/2))");
end if;
Scan; -- past INTERFACE
-- Ada 2005 (AI-345): In case of interfaces with a null list of
-- interfaces we build a record_definition node.
if Token = Tok_Semicolon or else Aspect_Specifications_Present then
Typedef_Node := New_Node (N_Record_Definition, Token_Ptr);
Set_Abstract_Present (Typedef_Node);
Set_Tagged_Present (Typedef_Node);
Set_Null_Present (Typedef_Node);
Set_Interface_Present (Typedef_Node);
-- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
-- a list of interfaces we build a derived_type_definition node. This
-- simplifies the semantic analysis (and hence further maintenance)
else
if Token /= Tok_And then
Error_Msg_AP ("AND expected");
else
Scan; -- past AND
end if;
Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
Set_Abstract_Present (Typedef_Node);
Set_Interface_Present (Typedef_Node);
Set_Subtype_Indication (Typedef_Node, P_Qualified_Simple_Name);
Set_Record_Extension_Part (Typedef_Node,
New_Node (N_Record_Definition, Token_Ptr));
Set_Null_Present (Record_Extension_Part (Typedef_Node));
if Token = Tok_And then
Set_Interface_List (Typedef_Node, New_List);
Scan; -- past AND
loop
Append (P_Qualified_Simple_Name,
Interface_List (Typedef_Node));
exit when Token /= Tok_And;
Scan; -- past AND
end loop;
end if;
end if;
return Typedef_Node;
end P_Interface_Type_Definition;
----------------------------------
-- 3.10 Access Type Definition --
----------------------------------
-- ACCESS_TYPE_DEFINITION ::=
-- ACCESS_TO_OBJECT_DEFINITION
-- | ACCESS_TO_SUBPROGRAM_DEFINITION
-- ACCESS_TO_OBJECT_DEFINITION ::=
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
-- GENERAL_ACCESS_MODIFIER ::= all | constant
-- ACCESS_TO_SUBPROGRAM_DEFINITION
-- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
-- | [NULL_EXCLUSION] access [protected] function
-- PARAMETER_AND_RESULT_PROFILE
-- PARAMETER_PROFILE ::= [FORMAL_PART]
-- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
-- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
-- parsed the null_exclusion part and has also removed the ACCESS token;
-- otherwise the caller has just checked that the initial token is ACCESS
-- Error recovery: can raise Error_Resync
function P_Access_Type_Definition
(Header_Already_Parsed : Boolean := False) return Node_Id
is
procedure Check_Junk_Subprogram_Name;
-- Used in access to subprogram definition cases to check for an
-- identifier or operator symbol that does not belong.
--------------------------------
-- Check_Junk_Subprogram_Name --
--------------------------------
procedure Check_Junk_Subprogram_Name is
Saved_State : Saved_Scan_State;
begin
if Token in Tok_Identifier | Tok_Operator_Symbol then
Save_Scan_State (Saved_State);
Scan; -- past possible junk subprogram name
if Token in Tok_Left_Paren | Tok_Semicolon then
Error_Msg_SP ("unexpected subprogram name ignored");
else
Restore_Scan_State (Saved_State);
end if;
end if;
end Check_Junk_Subprogram_Name;
Access_Loc : constant Source_Ptr := Token_Ptr;
Prot_Flag : Boolean;
Not_Null_Present : Boolean := False;
Not_Null_Subtype : Boolean := False;
Not_Null_Subtype_Loc : Source_Ptr; -- loc of second "not null"
Type_Def_Node : Node_Id;
Result_Not_Null : Boolean;
Result_Node : Node_Id;
-- Start of processing for P_Access_Type_Definition
begin
if not Header_Already_Parsed then
-- NOT NULL ACCESS... is a common form of access definition. ACCESS
-- NOT NULL... is certainly rare, but syntactically legal. NOT NULL
-- ACCESS NOT NULL... is rarer yet, and also legal. The last two
-- cases are only meaningful if the following subtype indication
-- denotes an access type. We check below for "not null procedure"
-- and "not null function"; in the access-to-object case it is a
-- semantic check. The flag Not_Null_Subtype indicates that this
-- second null exclusion is present in the access type definition.
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
if Token /= Tok_Access then
Error_Msg
("ACCESS expected",
Token_Ptr);
end if;
Scan; -- past ACCESS
Not_Null_Subtype_Loc := Token_Ptr;
Not_Null_Subtype := P_Null_Exclusion; -- Might also appear
end if;
if Token_Name = Name_Protected then
Check_95_Keyword (Tok_Protected, Tok_Procedure);
Check_95_Keyword (Tok_Protected, Tok_Function);
end if;
Prot_Flag := (Token = Tok_Protected);
if Prot_Flag then
Scan; -- past PROTECTED
if Token not in Tok_Procedure | Tok_Function then
Error_Msg_SC -- CODEFIX
("FUNCTION or PROCEDURE expected");
end if;
end if;
-- Access-to-subprogram case
if Token in Tok_Procedure | Tok_Function then
-- Check for "not null [protected] procedure" and "not null
-- [protected] function".
if Not_Null_Subtype then
Error_Msg
("null exclusion must apply to access type",
Not_Null_Subtype_Loc);
end if;
end if;
if Token = Tok_Procedure then
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) access to procedure not allowed!");
end if;
Type_Def_Node := New_Node (N_Access_Procedure_Definition, Access_Loc);
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
Scan; -- past PROCEDURE
Check_Junk_Subprogram_Name;
Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
Set_Protected_Present (Type_Def_Node, Prot_Flag);
elsif Token = Tok_Function then
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) access to function not allowed!");
end if;
Type_Def_Node := New_Node (N_Access_Function_Definition, Access_Loc);
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
Scan; -- past FUNCTION
Check_Junk_Subprogram_Name;
Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
Set_Protected_Present (Type_Def_Node, Prot_Flag);
TF_Return;
Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231)
-- Ada 2005 (AI-318-02)
if Token = Tok_Access then
Error_Msg_Ada_2005_Extension ("anonymous access result type");
Result_Node := P_Access_Definition (Result_Not_Null);
else
Result_Node := P_Subtype_Mark;
No_Constraint;
-- A null exclusion on the result type must be recorded in a flag
-- distinct from the one used for the access-to-subprogram type's
-- null exclusion.
Set_Null_Exclusion_In_Return_Present
(Type_Def_Node, Result_Not_Null);
end if;
Set_Result_Definition (Type_Def_Node, Result_Node);
-- Access-to-object case
else
Type_Def_Node := New_Node (N_Access_To_Object_Definition, Access_Loc);
Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
Set_Null_Excluding_Subtype (Type_Def_Node, Not_Null_Subtype);
if Token in Tok_All | Tok_Constant then
if Ada_Version = Ada_83 then
Error_Msg_SC ("(Ada 83) access modifier not allowed!");
end if;
if Token = Tok_All then
Set_All_Present (Type_Def_Node, True);
else
Set_Constant_Present (Type_Def_Node, True);
end if;
Scan; -- past ALL or CONSTANT
end if;
Set_Subtype_Indication (Type_Def_Node,
P_Subtype_Indication (Not_Null_Present));
end if;
return Type_Def_Node;
end P_Access_Type_Definition;
---------------------------------------
-- 3.10 Access To Object Definition --
---------------------------------------
-- Parsed by P_Access_Type_Definition (3.10)
-----------------------------------
-- 3.10 General Access Modifier --
-----------------------------------
-- Parsed by P_Access_Type_Definition (3.10)
-------------------------------------------
-- 3.10 Access To Subprogram Definition --
-------------------------------------------
-- Parsed by P_Access_Type_Definition (3.10)
-----------------------------
-- 3.10 Access Definition --
-----------------------------
-- ACCESS_DEFINITION ::=
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
-- | ACCESS_TO_SUBPROGRAM_DEFINITION
--
-- ACCESS_TO_SUBPROGRAM_DEFINITION
-- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
-- | [NULL_EXCLUSION] access [protected] function
-- PARAMETER_AND_RESULT_PROFILE
-- The caller has parsed the null-exclusion part and it has also checked
-- that the next token is ACCESS
-- Error recovery: cannot raise Error_Resync
function P_Access_Definition
(Null_Exclusion_Present : Boolean) return Node_Id
is
Def_Node : Node_Id;
Subp_Node : Node_Id;
begin
Def_Node := New_Node (N_Access_Definition, Token_Ptr);
Scan; -- past ACCESS
-- Ada 2005 (AI-254): Access_To_Subprogram_Definition
if Token in Tok_Protected | Tok_Procedure | Tok_Function then
Error_Msg_Ada_2005_Extension ("access-to-subprogram");
Subp_Node := P_Access_Type_Definition (Header_Already_Parsed => True);
Set_Null_Exclusion_Present (Subp_Node, Null_Exclusion_Present);
Set_Access_To_Subprogram_Definition (Def_Node, Subp_Node);
-- Ada 2005 (AI-231)
-- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
else
Set_Null_Exclusion_Present (Def_Node, Null_Exclusion_Present);
if Token = Tok_All then
if Ada_Version < Ada_2005 then
Error_Msg_SP
("ALL not permitted for anonymous access type");
end if;
Scan; -- past ALL
Set_All_Present (Def_Node);
elsif Token = Tok_Constant then
Error_Msg_Ada_2005_Extension ("access-to-constant");
Scan; -- past CONSTANT
Set_Constant_Present (Def_Node);
end if;
Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
No_Constraint;
end if;
return Def_Node;
end P_Access_Definition;
-----------------------------------------
-- 3.10.1 Incomplete Type Declaration --
-----------------------------------------
-- Parsed by P_Type_Declaration (3.2.1)
----------------------------
-- 3.11 Declarative Part --
----------------------------
-- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
-- Error recovery: cannot raise Error_Resync (because P_Declarative_Item
-- handles errors, and returns cleanly after an error has occurred)
function P_Declarative_Part return List_Id is
Decls : constant List_Id := New_List;
begin
-- Indicate no bad declarations detected yet. This will be reset by
-- P_Declarative_Items if a bad declaration is discovered.
Missing_Begin_Msg := No_Error_Msg;
-- Get rid of active SIS entry from outer scope. This means we will
-- miss some nested cases, but it doesn't seem worth the effort. See
-- discussion in Par for further details
SIS_Entry_Active := False;
P_Declarative_Items
(Decls, Declare_Expression => False,
In_Spec => False, In_Statements => False);
-- Get rid of active SIS entry which is left set only if we scanned a
-- procedure declaration and have not found the body. We could give
-- an error message, but that really would be usurping the role of
-- semantic analysis (this really is a missing body case).
SIS_Entry_Active := False;
return Decls;
end P_Declarative_Part;
----------------------------
-- 3.11 Declarative Item --
----------------------------
-- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
-- Can return Error if a junk declaration is found, or Empty if no
-- declaration is found (i.e. a token ending declarations, such as
-- BEGIN or END is encountered).
-- Error recovery: cannot raise Error_Resync. If an error resync occurs,
-- then the scan is set past the next semicolon and Error is returned.
procedure P_Declarative_Item
(Decls : List_Id;
Done : out Boolean;
Declare_Expression : Boolean;
In_Spec : Boolean;
In_Statements : Boolean)
is
Scan_State : Saved_Scan_State;
begin
Done := False;
-- In -gnatg mode, we don't want a "bad indentation" error inside a
-- declare_expression.
if Style_Check and not Declare_Expression then
Style.Check_Indentation;
end if;
case Token is
when Tok_Function
| Tok_Not
| Tok_Overriding
| Tok_Procedure
=>
Check_Bad_Layout;
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
when Tok_For =>
Check_Bad_Layout;
-- Check for loop (premature statement)
Save_Scan_State (Scan_State);
Scan; -- past FOR
declare
Is_Statement : Boolean := True;
begin
if Token = Tok_Identifier then
Scan; -- past identifier
if Token in Tok_Use | Tok_Apostrophe then
Is_Statement := False;
elsif Token = Tok_Dot then
Scan;
if Token = Tok_Identifier then
Scan;
Is_Statement := Token in Tok_In | Tok_Of;
end if;
end if;
else
Is_Statement := False;
end if;
Restore_Scan_State (Scan_State);
if Is_Statement then
if not In_Statements then
Statement_When_Declaration_Expected
(Decls, Done, In_Spec);
end if;
Done := True;
else
Append (P_Representation_Clause, Decls);
end if;
end;
when Tok_Generic =>
Check_Bad_Layout;
Append (P_Generic, Decls);
when Tok_Identifier =>
Check_Bad_Layout;
-- Special check for misuse of overriding not in Ada 2005 mode
if Token_Name = Name_Overriding
and then not Next_Token_Is (Tok_Colon)
then
Error_Msg_SC ("overriding indicator is an Ada 2005 extension");
Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
Token := Tok_Overriding;
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
-- Normal case, no overriding, or overriding followed by colon
else
P_Identifier_Declarations (Decls, Done, In_Spec, In_Statements);
end if;
when Tok_Package =>
Check_Bad_Layout;
Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
when Tok_Pragma =>
-- If we see a pragma and In_Statements is true, we want to let
-- the statement-parser deal with it.
if In_Statements then
Done := True;
else
Append (P_Pragma, Decls);
end if;
when Tok_Protected =>
Check_Bad_Layout;
Scan; -- past PROTECTED
Append (P_Protected, Decls);
when Tok_Subtype =>
Check_Bad_Layout;
Append (P_Subtype_Declaration, Decls);
when Tok_Task =>
Check_Bad_Layout;
Scan; -- past TASK
Append (P_Task, Decls);
when Tok_Type =>
Check_Bad_Layout;
Append (P_Type_Declaration, Decls);
when Tok_Use =>
Check_Bad_Layout;
P_Use_Clause (Decls);
when Tok_With =>
Check_Bad_Layout;
if Aspect_Specifications_Present (Strict => True) then
-- If we are after a semicolon, complain that it was ignored.
-- But we don't really ignore it, since we dump the aspects,
-- so we make the error message a normal fatal message which
-- will inhibit semantic analysis anyway).
if Prev_Token = Tok_Semicolon then
Error_Msg_SP -- CODEFIX
("extra "";"" ignored");
-- If not just past semicolon, just complain that aspects are
-- not allowed at this point.
else
Error_Msg_SC ("aspect specifications not allowed here");
end if;
-- Assume that this is a misplaced aspect specification within
-- a declarative list. After discarding the misplaced aspects
-- we can continue the scan.
declare
Dummy_Node : constant Node_Id :=
New_Node (N_Package_Specification, Token_Ptr);
pragma Warnings (Off, Dummy_Node);
-- Dummy node to attach aspect specifications to. We will
-- then throw them away.
begin
P_Aspect_Specifications (Dummy_Node, Semicolon => True);
end;
-- Here if not aspect specifications case
else
Error_Msg_SC ("WITH can only appear in context clause");
raise Error_Resync;
end if;
-- BEGIN terminates the scan of a sequence of declarations unless
-- there is a missing subprogram body, see section on handling
-- semicolon in place of IS. We only treat the begin as satisfying
-- the subprogram declaration if it falls in the expected column
-- or to its right.
when Tok_Begin =>
if SIS_Entry_Active and then Start_Column >= SIS_Ecol then
-- Here we have the case where a BEGIN is encountered during
-- declarations in a declarative part, or at the outer level,
-- and there is a subprogram declaration outstanding for which
-- no body has been supplied. This is the case where we assume
-- that the semicolon in the subprogram declaration should
-- really have been is. The active SIS entry describes the
-- subprogram declaration. On return the declaration has been
-- modified to become a body.
declare
Specification_Node : Node_Id;
Decl_Node : Node_Id;
Body_Node : Node_Id;
begin
-- First issue the error message. If we had a missing
-- semicolon in the declaration, then change the message
-- to <missing "is">
if SIS_Missing_Semicolon_Message /= No_Error_Msg then
Change_Error_Text -- Replace: "missing "";"" "
(SIS_Missing_Semicolon_Message, "missing ""is""");
-- Otherwise we saved the semicolon position, so complain
else
Error_Msg -- CODEFIX
("|"";"" should be IS", SIS_Semicolon_Sloc);
end if;
-- The next job is to fix up any declarations that occurred
-- between the procedure header and the BEGIN. These got
-- chained to the outer declarative region (immediately
-- after the procedure declaration) and they should be
-- chained to the subprogram itself, which is a body
-- rather than a spec.
Specification_Node := Specification (SIS_Declaration_Node);
Change_Node (SIS_Declaration_Node, N_Subprogram_Body);
Body_Node := SIS_Declaration_Node;
Set_Specification (Body_Node, Specification_Node);
Set_Declarations (Body_Node, New_List);
loop
Decl_Node := Remove_Next (Body_Node);
exit when Decl_Node = Empty;
Append (Decl_Node, Declarations (Body_Node));
end loop;
-- Now make the scope table entry for the Begin-End and
-- scan it out
Push_Scope_Stack;
Scopes (Scope.Last).Sloc := SIS_Sloc;
Scopes (Scope.Last).Etyp := E_Name;
Scopes (Scope.Last).Ecol := SIS_Ecol;
Scopes (Scope.Last).Labl := SIS_Labl;
Scopes (Scope.Last).Lreq := False;
SIS_Entry_Active := False;
Scan; -- past BEGIN
Set_Handled_Statement_Sequence (Body_Node,
P_Handled_Sequence_Of_Statements);
End_Statements (Handled_Statement_Sequence (Body_Node));
end;
else
Done := True;
end if;
-- Normally an END terminates the scan for basic declarative items.
-- The one exception is END RECORD, which is probably left over from
-- some other junk.
when Tok_End =>
Save_Scan_State (Scan_State); -- at END
Scan; -- past END
if Token = Tok_Record then
Error_Msg_SP ("no RECORD for this `end record`!");
Scan; -- past RECORD
TF_Semicolon;
-- This might happen because of misplaced aspect specification.
-- After discarding the misplaced aspects we can continue the
-- scan.
else
Restore_Scan_State (Scan_State); -- to END
Done := True;
end if;
-- The following tokens which can only be the start of a statement
-- are considered to end a declarative part (i.e. we have a missing
-- BEGIN situation). We are fairly conservative in making this
-- judgment, because it is a real mess to go into statement mode
-- prematurely in response to a junk declaration.
when Tok_Abort
| Tok_Accept
| Tok_Declare
| Tok_Delay
| Tok_Exit
| Tok_Goto
| Tok_If
| Tok_Loop
| Tok_Null
| Tok_Requeue
| Tok_Select
| Tok_While
=>
-- If we parsing declarations in a sequence of statements, we want
-- to let the caller continue parsing statements.
if In_Statements then
Done := True;
-- Otherwise, give an error. But before we decide that it's a
-- statement, check for a reserved word misused as an identifier.
elsif Is_Reserved_Identifier then
Save_Scan_State (Scan_State);
Scan; -- past the token
-- If reserved identifier not followed by colon or comma, then
-- this is most likely an assignment statement to the bad id.
if Token not in Tok_Colon | Tok_Comma then
Restore_Scan_State (Scan_State);
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
-- Otherwise we have a declaration of the bad id
else
Restore_Scan_State (Scan_State);
Scan_Reserved_Identifier (Force_Msg => True);
P_Identifier_Declarations
(Decls, Done, In_Spec, In_Statements);
end if;
-- If not reserved identifier, then it's an incorrectly placed a
-- statement.
else
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
end if;
-- The token RETURN may well also signal a missing BEGIN situation,
-- however, we never let it end the declarative part, because it
-- might also be part of a half-baked function declaration. If we are
-- In_Statements, then let the caller parse it; otherwise, it's an
-- error.
when Tok_Return =>
if In_Statements then
Done := True;
else
Error_Msg_SC ("misplaced RETURN statement");
raise Error_Resync;
end if;
-- PRIVATE definitely terminates the declarations in a spec,
-- and is an error in a body.
when Tok_Private =>
if In_Spec then
Done := True;
else
Error_Msg_SC ("PRIVATE not allowed in body");
Scan; -- past PRIVATE
end if;
-- An end of file definitely terminates the declarations
when Tok_EOF =>
Done := True;
-- The remaining tokens do not end the scan, but cannot start a
-- valid declaration, so we signal an error and resynchronize.
-- But first check for misuse of a reserved identifier.
when others =>
if In_Statements then
Done := True;
return;
end if;
-- Here we check for a reserved identifier
if Is_Reserved_Identifier then
Save_Scan_State (Scan_State);
Scan; -- past the token
if Token not in Tok_Colon | Tok_Comma then
Restore_Scan_State (Scan_State);
Set_Declaration_Expected;
raise Error_Resync;
else
Restore_Scan_State (Scan_State);
Scan_Reserved_Identifier (Force_Msg => True);
Check_Bad_Layout;
P_Identifier_Declarations
(Decls, Done, In_Spec, In_Statements);
end if;
else
Set_Declaration_Expected;
raise Error_Resync;
end if;
end case;
-- To resynchronize after an error, we scan to the next semicolon and
-- return with Done = False, indicating that there may still be more
-- valid declarations to come.
exception
when Error_Resync =>
Resync_Past_Semicolon;
end P_Declarative_Item;
procedure P_Declarative_Items
(Decls : List_Id;
Declare_Expression : Boolean;
In_Spec : Boolean;
In_Statements : Boolean)
is
Done : Boolean;
begin
loop
P_Declarative_Item
(Decls, Done, Declare_Expression, In_Spec, In_Statements);
exit when Done;
end loop;
end P_Declarative_Items;
----------------------------------
-- 3.11 Basic Declarative Item --
----------------------------------
-- BASIC_DECLARATIVE_ITEM ::=
-- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
-- Scan zero or more basic declarative items
-- Error recovery: cannot raise Error_Resync. If an error is detected, then
-- the scan pointer is repositioned past the next semicolon, and the scan
-- for declarative items continues.
function P_Basic_Declarative_Items
(Declare_Expression : Boolean) return List_Id
is
Decl : Node_Id;
Decls : constant List_Id := New_List;
Kind : Node_Kind;
begin
-- Indicate no bad declarations detected yet in the current context:
-- visible or private declarations of a package spec.
Missing_Begin_Msg := No_Error_Msg;
-- Get rid of active SIS entry from outer scope. This means we will
-- miss some nested cases, but it doesn't seem worth the effort. See
-- discussion in Par for further details
SIS_Entry_Active := False;
P_Declarative_Items
(Decls, Declare_Expression, In_Spec => True, In_Statements => False);
-- Get rid of active SIS entry. This is set only if we have scanned a
-- procedure declaration and have not found the body. We could give
-- an error message, but that really would be usurping the role of
-- semantic analysis (this really is a case of a missing body).
SIS_Entry_Active := False;
-- Test for assorted illegal declarations not diagnosed elsewhere
Decl := First (Decls);
while Present (Decl) loop
Kind := Nkind (Decl);
-- Test for body scanned, not acceptable as basic decl item
if Kind = N_Subprogram_Body or else
Kind = N_Package_Body or else
Kind = N_Task_Body or else
Kind = N_Protected_Body
then
if Declare_Expression then
Error_Msg
("proper body not allowed in declare_expression",
Sloc (Decl));
else
Error_Msg
("proper body not allowed in package spec",
Sloc (Decl));
end if;
-- Complete declaration of mangled subprogram body, for better
-- recovery if analysis is attempted.
if Nkind (Decl) in N_Subprogram_Body | N_Package_Body | N_Task_Body
and then No (Handled_Statement_Sequence (Decl))
then
Set_Handled_Statement_Sequence (Decl,
Make_Handled_Sequence_Of_Statements (Sloc (Decl),
Statements => New_List));
end if;
-- Test for body stub scanned, not acceptable as basic decl item
elsif Kind in N_Body_Stub then
Error_Msg ("body stub not allowed in package spec", Sloc (Decl));
elsif Kind = N_Assignment_Statement then
Error_Msg
("assignment statement not allowed in package spec",
Sloc (Decl));
end if;
Next (Decl);
end loop;
return Decls;
end P_Basic_Declarative_Items;
----------------
-- 3.11 Body --
----------------
-- For proper body, see below
-- For body stub, see 10.1.3
-----------------------
-- 3.11 Proper Body --
-----------------------
-- Subprogram body is parsed by P_Subprogram (6.1)
-- Package body is parsed by P_Package (7.1)
-- Task body is parsed by P_Task (9.1)
-- Protected body is parsed by P_Protected (9.4)
------------------------------
-- Set_Declaration_Expected --
------------------------------
procedure Set_Declaration_Expected is
begin
Error_Msg_SC ("declaration expected");
if Missing_Begin_Msg = No_Error_Msg then
Missing_Begin_Msg := Get_Msg_Id;
end if;
end Set_Declaration_Expected;
----------------------
-- Skip_Declaration --
----------------------
procedure Skip_Declaration (S : List_Id) is
Ignored_Done : Boolean;
begin
P_Declarative_Item
(S, Ignored_Done, Declare_Expression => False, In_Spec => False,
In_Statements => False);
end Skip_Declaration;
-----------------------------------------
-- Statement_When_Declaration_Expected --
-----------------------------------------
procedure Statement_When_Declaration_Expected
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean)
is
begin
-- Case of second occurrence of statement in one declaration sequence
if Missing_Begin_Msg /= No_Error_Msg then
-- In the procedure spec case, just ignore it, we only give one
-- message for the first occurrence, since otherwise we may get
-- horrible cascading if BODY was missing in the header line.
if In_Spec then
null;
-- Just ignore it if we are in -gnatd.2 (allow statements to appear
-- in declaration sequences) mode.
elsif Debug_Flag_Dot_2 then
null;
-- In the declarative part case, take a second statement as a sure
-- sign that we really have a missing BEGIN, and end the declarative
-- part now. Note that the caller will fix up the first message to
-- say "missing BEGIN" so that's how the error will be signalled.
else
Done := True;
return;
end if;
-- Case of first occurrence of unexpected statement
else
-- Do not give error message if we are operating in -gnatd.2 mode
-- (alllow statements to appear in declarative parts).
if not Debug_Flag_Dot_2 then
-- If we are in a package spec, then give message of statement
-- not allowed in package spec. This message never gets changed.
if In_Spec then
Error_Msg_SC ("statement not allowed in package spec");
-- If in declarative part, then we give the message complaining
-- about finding a statement when a declaration is expected. This
-- gets changed to a complaint about a missing BEGIN if we later
-- find that no BEGIN is present.
else
Error_Msg_SC ("statement not allowed in declarative part");
end if;
-- Capture message Id. This is used for two purposes, first to
-- stop multiple messages, see test above, and second, to allow
-- the replacement of the message in the declarative part case.
Missing_Begin_Msg := Get_Msg_Id;
end if;
end if;
-- In all cases except the case in which we decided to terminate the
-- declaration sequence on a second error, we scan out the statement
-- and append it to the list of declarations (note that the semantics
-- can handle statements in a declaration list so if we proceed to
-- call the semantic phase, all will be (reasonably) well.
Append_List_To (Decls, P_Sequence_Of_Statements (SS_Unco));
-- Done is set to False, since we want to continue the scan of
-- declarations, hoping that this statement was a temporary glitch.
-- If we indeed are now in the statement part (i.e. this was a missing
-- BEGIN, then it's not terrible, we will simply keep calling this
-- procedure to process the statements one by one, and then finally
-- hit the missing BEGIN, which will clean up the error message.
Done := False;
end Statement_When_Declaration_Expected;
end Ch3;
|