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
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P A R . C H 3 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- 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)
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 P_Declarative_Items
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean);
-- Scans out a single declarative item, or, in the case of a declaration
-- with a list of identifiers, a list of declarations, one for each of
-- the identifiers in the list. The declaration or declarations scanned
-- are appended to the given list. Done indicates whether or not there
-- may be additional declarative items to scan. If Done is True, then
-- a decision has been made that there are no more items to scan. If
-- Done is False, then there may be additional declarations to scan.
-- In_Spec is true if we are scanning a package declaration, and is used
-- to generate an appropriate message if a statement is encountered in
-- such a context.
procedure P_Identifier_Declarations
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean);
-- Scans out a set of declarations for an identifier or list of
-- identifiers, and appends them to the given list. The parameters have
-- the same significance 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 are as described 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.
-------------------
-- Init_Expr_Opt --
-------------------
function Init_Expr_Opt (P : Boolean := False) return Node_Id is
begin
if Token = Tok_Colon_Equal
or else Token = Tok_Equal
or else Token = Tok_Colon
or else Token = Tok_Is
then
null;
-- One other 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 return Node_Id is
Ident_Node : Node_Id;
begin
-- Scan out the identifier. Note that this code is essentially identical
-- to P_Identifier, except that in the call to Scan_Reserved_Identifier
-- we set Force_Msg to True, since we want at least one message for each
-- separate declaration (but not use) of a reserved identifier.
if Token = Tok_Identifier then
null;
-- If we have a reserved identifier, manufacture an identifier with
-- a corresponding name after posting an appropriate error message
elsif Is_Reserved_Identifier then
Scan_Reserved_Identifier (Force_Msg => True);
-- Otherwise we have junk that cannot be interpreted as an identifier
else
T_Identifier; -- to give message
raise Error_Resync;
end if;
Ident_Node := Token_Node;
Scan; -- past the reserved identifier
if Ident_Node /= Error then
Change_Identifier_To_Defining_Identifier (Ident_Node);
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;
-- | CONCURRENT_TYPE_DECLARATION
-- INCOMPLETE_TYPE_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART];
-- PRIVATE_TYPE_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
-- is [abstract] [tagged] [limited] private;
-- PRIVATE_EXTENSION_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
-- [abstract] new ancestor_SUBTYPE_INDICATION with private;
-- TYPE_DEFINITION ::=
-- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
-- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
-- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
-- | DERIVED_TYPE_DEFINITION
-- INTEGER_TYPE_DEFINITION ::=
-- SIGNED_INTEGER_TYPE_DEFINITION
-- MODULAR_TYPE_DEFINITION
-- Error recovery: can raise Error_Resync
-- Note: The processing for full type declaration, incomplete type
-- declaration, private type declaration and type definition is
-- included in this function. The processing for concurrent type
-- declarations is NOT here, but rather in chapter 9 (i.e. this
-- function handles only declarations starting with TYPE).
function P_Type_Declaration return Node_Id is
Type_Loc : Source_Ptr;
Type_Start_Col : Column_Number;
Ident_Node : Node_Id;
Decl_Node : Node_Id;
Discr_List : List_Id;
Unknown_Dis : Boolean;
Discr_Sloc : Source_Ptr;
Abstract_Present : Boolean;
Abstract_Loc : Source_Ptr;
End_Labl : Node_Id;
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;
T_Type;
Ident_Node := P_Defining_Identifier;
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 ("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
if Token = Tok_Limited
or else Token = Tok_Private
or else Token = Tok_Record
or else Token = Tok_Null
then
Error_Msg_AP ("TAGGED expected");
end if;
else
Abstract_Present := False;
Abstract_Loc := No_Location;
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 procesing 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 =>
Typedef_Node := P_Access_Type_Definition;
TF_Semicolon;
exit;
when Tok_Array =>
Typedef_Node := P_Array_Type_Definition;
TF_Semicolon;
exit;
when Tok_Delta =>
Typedef_Node := P_Fixed_Point_Definition;
TF_Semicolon;
exit;
when Tok_Digits =>
Typedef_Node := P_Floating_Point_Definition;
TF_Semicolon;
exit;
when Tok_In =>
Ignore (Tok_In);
when Tok_Integer_Literal =>
T_Range;
Typedef_Node := P_Signed_Integer_Type_Definition;
TF_Semicolon;
exit;
when Tok_Null =>
Typedef_Node := P_Record_Definition;
TF_Semicolon;
exit;
when Tok_Left_Paren =>
Typedef_Node := P_Enumeration_Type_Definition;
End_Labl :=
Make_Identifier (Token_Ptr,
Chars => Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
TF_Semicolon;
exit;
when Tok_Mod =>
Typedef_Node := P_Modular_Type_Definition;
TF_Semicolon;
exit;
when Tok_New =>
Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
TF_Semicolon;
exit;
when Tok_Range =>
Typedef_Node := P_Signed_Integer_Type_Definition;
TF_Semicolon;
exit;
when Tok_Record =>
Typedef_Node := P_Record_Definition;
End_Labl :=
Make_Identifier (Token_Ptr,
Chars => Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
TF_Semicolon;
exit;
when Tok_Tagged =>
Scan; -- past TAGGED
if Token = Tok_Abstract then
Error_Msg_SC ("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 => 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 => Chars (Ident_Node));
Set_Comes_From_Source (End_Labl, False);
Set_End_Label (Typedef_Node, End_Labl);
end if;
end if;
TF_Semicolon;
exit;
when Tok_Private =>
Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
Scan; -- past PRIVATE
TF_Semicolon;
exit;
when Tok_Limited =>
Scan; -- past LIMITED
loop
if Token = Tok_Tagged then
Error_Msg_SC ("TAGGED must come before LIMITED");
Scan; -- past TAGGED
elsif Token = Tok_Abstract then
Error_Msg_SC ("ABSTRACT must come before LIMITED");
Scan; -- past ABSTRACT
else
exit;
end if;
end loop;
-- LIMITED RECORD or LIMITED NULL RECORD
if Token = Tok_Record or else Token = Tok_Null then
if Ada_83 then
Error_Msg_SP
("(Ada 83) limited record declaration not allowed!");
end if;
Typedef_Node := P_Record_Definition;
Set_Limited_Present (Typedef_Node, True);
-- 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;
TF_Semicolon;
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;
TF_Semicolon;
-- 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;
TF_Semicolon;
end if;
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)))
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);
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 SUBTYPE_INDICATION;
-- 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;
begin
Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr);
Scan; -- past SUBTYPE
Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
TF_Is;
if Token = Tok_New then
Error_Msg_SC ("NEW ignored (only allowed in type declaration)");
Scan; -- past NEW
end if;
Set_Subtype_Indication (Decl_Node, P_Subtype_Indication);
TF_Semicolon;
return Decl_Node;
end P_Subtype_Declaration;
-------------------------------
-- 3.2.2 Subtype Indication --
-------------------------------
-- SUBTYPE_INDICATION ::= SUBTYPE_MARK [CONSTRAINT]
-- Error recovery: can raise Error_Resync
function P_Subtype_Indication return Node_Id is
Type_Node : Node_Id;
begin
if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
Type_Node := P_Subtype_Mark;
return P_Subtype_Indication (Type_Node);
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 definitions are 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) return Node_Id is
Indic_Node : Node_Id;
Constr_Node : Node_Id;
begin
Constr_Node := P_Constraint_Opt;
if No (Constr_Node) then
return Subtype_Mark;
else
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);
Delete_Node (Token_Node);
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;
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 : [constant] [aliased]
-- SUBTYPE_INDICATION [:= EXPRESSION];
-- | DEFINING_IDENTIFIER_LIST : [constant] [aliased]
-- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
-- NUMBER_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
-- OBJECT_RENAMING_DECLARATION ::=
-- DEFINING_IDENTIFIER : SUBTYPE_MARK renames object_NAME;
-- EXCEPTION_RENAMING_DECLARATION ::=
-- DEFINING_IDENTIFIER : exception renames exception_NAME;
-- EXCEPTION_DECLARATION ::=
-- DEFINING_IDENTIFIER_LIST : exception;
-- 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)
is
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;
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
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.
procedure No_List is
begin
if Num_Idents > 1 then
Error_Msg ("identifier list not allowed for RENAMES",
Sloc (Idents (2)));
end if;
List_OK := False;
end No_List;
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 ("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
Ident_Sloc := Token_Ptr;
Save_Scan_State (Scan_State); -- at first identifier
Idents (1) := P_Defining_Identifier;
-- 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;
end loop;
Save_Scan_State (Scan_State); -- at colon
T_Colon;
-- If we have 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);
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;
-- 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. Just complain that we expect a declaration, and
-- skip to a semicolon
else
Set_Declaration_Expected;
Resync_Past_Semicolon;
Done := False;
return;
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
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 ("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
Set_Object_Definition (Decl_Node, P_Subtype_Indication);
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
Set_Object_Definition (Decl_Node, P_Subtype_Indication);
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);
-- 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_Object_Definition
(Decl_Node, P_Subtype_Indication (Type_Node));
-- 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);
else
Error_Msg ("initialization not allowed here", Init_Loc);
end if;
end if;
TF_Semicolon;
Set_Defining_Identifier (Decl_Node, Idents (Ident));
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] new parent_SUBTYPE_INDICATION [RECORD_EXTENSION_PART]
-- PRIVATE_EXTENSION_DECLARATION ::=
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
-- [abstract] new ancestor_SUBTYPE_INDICATION with PRIVATE;
-- 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;
begin
Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
T_New;
if Token = Tok_Abstract then
Error_Msg_SC ("ABSTRACT must come before NEW, not after");
Scan;
end if;
Set_Subtype_Indication (Typedef_Node, P_Subtype_Indication);
-- 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".
if Token = Tok_With
or else Token = Tok_Record
or else Token = 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));
Delete_Node (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
-- 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);
Scan; -- past RANGE
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.
-- 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 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;
-- 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 qualifed 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 = Tok_Digits or else Token = Tok_Delta then
Error_Msg_SC
("accuracy definition not allowed in membership test");
Scan; -- past DIGITS or DELTA
raise Error_Resync;
elsif Token = Tok_Apostrophe then
return P_Subtype_Mark_Attribute (Expr_Node);
else
return Expr_Node;
end if;
-- At this stage, we have some junk following the expression. We
-- really can't tell what is wrong, might be a missing semicolon,
-- or a missing THEN, or whatever. Our caller will figure it out!
else
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;
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;
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);
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_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 ("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_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_No_Right_Paren;
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
-- 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_No_Right_Paren;
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] SUBTYPE_INDICATION
-- 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;
Def_Node : Node_Id;
Subs_List : List_Id;
Scan_State : Saved_Scan_State;
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
loop
Append (P_Subtype_Mark_Resync, Subs_List);
T_Range;
T_Box;
exit when Token = Tok_Right_Paren or else Token = Tok_Of;
T_Comma;
end loop;
Set_Subtype_Marks (Def_Node, Subs_List);
else
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;
if Token = Tok_Aliased then
Set_Aliased_Present (Def_Node, True);
Scan; -- past ALIASED
end if;
Set_Subtype_Indication (Def_Node, P_Subtype_Indication);
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);
Scan; -- past ..
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
Set_High_Bound (Range_Node, Expr_Node);
return Range_Node;
-- Otherwise we must have a subtype mark
elsif Expr_Form = EF_Simple_Name 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 Token /= Tok_Left_Paren then
return False;
else
Save_Scan_State (Scan_State);
Scan; -- past the left paren
if Token = Tok_Box then
if Ada_83 then
Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!");
end if;
Scan; -- past the box
T_Right_Paren; -- must be followed by right paren
return True;
else
Restore_Scan_State (Scan_State);
return False;
end if;
end if;
end P_Unknown_Discriminant_Part_Opt;
----------------------------------
-- 3.7 Known Discriminant Part --
----------------------------------
-- KNOWN_DISCRIMINANT_PART ::=
-- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
-- DISCRIMINANT_SPECIFICATION ::=
-- DEFINING_IDENTIFIER_LIST : SUBTYPE_MARK
-- [:= DEFAULT_EXPRESSION]
-- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
-- [:= DEFAULT_EXPRESSION]
-- 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;
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;
Num_Idents := 1;
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier;
end loop;
T_Colon;
-- 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;
-- 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));
if Token = Tok_Access then
if Ada_83 then
Error_Msg_SC
("(Ada 83) access discriminant not allowed!");
end if;
Set_Discriminant_Type
(Specification_Node, P_Access_Definition);
else
Set_Discriminant_Type
(Specification_Node, P_Subtype_Mark);
No_Constraint;
end if;
Set_Expression
(Specification_Node, Init_Expr_Opt (True));
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);
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 = Tok_Arrow or else Token = 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 ..
Expr_Node := P_Expression;
Check_Simple_Expression (Expr_Node);
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, 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
Rec_Node : Node_Id;
begin
Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
-- Null record case
if Token = Tok_Null then
Scan; -- past NULL
T_Record;
Set_Null_Present (Rec_Node, True);
-- 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
else
Push_Scope_Stack;
Scope.Table (Scope.Last).Etyp := E_Record;
Scope.Table (Scope.Last).Ecol := Start_Column;
Scope.Table (Scope.Last).Sloc := Token_Ptr;
Scope.Table (Scope.Last).Labl := Error;
Scope.Table (Scope.Last).Junk := (Token /= Tok_Record);
T_Record;
Set_Component_List (Rec_Node, P_Component_List);
loop
exit when Check_End;
Discard_Junk_Node (P_Component_List);
end loop;
end if;
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;
begin
Component_List_Node := New_Node (N_Component_List, Token_Ptr);
Decls_List := New_List;
if Token = Tok_Null then
Scan; -- past NULL
TF_Semicolon;
P_Pragmas_Opt (Decls_List);
Set_Null_Present (Component_List_Node, True);
return Component_List_Node;
else
P_Pragmas_Opt (Decls_List);
if Token /= Tok_Case then
Component_Scan_Loop : loop
P_Component_Items (Decls_List);
P_Pragmas_Opt (Decls_List);
exit Component_Scan_Loop when Token = Tok_End
or else Token = Tok_Case
or else Token = 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 > Scope.Table (Scope.Last).Ecol
and then Is_Reserved_Identifier
then
Save_Scan_State (Scan_State); -- at reserved id
Scan; -- possible reserved id
if Token = Tok_Comma or else Token = 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 Component_Scan_Loop;
end if;
-- Non-identifier that definitely was not reserved id
else
exit Component_Scan_Loop;
end if;
end if;
end loop Component_Scan_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;
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];
-- COMPONENT_DEFINITION ::= [aliased] SUBTYPE_INDICATION
-- 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
Decl_Node : Node_Id;
Scan_State : Saved_Scan_State;
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;
Idents (1) := P_Defining_Identifier;
Num_Idents := 1;
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier;
end loop;
T_Colon;
-- 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;
-- 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 components are not permitted");
Scan;
end if;
if Token_Name = Name_Aliased then
Check_95_Keyword (Tok_Aliased, Tok_Identifier);
end if;
if Token = Tok_Aliased then
Scan; -- past ALIASED
Set_Aliased_Present (Decl_Node, True);
end if;
if Token = Tok_Array then
Error_Msg_SC ("anonymous arrays not allowed as components");
raise Error_Resync;
end if;
Set_Subtype_Indication (Decl_Node, P_Subtype_Indication);
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);
end loop Ident_Loop;
TF_Semicolon;
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;
Case_Sloc : Source_Ptr;
begin
Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr);
Push_Scope_Stack;
Scope.Table (Scope.Last).Etyp := E_Case;
Scope.Table (Scope.Last).Sloc := Token_Ptr;
Scope.Table (Scope.Last).Ecol := Start_Column;
Scan; -- past CASE
Case_Node := P_Expression;
Case_Sloc := Token_Ptr;
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));
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 /= Tok_When
and then Token /= Tok_If
and then Token /= 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;
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
Expr_Node := No_Right_Paren (P_Expression_Or_Range_Attribute);
if Token = Tok_Colon
and then Nkind (Expr_Node) = N_Identifier
then
Error_Msg_SP ("label not permitted in this context");
Scan; -- past colon
elsif Expr_Form = EF_Range_Attr then
Append (Expr_Node, Choices);
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);
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;
else
Check_Simple_Expression_In_Ada_83 (Expr_Node);
Append (Expr_Node, Choices);
end if;
exception
when Error_Resync =>
Resync_Choice;
return Error_List;
end;
end if;
if Token = Tok_Comma then
Error_Msg_SC (""","" should be ""'|""");
else
exit when Token /= Tok_Vertical_Bar;
end if;
Scan; -- past | or comma
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.10 Access Type Definition --
----------------------------------
-- ACCESS_TYPE_DEFINITION ::=
-- ACCESS_TO_OBJECT_DEFINITION
-- | ACCESS_TO_SUBPROGRAM_DEFINITION
-- ACCESS_TO_OBJECT_DEFINITION ::=
-- access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
-- GENERAL_ACCESS_MODIFIER ::= all | constant
-- ACCESS_TO_SUBPROGRAM_DEFINITION
-- access [protected] procedure PARAMETER_PROFILE
-- | access [protected] function PARAMETER_AND_RESULT_PROFILE
-- PARAMETER_PROFILE ::= [FORMAL_PART]
-- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
-- The caller has checked that the initial token is ACCESS
-- Error recovery: can raise Error_Resync
function P_Access_Type_Definition return Node_Id is
Prot_Flag : Boolean;
Access_Loc : Source_Ptr;
Type_Def_Node : Node_Id;
procedure Check_Junk_Subprogram_Name;
-- Used in access to subprogram definition cases to check for an
-- identifier or operator symbol that does not belong.
procedure Check_Junk_Subprogram_Name is
Saved_State : Saved_Scan_State;
begin
if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
Save_Scan_State (Saved_State);
Scan; -- past possible junk subprogram name
if Token = Tok_Left_Paren or else Token = Tok_Semicolon then
Error_Msg_SP ("unexpected subprogram name ignored");
return;
else
Restore_Scan_State (Saved_State);
end if;
end if;
end Check_Junk_Subprogram_Name;
-- Start of processing for P_Access_Type_Definition
begin
Access_Loc := Token_Ptr;
Scan; -- past ACCESS
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 /= Tok_Procedure and then Token /= Tok_Function then
Error_Msg_SC ("FUNCTION or PROCEDURE expected");
end if;
end if;
if Token = Tok_Procedure then
if 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);
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_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);
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;
Set_Subtype_Mark (Type_Def_Node, P_Subtype_Mark);
No_Constraint;
else
Type_Def_Node :=
New_Node (N_Access_To_Object_Definition, Access_Loc);
if Token = Tok_All or else Token = Tok_Constant then
if 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);
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 ::= access SUBTYPE_MARK
-- The caller has checked that the initial token is ACCESS
-- Error recovery: cannot raise Error_Resync
function P_Access_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node := New_Node (N_Access_Definition, Token_Ptr);
Scan; -- past ACCESS
Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
No_Constraint;
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_Items
-- handles errors, and returns cleanly after an error has occurred)
function P_Declarative_Part return List_Id is
Decls : List_Id;
Done : Boolean;
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;
Decls := New_List;
-- Loop to scan out the declarations
loop
P_Declarative_Items (Decls, Done, In_Spec => False);
exit when Done;
end loop;
-- 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_Items
(Decls : List_Id;
Done : out Boolean;
In_Spec : Boolean)
is
Scan_State : Saved_Scan_State;
begin
if Style_Check then Style.Check_Indentation; end if;
case Token is
when Tok_Function =>
Check_Bad_Layout;
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
Done := False;
when Tok_For =>
Check_Bad_Layout;
-- Check for loop (premature statement)
Save_Scan_State (Scan_State);
Scan; -- past FOR
if Token = Tok_Identifier then
Scan; -- past identifier
if Token = Tok_In then
Restore_Scan_State (Scan_State);
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
return;
end if;
end if;
-- Not a loop, so must be rep clause
Restore_Scan_State (Scan_State);
Append (P_Representation_Clause, Decls);
Done := False;
when Tok_Generic =>
Check_Bad_Layout;
Append (P_Generic, Decls);
Done := False;
when Tok_Identifier =>
Check_Bad_Layout;
P_Identifier_Declarations (Decls, Done, In_Spec);
when Tok_Package =>
Check_Bad_Layout;
Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
Done := False;
when Tok_Pragma =>
Append (P_Pragma, Decls);
Done := False;
when Tok_Procedure =>
Check_Bad_Layout;
Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
Done := False;
when Tok_Protected =>
Check_Bad_Layout;
Scan; -- past PROTECTED
Append (P_Protected, Decls);
Done := False;
when Tok_Subtype =>
Check_Bad_Layout;
Append (P_Subtype_Declaration, Decls);
Done := False;
when Tok_Task =>
Check_Bad_Layout;
Scan; -- past TASK
Append (P_Task, Decls);
Done := False;
when Tok_Type =>
Check_Bad_Layout;
Append (P_Type_Declaration, Decls);
Done := False;
when Tok_Use =>
Check_Bad_Layout;
Append (P_Use_Clause, Decls);
Done := False;
when Tok_With =>
Check_Bad_Layout;
Error_Msg_SC ("WITH can only appear in context clause");
raise Error_Resync;
-- 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 (""";"" 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;
Scope.Table (Scope.Last).Sloc := SIS_Sloc;
Scope.Table (Scope.Last).Etyp := E_Name;
Scope.Table (Scope.Last).Ecol := SIS_Ecol;
Scope.Table (Scope.Last).Labl := SIS_Labl;
Scope.Table (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;
Done := False;
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;
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 =>
-- But before we decide that it's a statement, let's check for
-- a reserved word misused as an identifier.
if 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 /= Tok_Colon and then Token /= Tok_Comma then
Restore_Scan_State (Scan_State);
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
return;
-- 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);
end if;
-- If not reserved identifier, then it's definitely a statement
else
Statement_When_Declaration_Expected (Decls, Done, In_Spec);
return;
end if;
-- The token RETURN may well also signal a missing BEGIN situation,
-- however, we never let it end the declarative part, because it may
-- also be part of a half-baked function declaration.
when Tok_Return =>
Error_Msg_SC ("misplaced RETURN statement");
raise Error_Resync;
-- 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 =>
-- Here we check for a reserved identifier
if Is_Reserved_Identifier then
Save_Scan_State (Scan_State);
Scan; -- past the token
if Token /= Tok_Colon and then Token /= 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);
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;
Done := False;
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 return List_Id is
Decl : Node_Id;
Decls : List_Id;
Kind : Node_Kind;
Done : Boolean;
begin
-- 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;
-- Loop to scan out declarations
Decls := New_List;
loop
P_Declarative_Items (Decls, Done, In_Spec => True);
exit when Done;
end loop;
-- 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
Error_Msg
("proper body not allowed in package spec", Sloc (Decl));
-- 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
Dummy_Done : Boolean;
begin
P_Declarative_Items (S, Dummy_Done, 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;
-- 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
-- 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;
-- 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;
|