1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ C H 4 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Aspects; use Aspects;
with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Util; use Exp_Util;
with Itypes; use Itypes;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Namet.Sp; use Namet.Sp;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Case; use Sem_Case;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Dim; use Sem_Dim;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
package body Sem_Ch4 is
-- Tables which speed up the identification of dangerous calls to Ada 2012
-- functions with writable actuals (AI05-0144).
-- The following table enumerates the Ada constructs which may evaluate in
-- arbitrary order. It does not cover all the language constructs which can
-- be evaluated in arbitrary order but the subset needed for AI05-0144.
Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
(N_Aggregate => True,
N_Assignment_Statement => True,
N_Entry_Call_Statement => True,
N_Extension_Aggregate => True,
N_Full_Type_Declaration => True,
N_Indexed_Component => True,
N_Object_Declaration => True,
N_Pragma => True,
N_Range => True,
N_Slice => True,
N_Array_Type_Definition => True,
N_Membership_Test => True,
N_Binary_Op => True,
N_Subprogram_Call => True,
others => False);
-- The following table enumerates the nodes on which we stop climbing when
-- locating the outermost Ada construct that can be evaluated in arbitrary
-- order.
Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
(N_Aggregate => True,
N_Assignment_Statement => True,
N_Entry_Call_Statement => True,
N_Extended_Return_Statement => True,
N_Extension_Aggregate => True,
N_Full_Type_Declaration => True,
N_Object_Declaration => True,
N_Object_Renaming_Declaration => True,
N_Package_Specification => True,
N_Pragma => True,
N_Procedure_Call_Statement => True,
N_Simple_Return_Statement => True,
N_Has_Condition => True,
others => False);
-----------------------
-- Local Subprograms --
-----------------------
procedure Analyze_Concatenation_Rest (N : Node_Id);
-- Does the "rest" of the work of Analyze_Concatenation, after the left
-- operand has been analyzed. See Analyze_Concatenation for details.
procedure Analyze_Expression (N : Node_Id);
-- For expressions that are not names, this is just a call to analyze. If
-- the expression is a name, it may be a call to a parameterless function,
-- and if so must be converted into an explicit call node and analyzed as
-- such. This deproceduring must be done during the first pass of overload
-- resolution, because otherwise a procedure call with overloaded actuals
-- may fail to resolve.
procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
-- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
-- operator name or an expanded name whose selector is an operator name,
-- and one possible interpretation is as a predefined operator.
procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
-- If the prefix of a selected_component is overloaded, the proper
-- interpretation that yields a record type with the proper selector
-- name must be selected.
procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
-- Procedure to analyze a user defined binary operator, which is resolved
-- like a function, but instead of a list of actuals it is presented
-- with the left and right operands of an operator node.
procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
-- Procedure to analyze a user defined unary operator, which is resolved
-- like a function, but instead of a list of actuals, it is presented with
-- the operand of the operator node.
procedure Analyze_One_Call
(N : Node_Id;
Nam : Entity_Id;
Report : Boolean;
Success : out Boolean;
Skip_First : Boolean := False);
-- Check one interpretation of an overloaded subprogram name for
-- compatibility with the types of the actuals in a call. If there is a
-- single interpretation which does not match, post error if Report is
-- set to True.
--
-- Nam is the entity that provides the formals against which the actuals
-- are checked. Nam is either the name of a subprogram, or the internal
-- subprogram type constructed for an access_to_subprogram. If the actuals
-- are compatible with Nam, then Nam is added to the list of candidate
-- interpretations for N, and Success is set to True.
--
-- The flag Skip_First is used when analyzing a call that was rewritten
-- from object notation. In this case the first actual may have to receive
-- an explicit dereference, depending on the first formal of the operation
-- being called. The caller will have verified that the object is legal
-- for the call. If the remaining parameters match, the first parameter
-- will rewritten as a dereference if needed, prior to completing analysis.
procedure Check_Misspelled_Selector
(Prefix : Entity_Id;
Sel : Node_Id);
-- Give possible misspelling message if Sel seems likely to be a mis-
-- spelling of one of the selectors of the Prefix. This is called by
-- Analyze_Selected_Component after producing an invalid selector error
-- message.
procedure Find_Arithmetic_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- L and R are the operands of an arithmetic operator. Find consistent
-- pairs of interpretations for L and R that have a numeric type consistent
-- with the semantics of the operator.
procedure Find_Comparison_Equality_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- L and R are operands of a comparison or equality operator. Find valid
-- pairs of interpretations for L and R.
procedure Find_Concatenation_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- For the four varieties of concatenation
procedure Find_Boolean_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- Ditto for binary logical operations
procedure Find_Negation_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- Find consistent interpretation for operand of negation operator
function Find_Primitive_Operation (N : Node_Id) return Boolean;
-- Find candidate interpretations for the name Obj.Proc when it appears in
-- a subprogram renaming declaration.
procedure Find_Unary_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- Unary arithmetic types: plus, minus, abs
procedure Check_Arithmetic_Pair
(T1, T2 : Entity_Id;
Op_Id : Entity_Id;
N : Node_Id);
-- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
-- for left and right operand. Determine whether they constitute a valid
-- pair for the given operator, and record the corresponding interpretation
-- of the operator node. The node N may be an operator node (the usual
-- case) or a function call whose prefix is an operator designator. In
-- both cases Op_Id is the operator name itself.
procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
-- Give detailed information on overloaded call where none of the
-- interpretations match. N is the call node, Nam the designator for
-- the overloaded entity being called.
function Junk_Operand (N : Node_Id) return Boolean;
-- Test for an operand that is an inappropriate entity (e.g. a package
-- name or a label). If so, issue an error message and return True. If
-- the operand is not an inappropriate entity kind, return False.
procedure Operator_Check (N : Node_Id);
-- Verify that an operator has received some valid interpretation. If none
-- was found, determine whether a use clause would make the operation
-- legal. The variable Candidate_Type (defined in Sem_Type) is set for
-- every type compatible with the operator, even if the operator for the
-- type is not directly visible. The routine uses this type to emit a more
-- informative message.
function Has_Possible_Literal_Aspects (N : Node_Id) return Boolean;
-- Ada_2022: if an operand is a literal it may be subject to an
-- implicit conversion to a type for which a user-defined literal
-- function exists. During the first pass of type resolution we do
-- not know the context imposed on the literal, so we assume that
-- the literal type is a valid candidate and rely on the second pass
-- of resolution to find the type with the proper aspect. We only
-- add this interpretation if no other one was found, which may be
-- too restrictive but seems sufficient to handle most proper uses
-- of the new aspect. It is unclear whether a full implementation of
-- these aspects can be achieved without larger modifications to the
-- two-pass resolution algorithm.
function Possible_Type_For_Conditional_Expression
(T1, T2 : Entity_Id) return Entity_Id;
-- Given two types T1 and T2 that are _not_ compatible, return a type that
-- may still be used as the possible type of a conditional expression whose
-- dependent expressions, or part thereof, have type T1 and T2 respectively
-- during the first phase of type resolution, or Empty if such a type does
-- not exist.
-- The typical example is an if_expression whose then_expression is of a
-- tagged type and whose else_expresssion is of an extension of this type:
-- the types are not compatible but such an if_expression can be legal if
-- its expected type is the 'Class of the tagged type, so the function will
-- return the tagged type in this case. If the expected type turns out to
-- be something else, including the tagged type itself, then an error will
-- be given during the second phase of type resolution.
procedure Remove_Abstract_Operations (N : Node_Id);
-- Ada 2005: implementation of AI-310. An abstract non-dispatching
-- operation is not a candidate interpretation.
function Try_Container_Indexing
(N : Node_Id;
Prefix : Node_Id;
Exprs : List_Id) return Boolean;
-- AI05-0139: Generalized indexing to support iterators over containers
-- ??? Need to provide a more detailed spec of what this function does
function Try_Indexed_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id;
Skip_First : Boolean) return Boolean;
-- If a function has defaults for all its actuals, a call to it may in fact
-- be an indexing on the result of the call. Try_Indexed_Call attempts the
-- interpretation as an indexing, prior to analysis as a call. If both are
-- possible, the node is overloaded with both interpretations (same symbol
-- but two different types). If the call is written in prefix form, the
-- prefix becomes the first parameter in the call, and only the remaining
-- actuals must be checked for the presence of defaults.
function Try_Indirect_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean;
-- Similarly, a function F that needs no actuals can return an access to a
-- subprogram, and the call F (X) interpreted as F.all (X). In this case
-- the call may be overloaded with both interpretations.
procedure wpo (T : Entity_Id);
pragma Warnings (Off, wpo);
-- Used for debugging: obtain list of primitive operations even if
-- type is not frozen and dispatch table is not built yet.
------------------------
-- Ambiguous_Operands --
------------------------
procedure Ambiguous_Operands (N : Node_Id) is
procedure List_Operand_Interps (Opnd : Node_Id);
--------------------------
-- List_Operand_Interps --
--------------------------
procedure List_Operand_Interps (Opnd : Node_Id) is
Nam : Node_Id := Empty;
Err : Node_Id := N;
begin
if Is_Overloaded (Opnd) then
if Nkind (Opnd) in N_Op then
Nam := Opnd;
elsif Nkind (Opnd) = N_Function_Call then
Nam := Name (Opnd);
elsif Ada_Version >= Ada_2012 then
declare
It : Interp;
I : Interp_Index;
begin
Get_First_Interp (Opnd, I, It);
while Present (It.Nam) loop
if Has_Implicit_Dereference (It.Typ) then
Error_Msg_N
("can be interpreted as implicit dereference", Opnd);
return;
end if;
Get_Next_Interp (I, It);
end loop;
end;
return;
end if;
else
return;
end if;
if Opnd = Left_Opnd (N) then
Error_Msg_N
("\left operand has the following interpretations", N);
else
Error_Msg_N
("\right operand has the following interpretations", N);
Err := Opnd;
end if;
List_Interps (Nam, Err);
end List_Operand_Interps;
-- Start of processing for Ambiguous_Operands
begin
if Nkind (N) in N_Membership_Test then
Error_Msg_N ("ambiguous operands for membership", N);
elsif Nkind (N) in N_Op_Eq | N_Op_Ne then
Error_Msg_N ("ambiguous operands for equality", N);
else
Error_Msg_N ("ambiguous operands for comparison", N);
end if;
if All_Errors_Mode then
List_Operand_Interps (Left_Opnd (N));
List_Operand_Interps (Right_Opnd (N));
else
Error_Msg_N ("\use -gnatf switch for details", N);
end if;
end Ambiguous_Operands;
-----------------------
-- Analyze_Aggregate --
-----------------------
-- Most of the analysis of Aggregates requires that the type be known, and
-- is therefore put off until resolution of the context. Delta aggregates
-- have a base component that determines the enclosing aggregate type so
-- its type can be ascertained earlier. This also allows delta aggregates
-- to appear in the context of a record type with a private extension, as
-- per the latest update of AI12-0127.
procedure Analyze_Aggregate (N : Node_Id) is
begin
if No (Etype (N)) then
if Nkind (N) = N_Delta_Aggregate then
declare
Base : constant Node_Id := Expression (N);
I : Interp_Index;
It : Interp;
begin
Analyze (Base);
-- If the base is overloaded, propagate interpretations to the
-- enclosing aggregate.
if Is_Overloaded (Base) then
Get_First_Interp (Base, I, It);
Set_Etype (N, Any_Type);
while Present (It.Nam) loop
Add_One_Interp (N, It.Typ, It.Typ);
Get_Next_Interp (I, It);
end loop;
else
Set_Etype (N, Etype (Base));
end if;
end;
else
Set_Etype (N, Any_Composite);
end if;
end if;
end Analyze_Aggregate;
-----------------------
-- Analyze_Allocator --
-----------------------
procedure Analyze_Allocator (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Sav_Errs : constant Nat := Serious_Errors_Detected;
E : Node_Id := Expression (N);
Acc_Type : Entity_Id;
Type_Id : Entity_Id;
P : Node_Id;
C : Node_Id;
Onode : Node_Id;
begin
-- Deal with allocator restrictions
-- In accordance with H.4(7), the No_Allocators restriction only applies
-- to user-written allocators. The same consideration applies to the
-- No_Standard_Allocators_Before_Elaboration restriction.
if Comes_From_Source (N) then
Check_Restriction (No_Allocators, N);
-- Processing for No_Standard_Allocators_After_Elaboration, loop to
-- look at enclosing context, checking task/main subprogram case.
C := N;
P := Parent (C);
while Present (P) loop
-- For the task case we need a handled sequence of statements,
-- where the occurrence of the allocator is within the statements
-- and the parent is a task body
if Nkind (P) = N_Handled_Sequence_Of_Statements
and then Is_List_Member (C)
and then List_Containing (C) = Statements (P)
then
Onode := Original_Node (Parent (P));
-- Check for allocator within task body, this is a definite
-- violation of No_Allocators_After_Elaboration we can detect
-- at compile time.
if Nkind (Onode) = N_Task_Body then
Check_Restriction
(No_Standard_Allocators_After_Elaboration, N);
exit;
end if;
end if;
-- The other case is appearance in a subprogram body. This is
-- a violation if this is a library level subprogram with no
-- parameters. Note that this is now a static error even if the
-- subprogram is not the main program (this is a change, in an
-- earlier version only the main program was affected, and the
-- check had to be done in the binder).
if Nkind (P) = N_Subprogram_Body
and then Nkind (Parent (P)) = N_Compilation_Unit
and then No (Parameter_Specifications (Specification (P)))
then
Check_Restriction
(No_Standard_Allocators_After_Elaboration, N);
end if;
C := P;
P := Parent (C);
end loop;
end if;
-- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
-- any. The expected type for the name is any type. A non-overloading
-- rule then requires it to be of a type descended from
-- System.Storage_Pools.Subpools.Subpool_Handle.
-- This isn't exactly what the AI says, but it seems to be the right
-- rule. The AI should be fixed.???
declare
Subpool : constant Node_Id := Subpool_Handle_Name (N);
begin
if Present (Subpool) then
Analyze (Subpool);
if Is_Overloaded (Subpool) then
Error_Msg_N ("ambiguous subpool handle", Subpool);
end if;
-- Check that Etype (Subpool) is descended from Subpool_Handle
Resolve (Subpool);
end if;
end;
-- Analyze the qualified expression or subtype indication
if Nkind (E) = N_Qualified_Expression then
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Find_Type (Subtype_Mark (E));
-- Analyze the qualified expression, and apply the name resolution
-- rule given in 4.7(3).
Analyze (E);
Type_Id := Etype (E);
Set_Directly_Designated_Type (Acc_Type, Type_Id);
-- A qualified expression requires an exact match of the type,
-- class-wide matching is not allowed.
-- if Is_Class_Wide_Type (Type_Id)
-- and then Base_Type
-- (Etype (Expression (E))) /= Base_Type (Type_Id)
-- then
-- Wrong_Type (Expression (E), Type_Id);
-- end if;
-- We don't analyze the qualified expression itself because it's
-- part of the allocator. It is fully analyzed and resolved when
-- the allocator is resolved with the context type.
Set_Etype (E, Type_Id);
-- Case where allocator has a subtype indication
else
-- If the allocator includes a N_Subtype_Indication then a
-- constraint is present, otherwise the node is a subtype mark.
-- Introduce an explicit subtype declaration into the tree
-- defining some anonymous subtype and rewrite the allocator to
-- use this subtype rather than the subtype indication.
-- It is important to introduce the explicit subtype declaration
-- so that the bounds of the subtype indication are attached to
-- the tree in case the allocator is inside a generic unit.
-- Finally, if there is no subtype indication and the type is
-- a tagged unconstrained type with discriminants, the designated
-- object is constrained by their default values, and it is
-- simplest to introduce an explicit constraint now. In some cases
-- this is done during expansion, but freeze actions are certain
-- to be emitted in the proper order if constraint is explicit.
if Is_Entity_Name (E) and then Expander_Active then
Find_Type (E);
Type_Id := Entity (E);
if Is_Tagged_Type (Type_Id)
and then Has_Defaulted_Discriminants (Type_Id)
and then not Is_Constrained (Type_Id)
then
declare
Constr : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (E);
Discr : Entity_Id := First_Discriminant (Type_Id);
begin
while Present (Discr) loop
Append (Discriminant_Default_Value (Discr), Constr);
Next_Discriminant (Discr);
end loop;
Rewrite (E,
Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constr)));
end;
end if;
end if;
if Nkind (E) = N_Subtype_Indication then
declare
Def_Id : Entity_Id;
Base_Typ : Entity_Id;
begin
-- A constraint is only allowed for a composite type in Ada
-- 95. In Ada 83, a constraint is also allowed for an
-- access-to-composite type, but the constraint is ignored.
Find_Type (Subtype_Mark (E));
Base_Typ := Entity (Subtype_Mark (E));
if Is_Elementary_Type (Base_Typ) then
if not (Ada_Version = Ada_83
and then Is_Access_Type (Base_Typ))
then
Error_Msg_N ("constraint not allowed here", E);
if Nkind (Constraint (E)) =
N_Index_Or_Discriminant_Constraint
then
Error_Msg_N -- CODEFIX
("\if qualified expression was meant, " &
"use apostrophe", Constraint (E));
end if;
end if;
-- Get rid of the bogus constraint:
Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
Analyze_Allocator (N);
return;
end if;
-- In GNATprove mode we need to preserve the link between
-- the original subtype indication and the anonymous subtype,
-- to extend proofs to constrained access types. We only do
-- that outside of spec expressions, otherwise the declaration
-- cannot be inserted and analyzed. In such a case, GNATprove
-- later rejects the allocator as it is not used here in
-- a non-interfering context (SPARK 4.8(2) and 7.1.3(10)).
if Expander_Active
or else (GNATprove_Mode and then not In_Spec_Expression)
then
Def_Id := Make_Temporary (Loc, 'S');
declare
Subtype_Decl : constant Node_Id :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Indication => Relocate_Node (E));
begin
Insert_Action (E, Subtype_Decl);
-- Handle unusual case where Insert_Action does not
-- analyze the declaration. Subtype_Decl must be
-- preanalyzed before call to Process_Subtype below.
Preanalyze (Subtype_Decl);
end;
if Sav_Errs /= Serious_Errors_Detected
and then Nkind (Constraint (E)) =
N_Index_Or_Discriminant_Constraint
then
Error_Msg_N -- CODEFIX
("if qualified expression was meant, use apostrophe!",
Constraint (E));
end if;
E := New_Occurrence_Of (Def_Id, Loc);
Rewrite (Expression (N), E);
end if;
end;
end if;
Type_Id := Process_Subtype (E, N);
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Type_Id);
Check_Fully_Declared (Type_Id, N);
-- Ada 2005 (AI-231): If the designated type is itself an access
-- type that excludes null, its default initialization will
-- be a null object, and we can insert an unconditional raise
-- before the allocator.
-- Ada 2012 (AI-104): A not null indication here is altogether
-- illegal.
if Can_Never_Be_Null (Type_Id) then
declare
Not_Null_Check : constant Node_Id :=
Make_Raise_Constraint_Error (Sloc (E),
Reason => CE_Null_Not_Allowed);
begin
if Expander_Active then
Insert_Action (N, Not_Null_Check);
Analyze (Not_Null_Check);
elsif Warn_On_Ada_2012_Compatibility then
Error_Msg_N
("null value not allowed here in Ada 2012?y?", E);
end if;
end;
end if;
-- Check for missing initialization. Skip this check if we already
-- had errors on analyzing the allocator, since in that case these
-- are probably cascaded errors.
if not Is_Definite_Subtype (Type_Id)
and then Serious_Errors_Detected = Sav_Errs
then
-- The build-in-place machinery may produce an allocator when
-- the designated type is indefinite but the underlying type is
-- not. In this case the unknown discriminants are meaningless
-- and should not trigger error messages. Check the parent node
-- because the allocator is marked as coming from source.
if Present (Underlying_Type (Type_Id))
and then Is_Definite_Subtype (Underlying_Type (Type_Id))
and then not Comes_From_Source (Parent (N))
then
null;
-- An unusual case arises when the parent of a derived type is
-- a limited record extension with unknown discriminants, and
-- its full view has no discriminants.
--
-- A more general fix might be to create the proper underlying
-- type for such a derived type, but it is a record type with
-- no private attributes, so this required extending the
-- meaning of this attribute. ???
elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private
and then Present (Underlying_Type (Etype (Type_Id)))
and then
not Has_Discriminants (Underlying_Type (Etype (Type_Id)))
and then not Comes_From_Source (Parent (N))
then
null;
elsif Is_Class_Wide_Type (Type_Id) then
Error_Msg_N
("initialization required in class-wide allocation", N);
else
if Ada_Version < Ada_2005
and then Is_Limited_Type (Type_Id)
then
Error_Msg_N ("unconstrained allocation not allowed", N);
if Is_Array_Type (Type_Id) then
Error_Msg_N
("\constraint with array bounds required", N);
elsif Has_Unknown_Discriminants (Type_Id) then
null;
else pragma Assert (Has_Discriminants (Type_Id));
Error_Msg_N
("\constraint with discriminant values required", N);
end if;
-- Limited Ada 2005 and general nonlimited case.
-- This is an error, except in the case of an
-- uninitialized allocator that is generated
-- for a build-in-place function return of a
-- discriminated but compile-time-known-size
-- type.
else
if Is_Rewrite_Substitution (N)
and then Nkind (Original_Node (N)) = N_Allocator
then
declare
Qual : constant Node_Id :=
Expression (Original_Node (N));
pragma Assert
(Nkind (Qual) = N_Qualified_Expression);
Call : constant Node_Id := Expression (Qual);
pragma Assert
(Is_Expanded_Build_In_Place_Call (Call));
begin
null;
end;
else
Error_Msg_N
("uninitialized unconstrained allocation not "
& "allowed", N);
if Is_Array_Type (Type_Id) then
Error_Msg_N
("\qualified expression or constraint with "
& "array bounds required", N);
elsif Has_Unknown_Discriminants (Type_Id) then
Error_Msg_N ("\qualified expression required", N);
else pragma Assert (Has_Discriminants (Type_Id));
Error_Msg_N
("\qualified expression or constraint with "
& "discriminant values required", N);
end if;
end if;
end if;
end if;
end if;
end if;
if Is_Abstract_Type (Type_Id) then
Error_Msg_N ("cannot allocate abstract object", E);
end if;
if Has_Task (Designated_Type (Acc_Type)) then
Check_Restriction (No_Tasking, N);
Check_Restriction (Max_Tasks, N);
Check_Restriction (No_Task_Allocators, N);
end if;
-- Check restriction against dynamically allocated protected objects
if Has_Protected (Designated_Type (Acc_Type)) then
Check_Restriction (No_Protected_Type_Allocators, N);
end if;
-- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
-- type is nested, and the designated type needs finalization. The rule
-- is conservative in that class-wide types need finalization.
if Needs_Finalization (Designated_Type (Acc_Type))
and then not Is_Library_Level_Entity (Acc_Type)
then
Check_Restriction (No_Nested_Finalization, N);
end if;
-- Check that an allocator of a nested access type doesn't create a
-- protected object when restriction No_Local_Protected_Objects applies.
if Has_Protected (Designated_Type (Acc_Type))
and then not Is_Library_Level_Entity (Acc_Type)
then
Check_Restriction (No_Local_Protected_Objects, N);
end if;
-- Likewise for No_Local_Timing_Events
if Has_Timing_Event (Designated_Type (Acc_Type))
and then not Is_Library_Level_Entity (Acc_Type)
then
Check_Restriction (No_Local_Timing_Events, N);
end if;
-- If the No_Streams restriction is set, check that the type of the
-- object is not, and does not contain, any subtype derived from
-- Ada.Streams.Root_Stream_Type. Note that we guard the call to
-- Has_Stream just for efficiency reasons. There is no point in
-- spending time on a Has_Stream check if the restriction is not set.
if Restriction_Check_Required (No_Streams) then
if Has_Stream (Designated_Type (Acc_Type)) then
Check_Restriction (No_Streams, N);
end if;
end if;
Set_Etype (N, Acc_Type);
if not Is_Library_Level_Entity (Acc_Type) then
Check_Restriction (No_Local_Allocators, N);
end if;
if Serious_Errors_Detected > Sav_Errs then
Set_Error_Posted (N);
Set_Etype (N, Any_Type);
end if;
end Analyze_Allocator;
---------------------------
-- Analyze_Arithmetic_Op --
---------------------------
procedure Analyze_Arithmetic_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
-- If the entity is already set, the node is the instantiation of a
-- generic node with a non-local reference, or was manufactured by a
-- call to Make_Op_xxx. In either case the entity is known to be valid,
-- and we do not need to collect interpretations, instead we just get
-- the single possible interpretation.
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Find_Arithmetic_Types (L, R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
-- Entity is not already set, so we do need to collect interpretations
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator
and then Present (Next_Entity (First_Entity (Op_Id)))
then
Find_Arithmetic_Types (L, R, Op_Id, N);
-- The following may seem superfluous, because an operator cannot
-- be generic, but this ignores the cleverness of the author of
-- ACVC bc1013a.
elsif Is_Overloadable (Op_Id) then
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
Check_Function_Writable_Actuals (N);
end Analyze_Arithmetic_Op;
------------------
-- Analyze_Call --
------------------
-- Function, procedure, and entry calls are checked here. The Name in
-- the call may be overloaded. The actuals have been analyzed and may
-- themselves be overloaded. On exit from this procedure, the node N
-- may have zero, one or more interpretations. In the first case an
-- error message is produced. In the last case, the node is flagged
-- as overloaded and the interpretations are collected in All_Interp.
-- If the name is an Access_To_Subprogram, it cannot be overloaded, but
-- the type-checking is similar to that of other calls.
procedure Analyze_Call (N : Node_Id) is
Actuals : constant List_Id := Parameter_Associations (N);
Loc : constant Source_Ptr := Sloc (N);
Nam : Node_Id;
X : Interp_Index;
It : Interp;
Nam_Ent : Entity_Id := Empty;
Success : Boolean := False;
Deref : Boolean := False;
-- Flag indicates whether an interpretation of the prefix is a
-- parameterless call that returns an access_to_subprogram.
procedure Check_Writable_Actuals (N : Node_Id);
-- If the call has out or in-out parameters then mark its outermost
-- enclosing construct as a node on which the writable actuals check
-- must be performed.
function Name_Denotes_Function return Boolean;
-- If the type of the name is an access to subprogram, this may be the
-- type of a name, or the return type of the function being called. If
-- the name is not an entity then it can denote a protected function.
-- Until we distinguish Etype from Return_Type, we must use this routine
-- to resolve the meaning of the name in the call.
procedure No_Interpretation;
-- Output error message when no valid interpretation exists
----------------------------
-- Check_Writable_Actuals --
----------------------------
-- The identification of conflicts in calls to functions with writable
-- actuals is performed in the analysis phase of the front end to ensure
-- that it reports exactly the same errors compiling with and without
-- expansion enabled. It is performed in two stages:
-- 1) When a call to a function with out-mode parameters is found,
-- we climb to the outermost enclosing construct that can be
-- evaluated in arbitrary order and we mark it with the flag
-- Check_Actuals.
-- 2) When the analysis of the marked node is complete, we traverse
-- its decorated subtree searching for conflicts (see function
-- Sem_Util.Check_Function_Writable_Actuals).
-- The unique exception to this general rule is for aggregates, since
-- their analysis is performed by the front end in the resolution
-- phase. For aggregates we do not climb to their enclosing construct:
-- we restrict the analysis to the subexpressions initializing the
-- aggregate components.
-- This implies that the analysis of expressions containing aggregates
-- is not complete, since there may be conflicts on writable actuals
-- involving subexpressions of the enclosing logical or arithmetic
-- expressions. However, we cannot wait and perform the analysis when
-- the whole subtree is resolved, since the subtrees may be transformed,
-- thus adding extra complexity and computation cost to identify and
-- report exactly the same errors compiling with and without expansion
-- enabled.
procedure Check_Writable_Actuals (N : Node_Id) is
begin
if Comes_From_Source (N)
and then Present (Get_Subprogram_Entity (N))
and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
then
-- For procedures and entries there is no need to climb since
-- we only need to check if the actuals of this call invoke
-- functions whose out-mode parameters overlap.
if Nkind (N) /= N_Function_Call then
Set_Check_Actuals (N);
-- For calls to functions we climb to the outermost enclosing
-- construct where the out-mode actuals of this function may
-- introduce conflicts.
else
declare
Outermost : Node_Id := Empty; -- init to avoid warning
P : Node_Id := N;
begin
while Present (P) loop
-- For object declarations we can climb to the node from
-- its object definition branch or from its initializing
-- expression. We prefer to mark the child node as the
-- outermost construct to avoid adding further complexity
-- to the routine that will later take care of
-- performing the writable actuals check.
if Has_Arbitrary_Evaluation_Order (Nkind (P))
and then Nkind (P) not in
N_Assignment_Statement | N_Object_Declaration
then
Outermost := P;
end if;
-- Avoid climbing more than needed
exit when Stop_Subtree_Climbing (Nkind (P))
or else (Nkind (P) = N_Range
and then
Nkind (Parent (P)) not in N_In | N_Not_In);
P := Parent (P);
end loop;
Set_Check_Actuals (Outermost);
end;
end if;
end if;
end Check_Writable_Actuals;
---------------------------
-- Name_Denotes_Function --
---------------------------
function Name_Denotes_Function return Boolean is
begin
if Is_Entity_Name (Nam) then
return Ekind (Entity (Nam)) = E_Function;
elsif Nkind (Nam) = N_Selected_Component then
return Ekind (Entity (Selector_Name (Nam))) = E_Function;
else
return False;
end if;
end Name_Denotes_Function;
-----------------------
-- No_Interpretation --
-----------------------
procedure No_Interpretation is
L : constant Boolean := Is_List_Member (N);
K : constant Node_Kind := Nkind (Parent (N));
begin
-- If the node is in a list whose parent is not an expression then it
-- must be an attempted procedure call.
if L and then K not in N_Subexpr then
if Ekind (Entity (Nam)) = E_Generic_Procedure then
Error_Msg_NE
("must instantiate generic procedure& before call",
Nam, Entity (Nam));
else
Error_Msg_N ("procedure or entry name expected", Nam);
end if;
-- Check for tasking cases where only an entry call will do
elsif not L
and then K in N_Entry_Call_Alternative | N_Triggering_Alternative
then
Error_Msg_N ("entry name expected", Nam);
-- Otherwise give general error message
else
Error_Msg_N ("invalid prefix in call", Nam);
end if;
end No_Interpretation;
-- Start of processing for Analyze_Call
begin
-- Initialize the type of the result of the call to the error type,
-- which will be reset if the type is successfully resolved.
Set_Etype (N, Any_Type);
Nam := Name (N);
if not Is_Overloaded (Nam) then
-- Only one interpretation to check
if Ekind (Etype (Nam)) = E_Subprogram_Type then
Nam_Ent := Etype (Nam);
-- If the prefix is an access_to_subprogram, this may be an indirect
-- call. This is the case if the name in the call is not an entity
-- name, or if it is a function name in the context of a procedure
-- call. In this latter case, we have a call to a parameterless
-- function that returns a pointer_to_procedure which is the entity
-- being called. Finally, F (X) may be a call to a parameterless
-- function that returns a pointer to a function with parameters.
-- Note that if F returns an access-to-subprogram whose designated
-- type is an array, F (X) cannot be interpreted as an indirect call
-- through the result of the call to F.
elsif Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
and then
(not Name_Denotes_Function
or else Nkind (N) = N_Procedure_Call_Statement
or else
(Nkind (Parent (N)) /= N_Explicit_Dereference
and then Is_Entity_Name (Nam)
and then No (First_Formal (Entity (Nam)))
and then not
Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
and then Present (Actuals)))
then
Nam_Ent := Designated_Type (Etype (Nam));
Insert_Explicit_Dereference (Nam);
-- Selected component case. Simple entry or protected operation,
-- where the entry name is given by the selector name.
elsif Nkind (Nam) = N_Selected_Component then
Nam_Ent := Entity (Selector_Name (Nam));
if Ekind (Nam_Ent) not in E_Entry
| E_Entry_Family
| E_Function
| E_Procedure
then
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
end if;
-- If the name is an Indexed component, it can be a call to a member
-- of an entry family. The prefix must be a selected component whose
-- selector is the entry. Analyze_Procedure_Call normalizes several
-- kinds of call into this form.
elsif Nkind (Nam) = N_Indexed_Component then
if Nkind (Prefix (Nam)) = N_Selected_Component then
Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
else
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
end if;
elsif not Is_Entity_Name (Nam) then
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
else
Nam_Ent := Entity (Nam);
-- If not overloadable, this may be a generalized indexing
-- operation with named associations. Rewrite again as an
-- indexed component and analyze as container indexing.
if not Is_Overloadable (Nam_Ent) then
if Present
(Find_Value_Of_Aspect
(Etype (Nam_Ent), Aspect_Constant_Indexing))
then
Replace (N,
Make_Indexed_Component (Sloc (N),
Prefix => Nam,
Expressions => Parameter_Associations (N)));
if Try_Container_Indexing (N, Nam, Expressions (N)) then
return;
else
No_Interpretation;
end if;
else
No_Interpretation;
end if;
return;
end if;
end if;
-- Operations generated for RACW stub types are called only through
-- dispatching, and can never be the static interpretation of a call.
if Is_RACW_Stub_Type_Operation (Nam_Ent) then
No_Interpretation;
return;
end if;
Analyze_One_Call (N, Nam_Ent, True, Success);
-- If the nonoverloaded interpretation is a call to an abstract
-- nondispatching operation, then flag an error and return.
if Is_Overloadable (Nam_Ent)
and then Is_Abstract_Subprogram (Nam_Ent)
and then not Is_Dispatching_Operation (Nam_Ent)
then
Nondispatching_Call_To_Abstract_Operation (N, Nam_Ent);
return;
end if;
-- If this is an indirect call, the return type of the access_to
-- subprogram may be an incomplete type. At the point of the call,
-- use the full type if available, and at the same time update the
-- return type of the access_to_subprogram.
if Success
and then Nkind (Nam) = N_Explicit_Dereference
and then Ekind (Etype (N)) = E_Incomplete_Type
and then Present (Full_View (Etype (N)))
then
Set_Etype (N, Full_View (Etype (N)));
Set_Etype (Nam_Ent, Etype (N));
end if;
-- Overloaded call
else
-- An overloaded selected component must denote overloaded operations
-- of a concurrent type. The interpretations are attached to the
-- simple name of those operations.
if Nkind (Nam) = N_Selected_Component then
Nam := Selector_Name (Nam);
end if;
Get_First_Interp (Nam, X, It);
while Present (It.Nam) loop
Nam_Ent := It.Nam;
Deref := False;
-- Name may be call that returns an access to subprogram, or more
-- generally an overloaded expression one of whose interpretations
-- yields an access to subprogram. If the name is an entity, we do
-- not dereference, because the node is a call that returns the
-- access type: note difference between f(x), where the call may
-- return an access subprogram type, and f(x)(y), where the type
-- returned by the call to f is implicitly dereferenced to analyze
-- the outer call.
if Is_Access_Type (Nam_Ent) then
Nam_Ent := Designated_Type (Nam_Ent);
elsif Is_Access_Type (Etype (Nam_Ent))
and then
(not Is_Entity_Name (Nam)
or else Nkind (N) = N_Procedure_Call_Statement)
and then Ekind (Designated_Type (Etype (Nam_Ent)))
= E_Subprogram_Type
then
Nam_Ent := Designated_Type (Etype (Nam_Ent));
if Is_Entity_Name (Nam) then
Deref := True;
end if;
end if;
-- If the call has been rewritten from a prefixed call, the first
-- parameter has been analyzed, but may need a subsequent
-- dereference, so skip its analysis now.
if Is_Rewrite_Substitution (N)
and then Nkind (Original_Node (N)) = Nkind (N)
and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
and then Present (Parameter_Associations (N))
and then Present (Etype (First (Parameter_Associations (N))))
then
Analyze_One_Call
(N, Nam_Ent, False, Success, Skip_First => True);
else
Analyze_One_Call (N, Nam_Ent, False, Success);
end if;
-- If the interpretation succeeds, mark the proper type of the
-- prefix (any valid candidate will do). If not, remove the
-- candidate interpretation. If this is a parameterless call
-- on an anonymous access to subprogram, X is a variable with
-- an access discriminant D, the entity in the interpretation is
-- D, so rewrite X as X.D.all.
if Success then
if Deref
and then Nkind (Parent (N)) /= N_Explicit_Dereference
then
if Ekind (It.Nam) = E_Discriminant
and then Has_Implicit_Dereference (It.Nam)
then
Rewrite (Name (N),
Make_Explicit_Dereference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Entity (Nam), Loc),
Selector_Name =>
New_Occurrence_Of (It.Nam, Loc))));
Analyze (N);
return;
else
Set_Entity (Nam, It.Nam);
Insert_Explicit_Dereference (Nam);
Set_Etype (Nam, Nam_Ent);
end if;
else
Set_Etype (Nam, It.Typ);
end if;
elsif Nkind (Name (N)) in N_Function_Call | N_Selected_Component
then
Remove_Interp (X);
end if;
Get_Next_Interp (X, It);
end loop;
-- If the name is the result of a function call, it can only be a
-- call to a function returning an access to subprogram. Insert
-- explicit dereference.
if Nkind (Nam) = N_Function_Call then
Insert_Explicit_Dereference (Nam);
end if;
if Etype (N) = Any_Type then
-- None of the interpretations is compatible with the actuals
Diagnose_Call (N, Nam);
-- Special checks for uninstantiated put routines
if Nkind (N) = N_Procedure_Call_Statement
and then Is_Entity_Name (Nam)
and then Chars (Nam) = Name_Put
and then List_Length (Actuals) = 1
then
declare
Arg : constant Node_Id := First (Actuals);
Typ : Entity_Id;
begin
if Nkind (Arg) = N_Parameter_Association then
Typ := Etype (Explicit_Actual_Parameter (Arg));
else
Typ := Etype (Arg);
end if;
if Is_Signed_Integer_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Integer_'I'O!", Nam);
elsif Is_Modular_Integer_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Modular_'I'O!", Nam);
elsif Is_Floating_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Float_'I'O!", Nam);
elsif Is_Ordinary_Fixed_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Fixed_'I'O!", Nam);
elsif Is_Decimal_Fixed_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Decimal_'I'O!", Nam);
elsif Is_Enumeration_Type (Typ) then
Error_Msg_N
("possible missing instantiation of "
& "'Text_'I'O.'Enumeration_'I'O!", Nam);
end if;
end;
end if;
elsif not Is_Overloaded (N)
and then Is_Entity_Name (Nam)
then
-- Resolution yields a single interpretation. Verify that the
-- reference has capitalization consistent with the declaration.
Set_Entity_With_Checks (Nam, Entity (Nam));
Generate_Reference (Entity (Nam), Nam);
Set_Etype (Nam, Etype (Entity (Nam)));
else
Remove_Abstract_Operations (N);
end if;
end if;
-- Check the accessibility level for actuals for explicitly aliased
-- formals when a function call appears within a return statement.
-- This is only checked if the enclosing subprogram Comes_From_Source,
-- to avoid issuing errors on calls occurring in wrapper subprograms
-- (for example, where the call is part of an expression of an aspect
-- associated with a wrapper, such as Pre'Class).
if Nkind (N) = N_Function_Call
and then Comes_From_Source (N)
and then Present (Nam_Ent)
and then In_Return_Value (N)
and then Comes_From_Source (Current_Subprogram)
then
declare
Form : Node_Id;
Act : Node_Id;
begin
Act := First_Actual (N);
Form := First_Formal (Nam_Ent);
while Present (Form) and then Present (Act) loop
-- Check whether the formal is aliased and if the accessibility
-- level of the actual is deeper than the accessibility level
-- of the enclosing subprogram to which the current return
-- statement applies.
-- Should we be checking Is_Entity_Name on Act? Won't this miss
-- other cases ???
if Is_Explicitly_Aliased (Form)
and then Is_Entity_Name (Act)
and then Static_Accessibility_Level
(Act, Zero_On_Dynamic_Level)
> Subprogram_Access_Level (Current_Subprogram)
then
Error_Msg_N ("actual for explicitly aliased formal is too"
& " short lived", Act);
end if;
Next_Formal (Form);
Next_Actual (Act);
end loop;
end;
end if;
if Ada_Version >= Ada_2012 then
-- Check if the call contains a function with writable actuals
Check_Writable_Actuals (N);
-- If found and the outermost construct that can be evaluated in
-- an arbitrary order is precisely this call, then check all its
-- actuals.
Check_Function_Writable_Actuals (N);
-- The return type of the function may be incomplete. This can be
-- the case if the type is a generic formal, or a limited view. It
-- can also happen when the function declaration appears before the
-- full view of the type (which is legal in Ada 2012) and the call
-- appears in a different unit, in which case the incomplete view
-- must be replaced with the full view (or the nonlimited view)
-- to prevent subsequent type errors. Note that the usual install/
-- removal of limited_with clauses is not sufficient to handle this
-- case, because the limited view may have been captured in another
-- compilation unit that defines the current function.
if Is_Incomplete_Type (Etype (N)) then
if Present (Full_View (Etype (N))) then
if Is_Entity_Name (Nam) then
Set_Etype (Nam, Full_View (Etype (N)));
Set_Etype (Entity (Nam), Full_View (Etype (N)));
end if;
Set_Etype (N, Full_View (Etype (N)));
elsif From_Limited_With (Etype (N))
and then Present (Non_Limited_View (Etype (N)))
then
Set_Etype (N, Non_Limited_View (Etype (N)));
-- If there is no completion for the type, this may be because
-- there is only a limited view of it and there is nothing in
-- the context of the current unit that has required a regular
-- compilation of the unit containing the type. We recognize
-- this unusual case by the fact that unit is not analyzed.
-- Note that the call being analyzed is in a different unit from
-- the function declaration, and nothing indicates that the type
-- is a limited view.
elsif Ekind (Scope (Etype (N))) = E_Package
and then Present (Limited_View (Scope (Etype (N))))
and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N))))
then
Error_Msg_NE
("cannot call function that returns limited view of}",
N, Etype (N));
Error_Msg_NE
("\there must be a regular with_clause for package & in the "
& "current unit, or in some unit in its context",
N, Scope (Etype (N)));
Set_Etype (N, Any_Type);
end if;
end if;
end if;
end Analyze_Call;
-----------------------------
-- Analyze_Case_Expression --
-----------------------------
procedure Analyze_Case_Expression (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
First_Alt : constant Node_Id := First (Alternatives (N));
First_Expr : Node_Id := Empty;
-- First expression in the case where there is some type information
-- available, i.e. there is not Any_Type everywhere, which can happen
-- because of some error.
Second_Expr : Node_Id := Empty;
-- Second expression as above
Wrong_Alt : Node_Id := Empty;
-- For error reporting
procedure Non_Static_Choice_Error (Choice : Node_Id);
-- Error routine invoked by the generic instantiation below when
-- the case expression has a non static choice.
procedure Check_Next_Expression (T : Entity_Id; Alt : Node_Id);
-- Check one interpretation of the next expression with type T
procedure Check_Expression_Pair (T1, T2 : Entity_Id; Alt : Node_Id);
-- Check first expression with type T1 and next expression with type T2
package Case_Choices_Analysis is new
Generic_Analyze_Choices
(Process_Associated_Node => No_OP);
use Case_Choices_Analysis;
package Case_Choices_Checking is new
Generic_Check_Choices
(Process_Empty_Choice => No_OP,
Process_Non_Static_Choice => Non_Static_Choice_Error,
Process_Associated_Node => No_OP);
use Case_Choices_Checking;
-----------------------------
-- Non_Static_Choice_Error --
-----------------------------
procedure Non_Static_Choice_Error (Choice : Node_Id) is
begin
Flag_Non_Static_Expr
("choice given in case expression is not static!", Choice);
end Non_Static_Choice_Error;
---------------------------
-- Check_Next_Expression --
---------------------------
procedure Check_Next_Expression (T : Entity_Id; Alt : Node_Id) is
Next_Expr : constant Node_Id := Expression (Alt);
I : Interp_Index;
It : Interp;
begin
if Next_Expr = First_Expr then
Check_Next_Expression (T, Next (Alt));
return;
end if;
-- Loop through the interpretations of the next expression
if not Is_Overloaded (Next_Expr) then
Check_Expression_Pair (T, Etype (Next_Expr), Alt);
else
Get_First_Interp (Next_Expr, I, It);
while Present (It.Typ) loop
Check_Expression_Pair (T, It.Typ, Alt);
Get_Next_Interp (I, It);
end loop;
end if;
end Check_Next_Expression;
---------------------------
-- Check_Expression_Pair --
---------------------------
procedure Check_Expression_Pair (T1, T2 : Entity_Id; Alt : Node_Id) is
Next_Expr : constant Node_Id := Expression (Alt);
T : Entity_Id;
begin
if Covers (T1 => T1, T2 => T2)
or else Covers (T1 => T2, T2 => T1)
then
T := Specific_Type (T1, T2);
elsif Is_User_Defined_Literal (First_Expr, T2) then
T := T2;
elsif Is_User_Defined_Literal (Next_Expr, T1) then
T := T1;
else
T := Possible_Type_For_Conditional_Expression (T1, T2);
if No (T) then
Wrong_Alt := Alt;
return;
end if;
end if;
if Present (Next (Alt)) then
Check_Next_Expression (T, Next (Alt));
else
Add_One_Interp (N, T, T);
end if;
end Check_Expression_Pair;
-- Local variables
Alt : Node_Id;
Exp_Type : Entity_Id;
Exp_Btype : Entity_Id;
I : Interp_Index;
It : Interp;
Others_Present : Boolean;
-- Start of processing for Analyze_Case_Expression
begin
Analyze_And_Resolve (Expr, Any_Discrete);
Check_Unset_Reference (Expr);
Exp_Type := Etype (Expr);
Exp_Btype := Base_Type (Exp_Type);
Set_Etype (N, Any_Type);
Alt := First_Alt;
while Present (Alt) loop
if Error_Posted (Expression (Alt)) then
return;
end if;
Analyze_Expression (Expression (Alt));
if Etype (Expression (Alt)) /= Any_Type then
if No (First_Expr) then
First_Expr := Expression (Alt);
elsif No (Second_Expr) then
Second_Expr := Expression (Alt);
end if;
end if;
Next (Alt);
end loop;
-- Get our initial type from the first expression for which we got some
-- useful type information from the expression.
if No (First_Expr) then
return;
end if;
-- The expression must be of a discrete type which must be determinable
-- independently of the context in which the expression occurs, but
-- using the fact that the expression must be of a discrete type.
-- Moreover, the type this expression must not be a character literal
-- (which is always ambiguous).
-- If error already reported by Resolve, nothing more to do
if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
return;
-- Special case message for character literal
elsif Exp_Btype = Any_Character then
Error_Msg_N
("character literal as case expression is ambiguous", Expr);
return;
end if;
-- If the case expression is a formal object of mode in out, then
-- treat it as having a nonstatic subtype by forcing use of the base
-- type (which has to get passed to Check_Case_Choices below). Also
-- use base type when the case expression is parenthesized.
if Paren_Count (Expr) > 0
or else (Is_Entity_Name (Expr)
and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
then
Exp_Type := Exp_Btype;
end if;
-- The case expression alternatives cover the range of a static subtype
-- subject to aspect Static_Predicate. Do not check the choices when the
-- case expression has not been fully analyzed yet because this may lead
-- to bogus errors.
if Is_OK_Static_Subtype (Exp_Type)
and then Has_Static_Predicate_Aspect (Exp_Type)
and then In_Spec_Expression
then
null;
-- Call Analyze_Choices and Check_Choices to do the rest of the work
else
Analyze_Choices (Alternatives (N), Exp_Type);
Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
if Exp_Type = Universal_Integer and then not Others_Present then
Error_Msg_N
("case on universal integer requires OTHERS choice", Expr);
return;
end if;
end if;
-- RM 4.5.7(10/3): If the case_expression is the operand of a type
-- conversion, the type of the case_expression is the target type
-- of the conversion.
if Nkind (Parent (N)) = N_Type_Conversion then
Set_Etype (N, Etype (Parent (N)));
return;
end if;
-- Loop through the interpretations of the first expression and check
-- the other expressions if present.
if not Is_Overloaded (First_Expr) then
if Present (Second_Expr) then
Check_Next_Expression (Etype (First_Expr), First_Alt);
else
Set_Etype (N, Etype (First_Expr));
end if;
else
Get_First_Interp (First_Expr, I, It);
while Present (It.Typ) loop
if Present (Second_Expr) then
Check_Next_Expression (It.Typ, First_Alt);
else
Add_One_Interp (N, It.Typ, It.Typ);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- If no possible interpretation has been found, the type of the wrong
-- alternative doesn't match any interpretation of the FIRST expression.
if Etype (N) = Any_Type and then Present (Wrong_Alt) then
Second_Expr := Expression (Wrong_Alt);
if Is_Overloaded (First_Expr) then
if Is_Overloaded (Second_Expr) then
Error_Msg_N
("no interpretation compatible with those of previous "
& "alternative",
Second_Expr);
else
Error_Msg_N
("type incompatible with interpretations of previous "
& "alternative",
Second_Expr);
Error_Msg_NE
("\this alternative has}!",
Second_Expr,
Etype (Second_Expr));
end if;
else
if Is_Overloaded (Second_Expr) then
Error_Msg_N
("no interpretation compatible with type of previous "
& "alternative",
Second_Expr);
Error_Msg_NE
("\previous alternative has}!",
Second_Expr,
Etype (First_Expr));
else
Error_Msg_N
("type incompatible with that of previous alternative",
Second_Expr);
Error_Msg_NE
("\previous alternative has}!",
Second_Expr,
Etype (First_Expr));
Error_Msg_NE
("\this alternative has}!",
Second_Expr,
Etype (Second_Expr));
end if;
end if;
end if;
end Analyze_Case_Expression;
---------------------------
-- Analyze_Concatenation --
---------------------------
procedure Analyze_Concatenation (N : Node_Id) is
-- We wish to avoid deep recursion, because concatenations are often
-- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
-- operands nonrecursively until we find something that is not a
-- concatenation (A in this case), or has already been analyzed. We
-- analyze that, and then walk back up the tree following Parent
-- pointers, calling Analyze_Concatenation_Rest to do the rest of the
-- work at each level. The Parent pointers allow us to avoid recursion,
-- and thus avoid running out of memory.
NN : Node_Id := N;
L : Node_Id;
begin
Candidate_Type := Empty;
-- The following code is equivalent to:
-- Set_Etype (N, Any_Type);
-- Analyze_Expression (Left_Opnd (N));
-- Analyze_Concatenation_Rest (N);
-- where the Analyze_Expression call recurses back here if the left
-- operand is a concatenation.
-- Walk down left operands
loop
Set_Etype (NN, Any_Type);
L := Left_Opnd (NN);
exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
NN := L;
end loop;
-- Now (given the above example) NN is A&B and L is A
-- First analyze L ...
Analyze_Expression (L);
-- ... then walk NN back up until we reach N (where we started), calling
-- Analyze_Concatenation_Rest along the way.
loop
Analyze_Concatenation_Rest (NN);
exit when NN = N;
NN := Parent (NN);
end loop;
end Analyze_Concatenation;
--------------------------------
-- Analyze_Concatenation_Rest --
--------------------------------
-- If the only one-dimensional array type in scope is String,
-- this is the resulting type of the operation. Otherwise there
-- will be a concatenation operation defined for each user-defined
-- one-dimensional array.
procedure Analyze_Concatenation_Rest (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
LT : Entity_Id;
RT : Entity_Id;
begin
Analyze_Expression (R);
-- If the entity is present, the node appears in an instance, and
-- denotes a predefined concatenation operation. The resulting type is
-- obtained from the arguments when possible. If the arguments are
-- aggregates, the array type and the concatenation type must be
-- visible.
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
LT := Base_Type (Etype (L));
RT := Base_Type (Etype (R));
if Is_Array_Type (LT)
and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
then
Add_One_Interp (N, Op_Id, LT);
elsif Is_Array_Type (RT)
and then LT = Base_Type (Component_Type (RT))
then
Add_One_Interp (N, Op_Id, RT);
-- If one operand is a string type or a user-defined array type,
-- and the other is a literal, result is of the specific type.
elsif
(Root_Type (LT) = Standard_String
or else Scope (LT) /= Standard_Standard)
and then Etype (R) = Any_String
then
Add_One_Interp (N, Op_Id, LT);
elsif
(Root_Type (RT) = Standard_String
or else Scope (RT) /= Standard_Standard)
and then Etype (L) = Any_String
then
Add_One_Interp (N, Op_Id, RT);
elsif not Is_Generic_Type (Etype (Op_Id)) then
Add_One_Interp (N, Op_Id, Etype (Op_Id));
else
-- Type and its operations must be visible
Set_Entity (N, Empty);
Analyze_Concatenation (N);
end if;
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
-- Do not consider operators declared in dead code, they
-- cannot be part of the resolution.
if Is_Eliminated (Op_Id) then
null;
else
Find_Concatenation_Types (L, R, Op_Id, N);
end if;
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Concatenation_Rest;
------------------------------------
-- Analyze_Comparison_Equality_Op --
------------------------------------
procedure Analyze_Comparison_Equality_Op (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
-- If the entity is set, the node is a generic instance with a non-local
-- reference to the predefined operator or to a user-defined function.
-- It can also be an inequality that is expanded into the negation of a
-- call to a user-defined equality operator.
-- For the predefined case, the result is Boolean, regardless of the
-- type of the operands. The operands may even be limited, if they are
-- generic actuals. If they are overloaded, label the operands with the
-- common type that must be present, or with the type of the formal of
-- the user-defined function.
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Add_One_Interp (N, Op_Id, Standard_Boolean);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
if Is_Overloaded (L) then
if Ekind (Op_Id) = E_Operator then
Set_Etype (L, Intersect_Types (L, R));
else
Set_Etype (L, Etype (First_Formal (Op_Id)));
end if;
end if;
if Is_Overloaded (R) then
if Ekind (Op_Id) = E_Operator then
Set_Etype (R, Intersect_Types (L, R));
else
Set_Etype (R, Etype (Next_Formal (First_Formal (Op_Id))));
end if;
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Comparison_Equality_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
-- If there was no match, and the operator is inequality, this may be
-- a case where inequality has not been made explicit, as for tagged
-- types. Analyze the node as the negation of an equality operation.
-- This cannot be done earlier, because before analysis we cannot rule
-- out the presence of an explicit inequality.
if Etype (N) = Any_Type
and then Nkind (N) = N_Op_Ne
then
Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Comparison_Equality_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
if Etype (N) /= Any_Type then
Op_Id := Entity (N);
Rewrite (N,
Make_Op_Not (Loc,
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Left_Opnd (N),
Right_Opnd => Right_Opnd (N))));
Set_Entity (Right_Opnd (N), Op_Id);
Analyze (N);
end if;
end if;
Operator_Check (N);
Check_Function_Writable_Actuals (N);
end Analyze_Comparison_Equality_Op;
----------------------------------
-- Analyze_Explicit_Dereference --
----------------------------------
procedure Analyze_Explicit_Dereference (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Prefix (N);
T : Entity_Id;
I : Interp_Index;
It : Interp;
New_N : Node_Id;
function Is_Function_Type return Boolean;
-- Check whether node may be interpreted as an implicit function call
----------------------
-- Is_Function_Type --
----------------------
function Is_Function_Type return Boolean is
I : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (N) then
return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
else
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
then
return False;
end if;
Get_Next_Interp (I, It);
end loop;
return True;
end if;
end Is_Function_Type;
-- Start of processing for Analyze_Explicit_Dereference
begin
-- In formal verification mode, keep track of all reads and writes
-- through explicit dereferences.
if GNATprove_Mode then
SPARK_Specific.Generate_Dereference (N);
end if;
Analyze (P);
Set_Etype (N, Any_Type);
-- Test for remote access to subprogram type, and if so return
-- after rewriting the original tree.
if Remote_AST_E_Dereference (P) then
return;
end if;
-- Normal processing for other than remote access to subprogram type
if not Is_Overloaded (P) then
if Is_Access_Type (Etype (P)) then
-- Set the Etype
declare
DT : constant Entity_Id := Designated_Type (Etype (P));
begin
-- An explicit dereference is a legal occurrence of an
-- incomplete type imported through a limited_with clause, if
-- the full view is visible, or if we are within an instance
-- body, where the enclosing body has a regular with_clause
-- on the unit.
if From_Limited_With (DT)
and then not From_Limited_With (Scope (DT))
and then
(Is_Immediately_Visible (Scope (DT))
or else
(Is_Child_Unit (Scope (DT))
and then Is_Visible_Lib_Unit (Scope (DT)))
or else In_Instance_Body)
then
Set_Etype (N, Available_View (DT));
else
Set_Etype (N, DT);
end if;
end;
elsif Etype (P) /= Any_Type then
Error_Msg_N ("prefix of dereference must be an access type", N);
return;
end if;
else
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
T := It.Typ;
if Is_Access_Type (T) then
Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
end if;
Get_Next_Interp (I, It);
end loop;
-- Error if no interpretation of the prefix has an access type
if Etype (N) = Any_Type then
Error_Msg_N
("access type required in prefix of explicit dereference", P);
Set_Etype (N, Any_Type);
return;
end if;
end if;
if Is_Function_Type
and then Nkind (Parent (N)) /= N_Indexed_Component
and then (Nkind (Parent (N)) /= N_Function_Call
or else N /= Name (Parent (N)))
and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
or else N /= Name (Parent (N)))
and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
and then (Nkind (Parent (N)) /= N_Attribute_Reference
or else
(Attribute_Name (Parent (N)) /= Name_Address
and then
Attribute_Name (Parent (N)) /= Name_Access))
then
-- Name is a function call with no actuals, in a context that
-- requires deproceduring (including as an actual in an enclosing
-- function or procedure call). There are some pathological cases
-- where the prefix might include functions that return access to
-- subprograms and others that return a regular type. Disambiguation
-- of those has to take place in Resolve.
New_N :=
Make_Function_Call (Loc,
Name => Make_Explicit_Dereference (Loc, P),
Parameter_Associations => New_List);
-- If the prefix is overloaded, remove operations that have formals,
-- we know that this is a parameterless call.
if Is_Overloaded (P) then
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
T := It.Typ;
if No (First_Formal (Base_Type (Designated_Type (T)))) then
Set_Etype (P, T);
else
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
Rewrite (N, New_N);
Analyze (N);
elsif not Is_Function_Type
and then Is_Overloaded (N)
then
-- The prefix may include access to subprograms and other access
-- types. If the context selects the interpretation that is a
-- function call (not a procedure call) we cannot rewrite the node
-- yet, but we include the result of the call interpretation.
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
then
Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- A value of remote access-to-class-wide must not be dereferenced
-- (RM E.2.2(16)).
Validate_Remote_Access_To_Class_Wide_Type (N);
end Analyze_Explicit_Dereference;
------------------------
-- Analyze_Expression --
------------------------
procedure Analyze_Expression (N : Node_Id) is
begin
-- If the expression is an indexed component that will be rewritten
-- as a container indexing, it has already been analyzed.
if Nkind (N) = N_Indexed_Component
and then Present (Generalized_Indexing (N))
then
null;
else
Analyze (N);
Check_Parameterless_Call (N);
end if;
end Analyze_Expression;
-------------------------------------
-- Analyze_Expression_With_Actions --
-------------------------------------
procedure Analyze_Expression_With_Actions (N : Node_Id) is
procedure Check_Action_OK (A : Node_Id);
-- Check that the action A is allowed as a declare_item of a declare
-- expression if N and A come from source.
---------------------
-- Check_Action_OK --
---------------------
procedure Check_Action_OK (A : Node_Id) is
begin
if not Comes_From_Source (N) or else not Comes_From_Source (A) then
return; -- Allow anything in generated code
end if;
case Nkind (A) is
when N_Object_Declaration =>
if Nkind (Object_Definition (A)) = N_Access_Definition then
Error_Msg_N
("anonymous access type not allowed in declare_expression",
Object_Definition (A));
end if;
if Aliased_Present (A) then
Error_Msg_N ("ALIASED not allowed in declare_expression", A);
end if;
if Constant_Present (A)
and then not Is_Limited_Type (Etype (Defining_Identifier (A)))
then
return; -- nonlimited constants are OK
end if;
when N_Object_Renaming_Declaration =>
if Present (Access_Definition (A)) then
Error_Msg_N
("anonymous access type not allowed in declare_expression",
Access_Definition (A));
end if;
if not Is_Limited_Type (Etype (Defining_Identifier (A))) then
return; -- ???For now; the RM rule is a bit more complicated
end if;
when others =>
null; -- Nothing else allowed, not even pragmas
end case;
Error_Msg_N ("object renaming or constant declaration expected", A);
end Check_Action_OK;
A : Node_Id;
EWA_Scop : Entity_Id;
-- Start of processing for Analyze_Expression_With_Actions
begin
-- Create a scope, which is needed to provide proper visibility of the
-- declare_items.
EWA_Scop := New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
Set_Etype (EWA_Scop, Standard_Void_Type);
Set_Scope (EWA_Scop, Current_Scope);
Set_Parent (EWA_Scop, N);
Push_Scope (EWA_Scop);
-- If this Expression_With_Actions node comes from source, then it
-- represents a declare_expression; increment the counter to take note
-- of that.
if Comes_From_Source (N) then
In_Declare_Expr := In_Declare_Expr + 1;
end if;
A := First (Actions (N));
while Present (A) loop
Analyze (A);
Check_Action_OK (A);
Next (A);
end loop;
Analyze_Expression (Expression (N));
Set_Etype (N, Etype (Expression (N)));
End_Scope;
if Comes_From_Source (N) then
In_Declare_Expr := In_Declare_Expr - 1;
end if;
end Analyze_Expression_With_Actions;
---------------------------
-- Analyze_If_Expression --
---------------------------
procedure Analyze_If_Expression (N : Node_Id) is
Condition : constant Node_Id := First (Expressions (N));
Then_Expr : Node_Id;
Else_Expr : Node_Id;
procedure Check_Else_Expression (T : Entity_Id);
-- Check one interpretation of the THEN expression with type T
procedure Check_Expression_Pair (T1, T2 : Entity_Id);
-- Check THEN expression with type T1 and ELSE expression with type T2
---------------------------
-- Check_Else_Expression --
---------------------------
procedure Check_Else_Expression (T : Entity_Id) is
I : Interp_Index;
It : Interp;
begin
-- Loop through the interpretations of the ELSE expression
if not Is_Overloaded (Else_Expr) then
Check_Expression_Pair (T, Etype (Else_Expr));
else
Get_First_Interp (Else_Expr, I, It);
while Present (It.Typ) loop
Check_Expression_Pair (T, It.Typ);
Get_Next_Interp (I, It);
end loop;
end if;
end Check_Else_Expression;
---------------------------
-- Check_Expression_Pair --
---------------------------
procedure Check_Expression_Pair (T1, T2 : Entity_Id) is
T : Entity_Id;
begin
if Covers (T1 => T1, T2 => T2)
or else Covers (T1 => T2, T2 => T1)
then
T := Specific_Type (T1, T2);
elsif Is_User_Defined_Literal (Then_Expr, T2) then
T := T2;
elsif Is_User_Defined_Literal (Else_Expr, T1) then
T := T1;
else
T := Possible_Type_For_Conditional_Expression (T1, T2);
if No (T) then
return;
end if;
end if;
Add_One_Interp (N, T, T);
end Check_Expression_Pair;
-- Local variables
I : Interp_Index;
It : Interp;
-- Start of processing for Analyze_If_Expression
begin
-- Defend against error of missing expressions from previous error
if No (Condition) then
Check_Error_Detected;
return;
end if;
Set_Etype (N, Any_Type);
Then_Expr := Next (Condition);
if No (Then_Expr) then
Check_Error_Detected;
return;
end if;
Else_Expr := Next (Then_Expr);
-- Analyze and resolve the condition. We need to resolve this now so
-- that it gets folded to True/False if possible, before we analyze
-- the THEN/ELSE branches, because when analyzing these branches, we
-- may call Is_Statically_Unevaluated, which expects the condition of
-- an enclosing IF to have been analyze/resolved/evaluated.
Analyze_Expression (Condition);
Resolve (Condition, Any_Boolean);
-- Analyze the THEN expression and (if present) the ELSE expression. For
-- them we delay resolution in the normal manner because of overloading.
Analyze_Expression (Then_Expr);
if Present (Else_Expr) then
Analyze_Expression (Else_Expr);
end if;
-- RM 4.5.7(10/3): If the if_expression is the operand of a type
-- conversion, the type of the if_expression is the target type
-- of the conversion.
if Nkind (Parent (N)) = N_Type_Conversion then
Set_Etype (N, Etype (Parent (N)));
return;
end if;
-- Loop through the interpretations of the THEN expression and check the
-- ELSE expression if present.
if not Is_Overloaded (Then_Expr) then
if Present (Else_Expr) then
Check_Else_Expression (Etype (Then_Expr));
else
Set_Etype (N, Etype (Then_Expr));
end if;
else
Get_First_Interp (Then_Expr, I, It);
while Present (It.Typ) loop
if Present (Else_Expr) then
Check_Else_Expression (It.Typ);
else
Add_One_Interp (N, It.Typ, It.Typ);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
-- If no possible interpretation has been found, the type of the
-- ELSE expression does not match any interpretation of the THEN
-- expression.
if Etype (N) = Any_Type then
if Is_Overloaded (Then_Expr) then
if Is_Overloaded (Else_Expr) then
Error_Msg_N
("no interpretation compatible with those of THEN expression",
Else_Expr);
else
Error_Msg_N
("type of ELSE incompatible with interpretations of THEN "
& "expression",
Else_Expr);
Error_Msg_NE
("\ELSE expression has}!", Else_Expr, Etype (Else_Expr));
end if;
else
if Is_Overloaded (Else_Expr) then
Error_Msg_N
("no interpretation compatible with type of THEN expression",
Else_Expr);
Error_Msg_NE
("\THEN expression has}!", Else_Expr, Etype (Then_Expr));
else
Error_Msg_N
("type of ELSE incompatible with that of THEN expression",
Else_Expr);
Error_Msg_NE
("\THEN expression has}!", Else_Expr, Etype (Then_Expr));
Error_Msg_NE
("\ELSE expression has}!", Else_Expr, Etype (Else_Expr));
end if;
end if;
end if;
end Analyze_If_Expression;
------------------------------------
-- Analyze_Indexed_Component_Form --
------------------------------------
procedure Analyze_Indexed_Component_Form (N : Node_Id) is
P : constant Node_Id := Prefix (N);
Exprs : constant List_Id := Expressions (N);
Exp : Node_Id;
P_T : Entity_Id;
E : Node_Id;
U_N : Entity_Id;
procedure Process_Function_Call;
-- Prefix in indexed component form is an overloadable entity, so the
-- node is very likely a function call; reformat it as such. The only
-- exception is a call to a parameterless function that returns an
-- array type, or an access type thereof, in which case this will be
-- undone later by Resolve_Call or Resolve_Entry_Call.
procedure Process_Indexed_Component;
-- Prefix in indexed component form is actually an indexed component.
-- This routine processes it, knowing that the prefix is already
-- resolved.
procedure Process_Indexed_Component_Or_Slice;
-- An indexed component with a single index may designate a slice if
-- the index is a subtype mark. This routine disambiguates these two
-- cases by resolving the prefix to see if it is a subtype mark.
procedure Process_Overloaded_Indexed_Component;
-- If the prefix of an indexed component is overloaded, the proper
-- interpretation is selected by the index types and the context.
---------------------------
-- Process_Function_Call --
---------------------------
procedure Process_Function_Call is
Loc : constant Source_Ptr := Sloc (N);
Actual : Node_Id;
begin
Change_Node (N, N_Function_Call);
Set_Name (N, P);
Set_Parameter_Associations (N, Exprs);
-- Analyze actuals prior to analyzing the call itself
Actual := First (Parameter_Associations (N));
while Present (Actual) loop
Analyze (Actual);
Check_Parameterless_Call (Actual);
-- Move to next actual. Note that we use Next, not Next_Actual
-- here. The reason for this is a bit subtle. If a function call
-- includes named associations, the parser recognizes the node
-- as a call, and it is analyzed as such. If all associations are
-- positional, the parser builds an indexed_component node, and
-- it is only after analysis of the prefix that the construct
-- is recognized as a call, in which case Process_Function_Call
-- rewrites the node and analyzes the actuals. If the list of
-- actuals is malformed, the parser may leave the node as an
-- indexed component (despite the presence of named associations).
-- The iterator Next_Actual is equivalent to Next if the list is
-- positional, but follows the normalized chain of actuals when
-- named associations are present. In this case normalization has
-- not taken place, and actuals remain unanalyzed, which leads to
-- subsequent crashes or loops if there is an attempt to continue
-- analysis of the program.
-- IF there is a single actual and it is a type name, the node
-- can only be interpreted as a slice of a parameterless call.
-- Rebuild the node as such and analyze.
if No (Next (Actual))
and then Is_Entity_Name (Actual)
and then Is_Type (Entity (Actual))
and then Is_Discrete_Type (Entity (Actual))
and then not Is_Current_Instance (Actual)
then
Replace (N,
Make_Slice (Loc,
Prefix => P,
Discrete_Range =>
New_Occurrence_Of (Entity (Actual), Loc)));
Analyze (N);
return;
else
Next (Actual);
end if;
end loop;
Analyze_Call (N);
end Process_Function_Call;
-------------------------------
-- Process_Indexed_Component --
-------------------------------
procedure Process_Indexed_Component is
Exp : Node_Id;
Array_Type : Entity_Id;
Index : Node_Id;
Pent : Entity_Id := Empty;
begin
Exp := First (Exprs);
if Is_Overloaded (P) then
Process_Overloaded_Indexed_Component;
else
Array_Type := Etype (P);
if Is_Entity_Name (P) then
Pent := Entity (P);
elsif Nkind (P) = N_Selected_Component
and then Is_Entity_Name (Selector_Name (P))
then
Pent := Entity (Selector_Name (P));
end if;
-- Prefix must be appropriate for an array type, taking into
-- account a possible implicit dereference.
if Is_Access_Type (Array_Type) then
Error_Msg_NW
(Warn_On_Dereference, "?d?implicit dereference", N);
Array_Type := Implicitly_Designated_Type (Array_Type);
end if;
if Is_Array_Type (Array_Type) then
-- In order to correctly access First_Index component later,
-- replace string literal subtype by its parent type.
if Ekind (Array_Type) = E_String_Literal_Subtype then
Array_Type := Etype (Array_Type);
end if;
elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
Analyze (Exp);
Set_Etype (N, Any_Type);
if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
Error_Msg_N ("invalid index type in entry name", N);
elsif Present (Next (Exp)) then
Error_Msg_N ("too many subscripts in entry reference", N);
else
Set_Etype (N, Etype (P));
end if;
return;
elsif Is_Record_Type (Array_Type)
and then Remote_AST_I_Dereference (P)
then
return;
elsif Try_Container_Indexing (N, P, Exprs) then
return;
elsif Array_Type = Any_Type then
Set_Etype (N, Any_Type);
-- In most cases the analysis of the prefix will have emitted
-- an error already, but if the prefix may be interpreted as a
-- call in prefixed notation, the report is left to the caller.
-- To prevent cascaded errors, report only if no previous ones.
if Serious_Errors_Detected = 0 then
Error_Msg_N ("invalid prefix in indexed component", P);
if Nkind (P) = N_Expanded_Name then
Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
end if;
end if;
return;
-- Here we definitely have a bad indexing
else
if Nkind (Parent (N)) = N_Requeue_Statement
and then Present (Pent) and then Ekind (Pent) = E_Entry
then
Error_Msg_N
("REQUEUE does not permit parameters", First (Exprs));
elsif Is_Entity_Name (P)
and then Etype (P) = Standard_Void_Type
then
Error_Msg_NE ("incorrect use of &", P, Entity (P));
else
Error_Msg_N ("array type required in indexed component", P);
end if;
Set_Etype (N, Any_Type);
return;
end if;
Index := First_Index (Array_Type);
while Present (Index) and then Present (Exp) loop
if not Has_Compatible_Type (Exp, Etype (Index)) then
Wrong_Type (Exp, Etype (Index));
Set_Etype (N, Any_Type);
return;
end if;
Next_Index (Index);
Next (Exp);
end loop;
Set_Etype (N, Component_Type (Array_Type));
Check_Implicit_Dereference (N, Etype (N));
if Present (Index) then
Error_Msg_N
("too few subscripts in array reference", First (Exprs));
elsif Present (Exp) then
Error_Msg_N ("too many subscripts in array reference", Exp);
end if;
end if;
end Process_Indexed_Component;
----------------------------------------
-- Process_Indexed_Component_Or_Slice --
----------------------------------------
procedure Process_Indexed_Component_Or_Slice is
begin
Exp := First (Exprs);
while Present (Exp) loop
Analyze_Expression (Exp);
Next (Exp);
end loop;
Exp := First (Exprs);
-- If one index is present, and it is a subtype name, then the node
-- denotes a slice (note that the case of an explicit range for a
-- slice was already built as an N_Slice node in the first place,
-- so that case is not handled here).
-- We use a replace rather than a rewrite here because this is one
-- of the cases in which the tree built by the parser is plain wrong.
if No (Next (Exp))
and then Is_Entity_Name (Exp)
and then Is_Type (Entity (Exp))
then
Replace (N,
Make_Slice (Sloc (N),
Prefix => P,
Discrete_Range => New_Copy (Exp)));
Analyze (N);
-- Otherwise (more than one index present, or single index is not
-- a subtype name), then we have the indexed component case.
else
Process_Indexed_Component;
end if;
end Process_Indexed_Component_Or_Slice;
------------------------------------------
-- Process_Overloaded_Indexed_Component --
------------------------------------------
procedure Process_Overloaded_Indexed_Component is
Exp : Node_Id;
I : Interp_Index;
It : Interp;
Typ : Entity_Id;
Index : Node_Id;
Found : Boolean;
begin
Set_Etype (N, Any_Type);
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
Typ := It.Typ;
if Is_Access_Type (Typ) then
Typ := Designated_Type (Typ);
Error_Msg_NW
(Warn_On_Dereference, "?d?implicit dereference", N);
end if;
if Is_Array_Type (Typ) then
-- Got a candidate: verify that index types are compatible
Index := First_Index (Typ);
Found := True;
Exp := First (Exprs);
while Present (Index) and then Present (Exp) loop
if Has_Compatible_Type (Exp, Etype (Index)) then
null;
else
Found := False;
Remove_Interp (I);
exit;
end if;
Next_Index (Index);
Next (Exp);
end loop;
if Found and then No (Index) and then No (Exp) then
declare
CT : constant Entity_Id :=
Base_Type (Component_Type (Typ));
begin
Add_One_Interp (N, CT, CT);
Check_Implicit_Dereference (N, CT);
end;
end if;
elsif Try_Container_Indexing (N, P, Exprs) then
return;
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type then
Error_Msg_N ("no legal interpretation for indexed component", N);
Set_Is_Overloaded (N, False);
end if;
end Process_Overloaded_Indexed_Component;
-- Start of processing for Analyze_Indexed_Component_Form
begin
-- Get name of array, function or type
Analyze (P);
-- If P is an explicit dereference whose prefix is of a remote access-
-- to-subprogram type, then N has already been rewritten as a subprogram
-- call and analyzed.
if Nkind (N) in N_Subprogram_Call then
return;
-- When the prefix is attribute 'Loop_Entry and the sole expression of
-- the indexed component denotes a loop name, the indexed form is turned
-- into an attribute reference.
elsif Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Loop_Entry
then
return;
end if;
pragma Assert (Nkind (N) = N_Indexed_Component);
P_T := Base_Type (Etype (P));
if Is_Entity_Name (P) and then Present (Entity (P)) then
U_N := Entity (P);
if Is_Type (U_N) then
-- Reformat node as a type conversion
E := Remove_Head (Exprs);
if Present (First (Exprs)) then
Error_Msg_N
("argument of type conversion must be single expression", N);
end if;
Change_Node (N, N_Type_Conversion);
Set_Subtype_Mark (N, P);
Set_Etype (N, U_N);
Set_Expression (N, E);
-- After changing the node, call for the specific Analysis
-- routine directly, to avoid a double call to the expander.
Analyze_Type_Conversion (N);
return;
end if;
if Is_Overloadable (U_N) then
Process_Function_Call;
elsif Ekind (Etype (P)) = E_Subprogram_Type
or else (Is_Access_Type (Etype (P))
and then
Ekind (Designated_Type (Etype (P))) =
E_Subprogram_Type)
then
-- Call to access_to-subprogram with possible implicit dereference
Process_Function_Call;
elsif Is_Generic_Subprogram (U_N) then
-- A common beginner's (or C++ templates fan) error
Error_Msg_N ("generic subprogram cannot be called", N);
Set_Etype (N, Any_Type);
return;
else
Process_Indexed_Component_Or_Slice;
end if;
-- If not an entity name, prefix is an expression that may denote
-- an array or an access-to-subprogram.
else
if Ekind (P_T) = E_Subprogram_Type
or else (Is_Access_Type (P_T)
and then
Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
then
Process_Function_Call;
elsif Nkind (P) = N_Selected_Component
and then Present (Entity (Selector_Name (P)))
and then Is_Overloadable (Entity (Selector_Name (P)))
then
Process_Function_Call;
else
-- Indexed component, slice, or a call to a member of a family
-- entry, which will be converted to an entry call later.
Process_Indexed_Component_Or_Slice;
end if;
end if;
Analyze_Dimension (N);
end Analyze_Indexed_Component_Form;
------------------------
-- Analyze_Logical_Op --
------------------------
procedure Analyze_Logical_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
-- If the entity is already set, the node is the instantiation of a
-- generic node with a non-local reference, or was manufactured by a
-- call to Make_Op_xxx. In either case the entity is known to be valid,
-- and we do not need to collect interpretations, instead we just get
-- the single possible interpretation.
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Find_Boolean_Types (L, R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
-- Entity is not already set, so we do need to collect interpretations
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Boolean_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
Check_Function_Writable_Actuals (N);
end Analyze_Logical_Op;
---------------------------
-- Analyze_Membership_Op --
---------------------------
procedure Analyze_Membership_Op (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
procedure Analyze_Set_Membership;
-- If a set of alternatives is present, analyze each and find the
-- common type to which they must all resolve.
function Find_Interp return Boolean;
-- Find a valid interpretation of the test. Note that the context of the
-- operation plays no role in resolving the operands, so that if there
-- is more than one interpretation of the operands that is compatible
-- with the test, the operation is ambiguous.
function Try_Left_Interp (T : Entity_Id) return Boolean;
-- Try an interpretation of the left operand with type T. Return true if
-- one interpretation (at least) of the right operand making up a valid
-- operand pair exists, otherwise false if no such pair exists.
function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean;
-- Return true if T1 and T2 constitute a valid pair of operand types for
-- L and R respectively.
----------------------------
-- Analyze_Set_Membership --
----------------------------
procedure Analyze_Set_Membership is
Alt : Node_Id;
Index : Interp_Index;
It : Interp;
Candidate_Interps : Node_Id;
Common_Type : Entity_Id := Empty;
begin
Analyze (L);
Candidate_Interps := L;
if not Is_Overloaded (L) then
Common_Type := Etype (L);
Alt := First (Alternatives (N));
while Present (Alt) loop
Analyze (Alt);
if not Has_Compatible_Type (Alt, Common_Type) then
Wrong_Type (Alt, Common_Type);
end if;
Next (Alt);
end loop;
else
Alt := First (Alternatives (N));
while Present (Alt) loop
Analyze (Alt);
if not Is_Overloaded (Alt) then
Common_Type := Etype (Alt);
else
Get_First_Interp (Alt, Index, It);
while Present (It.Typ) loop
if not
Has_Compatible_Type (Candidate_Interps, It.Typ)
then
Remove_Interp (Index);
end if;
Get_Next_Interp (Index, It);
end loop;
Get_First_Interp (Alt, Index, It);
if No (It.Typ) then
Error_Msg_N ("alternative has no legal type", Alt);
return;
end if;
-- If alternative is not overloaded, we have a unique type
-- for all of them.
Set_Etype (Alt, It.Typ);
-- If the alternative is an enumeration literal, use the one
-- for this interpretation.
if Is_Entity_Name (Alt) then
Set_Entity (Alt, It.Nam);
end if;
Get_Next_Interp (Index, It);
if No (It.Typ) then
Set_Is_Overloaded (Alt, False);
Common_Type := Etype (Alt);
end if;
Candidate_Interps := Alt;
end if;
Next (Alt);
end loop;
end if;
if Present (Common_Type) then
Set_Etype (L, Common_Type);
-- The left operand may still be overloaded, to be resolved using
-- the Common_Type.
else
Error_Msg_N ("cannot resolve membership operation", N);
end if;
end Analyze_Set_Membership;
-----------------
-- Find_Interp --
-----------------
function Find_Interp return Boolean is
Found : Boolean;
I : Interp_Index;
It : Interp;
L_Typ : Entity_Id;
Valid_I : Interp_Index;
begin
-- Loop through the interpretations of the left operand
if not Is_Overloaded (L) then
Found := Try_Left_Interp (Etype (L));
else
Found := False;
L_Typ := Empty;
Valid_I := 0;
Get_First_Interp (L, I, It);
while Present (It.Typ) loop
if Try_Left_Interp (It.Typ) then
-- If several interpretations are possible, disambiguate
if Present (L_Typ)
and then Base_Type (It.Typ) /= Base_Type (L_Typ)
then
It := Disambiguate (L, Valid_I, I, Any_Type);
if It = No_Interp then
Ambiguous_Operands (N);
Set_Etype (L, Any_Type);
return True;
end if;
else
Valid_I := I;
end if;
L_Typ := It.Typ;
Set_Etype (L, L_Typ);
Found := True;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
return Found;
end Find_Interp;
---------------------
-- Try_Left_Interp --
---------------------
function Try_Left_Interp (T : Entity_Id) return Boolean is
Found : Boolean;
I : Interp_Index;
It : Interp;
R_Typ : Entity_Id;
Valid_I : Interp_Index;
begin
-- Defend against previous error
if Nkind (R) = N_Error then
Found := False;
-- Loop through the interpretations of the right operand
elsif not Is_Overloaded (R) then
Found := Is_Valid_Pair (T, Etype (R));
else
Found := False;
R_Typ := Empty;
Valid_I := 0;
Get_First_Interp (R, I, It);
while Present (It.Typ) loop
if Is_Valid_Pair (T, It.Typ) then
-- If several interpretations are possible, disambiguate
if Present (R_Typ)
and then Base_Type (It.Typ) /= Base_Type (R_Typ)
then
It := Disambiguate (R, Valid_I, I, Any_Type);
if It = No_Interp then
Ambiguous_Operands (N);
Set_Etype (R, Any_Type);
return True;
end if;
else
Valid_I := I;
end if;
R_Typ := It.Typ;
Found := True;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
return Found;
end Try_Left_Interp;
-------------------
-- Is_Valid_Pair --
-------------------
function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean is
begin
return Covers (T1 => T1, T2 => T2)
or else Covers (T1 => T2, T2 => T1)
or else Is_User_Defined_Literal (L, T2)
or else Is_User_Defined_Literal (R, T1);
end Is_Valid_Pair;
-- Local variables
Dummy : Boolean;
Op : Node_Id;
-- Start of processing for Analyze_Membership_Op
begin
Analyze_Expression (L);
if No (R) then
pragma Assert (Ada_Version >= Ada_2012);
Analyze_Set_Membership;
elsif Nkind (R) = N_Range
or else (Nkind (R) = N_Attribute_Reference
and then Attribute_Name (R) = Name_Range)
then
Analyze_Expression (R);
Dummy := Find_Interp;
-- If not a range, it can be a subtype mark, or else it is a degenerate
-- membership test with a singleton value, i.e. a test for equality,
-- if the types are compatible.
else
Analyze_Expression (R);
if Is_Entity_Name (R) and then Is_Type (Entity (R)) then
Find_Type (R);
Check_Fully_Declared (Entity (R), R);
elsif Ada_Version >= Ada_2012 and then Find_Interp then
Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R);
Resolve_Membership_Equality (Op, Etype (L));
if Nkind (N) = N_Not_In then
Op := Make_Op_Not (Loc, Op);
end if;
Rewrite (N, Op);
Analyze (N);
return;
else
-- In all versions of the language, if we reach this point there
-- is a previous error that will be diagnosed below.
Find_Type (R);
end if;
end if;
-- Compatibility between expression and subtype mark or range is
-- checked during resolution. The result of the operation is Boolean
-- in any case.
Set_Etype (N, Standard_Boolean);
if Comes_From_Source (N)
and then Present (Right_Opnd (N))
and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
then
Error_Msg_N ("membership test not applicable to cpp-class types", N);
end if;
Check_Function_Writable_Actuals (N);
end Analyze_Membership_Op;
-----------------
-- Analyze_Mod --
-----------------
procedure Analyze_Mod (N : Node_Id) is
begin
-- A special warning check, if we have an expression of the form:
-- expr mod 2 * literal
-- where literal is 128 or less, then probably what was meant was
-- expr mod 2 ** literal
-- so issue an appropriate warning.
if Warn_On_Suspicious_Modulus_Value
and then Nkind (Right_Opnd (N)) = N_Integer_Literal
and then Intval (Right_Opnd (N)) = Uint_2
and then Nkind (Parent (N)) = N_Op_Multiply
and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
and then Intval (Right_Opnd (Parent (N))) <= Uint_128
then
Error_Msg_N
("suspicious MOD value, was '*'* intended'??.m?", Parent (N));
end if;
-- Remaining processing is same as for other arithmetic operators
Analyze_Arithmetic_Op (N);
end Analyze_Mod;
----------------------
-- Analyze_Negation --
----------------------
procedure Analyze_Negation (N : Node_Id) is
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (R);
-- If the entity is already set, the node is the instantiation of a
-- generic node with a non-local reference, or was manufactured by a
-- call to Make_Op_xxx. In either case the entity is known to be valid,
-- and we do not need to collect interpretations, instead we just get
-- the single possible interpretation.
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Find_Negation_Types (R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Negation_Types (R, Op_Id, N);
else
Analyze_User_Defined_Unary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Negation;
------------------
-- Analyze_Null --
------------------
procedure Analyze_Null (N : Node_Id) is
begin
Set_Etype (N, Universal_Access);
end Analyze_Null;
----------------------
-- Analyze_One_Call --
----------------------
procedure Analyze_One_Call
(N : Node_Id;
Nam : Entity_Id;
Report : Boolean;
Success : out Boolean;
Skip_First : Boolean := False)
is
Actuals : constant List_Id := Parameter_Associations (N);
Prev_T : constant Entity_Id := Etype (N);
-- Recognize cases of prefixed calls that have been rewritten in
-- various ways. The simplest case is a rewritten selected component,
-- but it can also be an already-examined indexed component, or a
-- prefix that is itself a rewritten prefixed call that is in turn
-- an indexed call (the syntactic ambiguity involving the indexing of
-- a function with defaulted parameters that returns an array).
-- A flag Maybe_Indexed_Call might be useful here ???
Must_Skip : constant Boolean := Skip_First
or else Nkind (Original_Node (N)) = N_Selected_Component
or else
(Nkind (Original_Node (N)) = N_Indexed_Component
and then Nkind (Prefix (Original_Node (N))) =
N_Selected_Component)
or else
(Nkind (Parent (N)) = N_Function_Call
and then Is_Array_Type (Etype (Name (N)))
and then Etype (Original_Node (N)) =
Component_Type (Etype (Name (N)))
and then Nkind (Original_Node (Parent (N))) =
N_Selected_Component);
-- The first formal must be omitted from the match when trying to find
-- a primitive operation that is a possible interpretation, and also
-- after the call has been rewritten, because the corresponding actual
-- is already known to be compatible, and because this may be an
-- indexing of a call with default parameters.
First_Form : Entity_Id;
Formal : Entity_Id;
Actual : Node_Id;
Is_Indexed : Boolean := False;
Is_Indirect : Boolean := False;
Subp_Type : constant Entity_Id := Etype (Nam);
Norm_OK : Boolean;
function Compatible_Types_In_Predicate
(T1 : Entity_Id;
T2 : Entity_Id) return Boolean;
-- For an Ada 2012 predicate or invariant, a call may mention an
-- incomplete type, while resolution of the corresponding predicate
-- function may see the full view, as a consequence of the delayed
-- resolution of the corresponding expressions. This may occur in
-- the body of a predicate function, or in a call to such. Anomalies
-- involving private and full views can also happen. In each case,
-- rewrite node or add conversions to remove spurious type errors.
procedure Indicate_Name_And_Type;
-- If candidate interpretation matches, indicate name and type of result
-- on call node.
function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
-- There may be a user-defined operator that hides the current
-- interpretation. We must check for this independently of the
-- analysis of the call with the user-defined operation, because
-- the parameter names may be wrong and yet the hiding takes place.
-- This fixes a problem with ACATS test B34014O.
--
-- When the type Address is a visible integer type, and the DEC
-- system extension is visible, the predefined operator may be
-- hidden as well, by one of the address operations in auxdec.
-- Finally, the abstract operations on address do not hide the
-- predefined operator (this is the purpose of making them abstract).
-----------------------------------
-- Compatible_Types_In_Predicate --
-----------------------------------
function Compatible_Types_In_Predicate
(T1 : Entity_Id;
T2 : Entity_Id) return Boolean
is
function Common_Type (T : Entity_Id) return Entity_Id;
-- Find non-private underlying full view if any, without going to
-- ancestor type (as opposed to Underlying_Type).
-----------------
-- Common_Type --
-----------------
function Common_Type (T : Entity_Id) return Entity_Id is
CT : Entity_Id;
begin
CT := T;
if Is_Private_Type (CT) and then Present (Full_View (CT)) then
CT := Full_View (CT);
end if;
if Is_Private_Type (CT)
and then Present (Underlying_Full_View (CT))
then
CT := Underlying_Full_View (CT);
end if;
return Base_Type (CT);
end Common_Type;
-- Start of processing for Compatible_Types_In_Predicate
begin
if (Ekind (Current_Scope) = E_Function
and then Is_Predicate_Function (Current_Scope))
or else
(Ekind (Nam) = E_Function
and then Is_Predicate_Function (Nam))
then
if Is_Incomplete_Type (T1)
and then Present (Full_View (T1))
and then Full_View (T1) = T2
then
Set_Etype (Formal, Etype (Actual));
return True;
elsif Common_Type (T1) = Common_Type (T2) then
Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
return True;
else
return False;
end if;
else
return False;
end if;
end Compatible_Types_In_Predicate;
----------------------------
-- Indicate_Name_And_Type --
----------------------------
procedure Indicate_Name_And_Type is
begin
Add_One_Interp (N, Nam, Etype (Nam));
Check_Implicit_Dereference (N, Etype (Nam));
Success := True;
-- If the prefix of the call is a name, indicate the entity
-- being called. If it is not a name, it is an expression that
-- denotes an access to subprogram or else an entry or family. In
-- the latter case, the name is a selected component, and the entity
-- being called is noted on the selector.
if not Is_Type (Nam) then
if Is_Entity_Name (Name (N)) then
Set_Entity (Name (N), Nam);
Set_Etype (Name (N), Etype (Nam));
elsif Nkind (Name (N)) = N_Selected_Component then
Set_Entity (Selector_Name (Name (N)), Nam);
end if;
end if;
if Debug_Flag_E and not Report then
Write_Str (" Overloaded call ");
Write_Int (Int (N));
Write_Str (" compatible with ");
Write_Int (Int (Nam));
Write_Eol;
end if;
end Indicate_Name_And_Type;
------------------------
-- Operator_Hidden_By --
------------------------
function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
Act1 : constant Node_Id := First_Actual (N);
Act2 : constant Node_Id := Next_Actual (Act1);
Form1 : constant Entity_Id := First_Formal (Fun);
Form2 : constant Entity_Id := Next_Formal (Form1);
begin
if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
return False;
elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
return False;
elsif Present (Form2) then
if No (Act2)
or else not Has_Compatible_Type (Act2, Etype (Form2))
then
return False;
end if;
elsif Present (Act2) then
return False;
end if;
-- Now we know that the arity of the operator matches the function,
-- and the function call is a valid interpretation. The function
-- hides the operator if it has the right signature, or if one of
-- its operands is a non-abstract operation on Address when this is
-- a visible integer type.
return Hides_Op (Fun, Nam)
or else Is_Descendant_Of_Address (Etype (Form1))
or else
(Present (Form2)
and then Is_Descendant_Of_Address (Etype (Form2)));
end Operator_Hidden_By;
-- Start of processing for Analyze_One_Call
begin
Success := False;
-- If the subprogram has no formals or if all the formals have defaults,
-- and the return type is an array type, the node may denote an indexing
-- of the result of a parameterless call. In Ada 2005, the subprogram
-- may have one non-defaulted formal, and the call may have been written
-- in prefix notation, so that the rebuilt parameter list has more than
-- one actual.
if not Is_Overloadable (Nam)
and then Ekind (Nam) /= E_Subprogram_Type
and then Ekind (Nam) /= E_Entry_Family
then
return;
end if;
-- An indexing requires at least one actual. The name of the call cannot
-- be an implicit indirect call, so it cannot be a generated explicit
-- dereference.
if not Is_Empty_List (Actuals)
and then
(Needs_No_Actuals (Nam)
or else
(Needs_One_Actual (Nam)
and then Present (Next_Actual (First (Actuals)))))
then
if Is_Array_Type (Subp_Type)
and then
(Nkind (Name (N)) /= N_Explicit_Dereference
or else Comes_From_Source (Name (N)))
then
Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
elsif Is_Access_Type (Subp_Type)
and then Is_Array_Type (Designated_Type (Subp_Type))
then
Is_Indexed :=
Try_Indexed_Call
(N, Nam, Designated_Type (Subp_Type), Must_Skip);
-- The prefix can also be a parameterless function that returns an
-- access to subprogram, in which case this is an indirect call.
-- If this succeeds, an explicit dereference is added later on,
-- in Analyze_Call or Resolve_Call.
elsif Is_Access_Type (Subp_Type)
and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
then
Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
end if;
end if;
-- If the call has been transformed into a slice, it is of the form
-- F (Subtype) where F is parameterless. The node has been rewritten in
-- Try_Indexed_Call and there is nothing else to do.
if Is_Indexed
and then Nkind (N) = N_Slice
then
return;
end if;
Normalize_Actuals
(N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
if not Norm_OK then
-- If an indirect call is a possible interpretation, indicate
-- success to the caller. This may be an indexing of an explicit
-- dereference of a call that returns an access type (see above).
if Is_Indirect
or else (Is_Indexed
and then Nkind (Name (N)) = N_Explicit_Dereference
and then Comes_From_Source (Name (N)))
then
Success := True;
return;
-- Mismatch in number or names of parameters
elsif Debug_Flag_E then
Write_Str (" normalization fails in call ");
Write_Int (Int (N));
Write_Str (" with subprogram ");
Write_Int (Int (Nam));
Write_Eol;
end if;
-- If the context expects a function call, discard any interpretation
-- that is a procedure. If the node is not overloaded, leave as is for
-- better error reporting when type mismatch is found.
elsif Nkind (N) = N_Function_Call
and then Is_Overloaded (Name (N))
and then Ekind (Nam) = E_Procedure
then
return;
-- Ditto for function calls in a procedure context
elsif Nkind (N) = N_Procedure_Call_Statement
and then Is_Overloaded (Name (N))
and then Etype (Nam) /= Standard_Void_Type
then
return;
elsif No (Actuals) then
-- If Normalize succeeds, then there are default parameters for
-- all formals.
Indicate_Name_And_Type;
elsif Ekind (Nam) = E_Operator then
if Nkind (N) = N_Procedure_Call_Statement then
return;
end if;
-- This occurs when the prefix of the call is an operator name
-- or an expanded name whose selector is an operator name.
Analyze_Operator_Call (N, Nam);
if Etype (N) /= Prev_T then
-- Check that operator is not hidden by a function interpretation
if Is_Overloaded (Name (N)) then
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Name (N), I, It);
while Present (It.Nam) loop
if Operator_Hidden_By (It.Nam) then
Set_Etype (N, Prev_T);
return;
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
-- If operator matches formals, record its name on the call.
-- If the operator is overloaded, Resolve will select the
-- correct one from the list of interpretations. The call
-- node itself carries the first candidate.
Set_Entity (Name (N), Nam);
Success := True;
elsif Report and then Etype (N) = Any_Type then
Error_Msg_N ("incompatible arguments for operator", N);
end if;
else
-- Normalize_Actuals has chained the named associations in the
-- correct order of the formals.
Actual := First_Actual (N);
Formal := First_Formal (Nam);
First_Form := Formal;
-- If we are analyzing a call rewritten from object notation, skip
-- first actual, which may be rewritten later as an explicit
-- dereference.
if Must_Skip then
Next_Actual (Actual);
Next_Formal (Formal);
end if;
while Present (Actual) and then Present (Formal) loop
if Nkind (Parent (Actual)) /= N_Parameter_Association
or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
then
-- The actual can be compatible with the formal, but we must
-- also check that the context is not an address type that is
-- visibly an integer type. In this case the use of literals is
-- illegal, except in the body of descendants of system, where
-- arithmetic operations on address are of course used.
if Has_Compatible_Type (Actual, Etype (Formal))
and then
(Etype (Actual) /= Universal_Integer
or else not Is_Descendant_Of_Address (Etype (Formal))
or else In_Predefined_Unit (N))
then
Next_Actual (Actual);
Next_Formal (Formal);
-- In Allow_Integer_Address mode, we allow an actual integer to
-- match a formal address type and vice versa. We only do this
-- if we are certain that an error will otherwise be issued
elsif Address_Integer_Convert_OK
(Etype (Actual), Etype (Formal))
and then (Report and not Is_Indexed and not Is_Indirect)
then
-- Handle this case by introducing an unchecked conversion
Rewrite (Actual,
Unchecked_Convert_To (Etype (Formal),
Relocate_Node (Actual)));
Analyze_And_Resolve (Actual, Etype (Formal));
Next_Actual (Actual);
Next_Formal (Formal);
-- Under relaxed RM semantics silently replace occurrences of
-- null by System.Address_Null. We only do this if we know that
-- an error will otherwise be issued.
elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
and then (Report and not Is_Indexed and not Is_Indirect)
then
Replace_Null_By_Null_Address (Actual);
Analyze_And_Resolve (Actual, Etype (Formal));
Next_Actual (Actual);
Next_Formal (Formal);
elsif Compatible_Types_In_Predicate
(Etype (Formal), Etype (Actual))
then
Next_Actual (Actual);
Next_Formal (Formal);
-- A current instance used as an actual of a function,
-- whose body has not been seen, may include a formal
-- whose type is an incomplete view of an enclosing
-- type declaration containing the current call (e.g.
-- in the Expression for a component declaration).
-- In this case, update the signature of the subprogram
-- so the formal has the type of the full view.
elsif Inside_Init_Proc
and then Nkind (Actual) = N_Identifier
and then Ekind (Etype (Formal)) = E_Incomplete_Type
and then Etype (Actual) = Full_View (Etype (Formal))
then
Set_Etype (Formal, Etype (Actual));
Next_Actual (Actual);
Next_Formal (Formal);
-- Handle failed type check
else
if Debug_Flag_E then
Write_Str (" type checking fails in call ");
Write_Int (Int (N));
Write_Str (" with formal ");
Write_Int (Int (Formal));
Write_Str (" in subprogram ");
Write_Int (Int (Nam));
Write_Eol;
end if;
-- Comment needed on the following test???
if Report and not Is_Indexed and not Is_Indirect then
-- Ada 2005 (AI-251): Complete the error notification
-- to help new Ada 2005 users.
if Is_Class_Wide_Type (Etype (Formal))
and then Is_Interface (Etype (Etype (Formal)))
and then not Interface_Present_In_Ancestor
(Typ => Etype (Actual),
Iface => Etype (Etype (Formal)))
then
Error_Msg_NE
("(Ada 2005) does not implement interface }",
Actual, Etype (Etype (Formal)));
end if;
Wrong_Type (Actual, Etype (Formal));
if Nkind (Actual) = N_Op_Eq
and then Nkind (Left_Opnd (Actual)) = N_Identifier
then
Formal := First_Formal (Nam);
while Present (Formal) loop
if Chars (Left_Opnd (Actual)) = Chars (Formal) then
Error_Msg_N -- CODEFIX
("possible misspelling of `='>`!", Actual);
exit;
end if;
Next_Formal (Formal);
end loop;
end if;
if All_Errors_Mode then
Error_Msg_Sloc := Sloc (Nam);
if Etype (Formal) = Any_Type then
Error_Msg_N
("there is no legal actual parameter", Actual);
end if;
if Is_Overloadable (Nam)
and then Present (Alias (Nam))
and then not Comes_From_Source (Nam)
then
Error_Msg_NE
("\\ =='> in call to inherited operation & #!",
Actual, Nam);
elsif Ekind (Nam) = E_Subprogram_Type then
declare
Access_To_Subprogram_Typ :
constant Entity_Id :=
Defining_Identifier
(Associated_Node_For_Itype (Nam));
begin
Error_Msg_NE
("\\ =='> in call to dereference of &#!",
Actual, Access_To_Subprogram_Typ);
end;
else
Error_Msg_NE
("\\ =='> in call to &#!", Actual, Nam);
end if;
end if;
end if;
return;
end if;
else
-- Normalize_Actuals has verified that a default value exists
-- for this formal. Current actual names a subsequent formal.
Next_Formal (Formal);
end if;
end loop;
-- Due to our current model of controlled type expansion we may
-- have resolved a user call to a non-visible controlled primitive
-- since these inherited subprograms may be generated in the current
-- scope. This is a side effect of the need for the expander to be
-- able to resolve internally generated calls.
-- Specifically, the issue appears when predefined controlled
-- operations get called on a type extension whose parent is a
-- private extension completed with a controlled extension - see
-- below:
-- package X is
-- type Par_Typ is tagged private;
-- private
-- type Par_Typ is new Controlled with null record;
-- end;
-- ...
-- procedure Main is
-- type Ext_Typ is new Par_Typ with null record;
-- Obj : Ext_Typ;
-- begin
-- Finalize (Obj); -- Will improperly resolve
-- end;
-- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
-- primitives, but we still need to verify that Nam is indeed a
-- non-visible controlled subprogram. So, we do that here and issue
-- the appropriate error.
if Is_Hidden (Nam)
and then not In_Instance
and then not Comes_From_Source (Nam)
and then Comes_From_Source (N)
-- Verify Nam is a non-visible controlled primitive
and then Chars (Nam) in Name_Adjust
| Name_Finalize
| Name_Initialize
and then Ekind (Nam) = E_Procedure
and then Is_Controlled (Etype (First_Form))
and then No (Next_Formal (First_Form))
and then not Is_Visibly_Controlled (Etype (First_Form))
then
Error_Msg_Node_2 := Etype (First_Form);
Error_Msg_NE ("call to non-visible controlled primitive & on type"
& " &", N, Nam);
end if;
-- On exit, all actuals match
Indicate_Name_And_Type;
end if;
end Analyze_One_Call;
---------------------------
-- Analyze_Operator_Call --
---------------------------
procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
Op_Name : constant Name_Id := Chars (Op_Id);
Act1 : constant Node_Id := First_Actual (N);
Act2 : constant Node_Id := Next_Actual (Act1);
begin
-- Binary operator case
if Present (Act2) then
-- If more than two operands, then not binary operator after all
if Present (Next_Actual (Act2)) then
return;
end if;
-- Otherwise action depends on operator
case Op_Name is
when Name_Op_Add
| Name_Op_Divide
| Name_Op_Expon
| Name_Op_Mod
| Name_Op_Multiply
| Name_Op_Rem
| Name_Op_Subtract
=>
Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
when Name_Op_And
| Name_Op_Or
| Name_Op_Xor
=>
Find_Boolean_Types (Act1, Act2, Op_Id, N);
when Name_Op_Eq
| Name_Op_Ge
| Name_Op_Gt
| Name_Op_Le
| Name_Op_Lt
| Name_Op_Ne
=>
Find_Comparison_Equality_Types (Act1, Act2, Op_Id, N);
when Name_Op_Concat =>
Find_Concatenation_Types (Act1, Act2, Op_Id, N);
-- Is this when others, or should it be an abort???
when others =>
null;
end case;
-- Unary operator case
else
case Op_Name is
when Name_Op_Abs
| Name_Op_Add
| Name_Op_Subtract
=>
Find_Unary_Types (Act1, Op_Id, N);
when Name_Op_Not =>
Find_Negation_Types (Act1, Op_Id, N);
-- Is this when others correct, or should it be an abort???
when others =>
null;
end case;
end if;
end Analyze_Operator_Call;
-------------------------------------------
-- Analyze_Overloaded_Selected_Component --
-------------------------------------------
procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
Nam : constant Node_Id := Prefix (N);
Sel : constant Node_Id := Selector_Name (N);
Comp : Entity_Id;
I : Interp_Index;
It : Interp;
T : Entity_Id;
begin
Set_Etype (Sel, Any_Type);
Get_First_Interp (Nam, I, It);
while Present (It.Typ) loop
if Is_Access_Type (It.Typ) then
T := Designated_Type (It.Typ);
Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
else
T := It.Typ;
end if;
-- Locate the component. For a private prefix the selector can denote
-- a discriminant.
if Is_Record_Type (T) or else Is_Private_Type (T) then
-- If the prefix is a class-wide type, the visible components are
-- those of the base type.
if Is_Class_Wide_Type (T) then
T := Etype (T);
end if;
Comp := First_Entity (T);
while Present (Comp) loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp, Sel)
then
-- AI05-105: if the context is an object renaming with
-- an anonymous access type, the expected type of the
-- object must be anonymous. This is a name resolution rule.
if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
or else No (Access_Definition (Parent (N)))
or else Is_Anonymous_Access_Type (Etype (Comp))
then
Set_Entity (Sel, Comp);
Set_Etype (Sel, Etype (Comp));
Add_One_Interp (N, Etype (Comp), Etype (Comp));
Check_Implicit_Dereference (N, Etype (Comp));
-- This also specifies a candidate to resolve the name.
-- Further overloading will be resolved from context.
-- The selector name itself does not carry overloading
-- information.
Set_Etype (Nam, It.Typ);
else
-- Named access type in the context of a renaming
-- declaration with an access definition. Remove
-- inapplicable candidate.
Remove_Interp (I);
end if;
end if;
Next_Entity (Comp);
end loop;
elsif Is_Concurrent_Type (T) then
Comp := First_Entity (T);
while Present (Comp)
and then Comp /= First_Private_Entity (T)
loop
if Chars (Comp) = Chars (Sel) then
if Is_Overloadable (Comp) then
Add_One_Interp (Sel, Comp, Etype (Comp));
else
Set_Entity_With_Checks (Sel, Comp);
Generate_Reference (Comp, Sel);
end if;
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
Set_Etype (Nam, It.Typ);
end if;
Next_Entity (Comp);
end loop;
Set_Is_Overloaded (N, Is_Overloaded (Sel));
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type
and then not Try_Object_Operation (N)
then
Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
end if;
end Analyze_Overloaded_Selected_Component;
----------------------------------
-- Analyze_Qualified_Expression --
----------------------------------
procedure Analyze_Qualified_Expression (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
Mark : constant Entity_Id := Subtype_Mark (N);
I : Interp_Index;
It : Interp;
T : Entity_Id;
begin
Find_Type (Mark);
T := Entity (Mark);
if Nkind (Enclosing_Declaration (N)) in
N_Formal_Type_Declaration |
N_Full_Type_Declaration |
N_Incomplete_Type_Declaration |
N_Protected_Type_Declaration |
N_Private_Extension_Declaration |
N_Private_Type_Declaration |
N_Subtype_Declaration |
N_Task_Type_Declaration
and then T = Defining_Identifier (Enclosing_Declaration (N))
then
Error_Msg_N ("current instance not allowed", Mark);
T := Any_Type;
end if;
Set_Etype (N, T);
Analyze_Expression (Expr);
if T = Any_Type then
return;
end if;
Check_Fully_Declared (T, N);
-- If expected type is class-wide, check for exact match before
-- expansion, because if the expression is a dispatching call it
-- may be rewritten as explicit dereference with class-wide result.
-- If expression is overloaded, retain only interpretations that
-- will yield exact matches.
if Is_Class_Wide_Type (T) then
if not Is_Overloaded (Expr) then
if Base_Type (Etype (Expr)) /= Base_Type (T)
and then Etype (Expr) /= Raise_Type
then
if Nkind (Expr) = N_Aggregate then
Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
else
Wrong_Type (Expr, T);
end if;
end if;
else
Get_First_Interp (Expr, I, It);
while Present (It.Nam) loop
if Base_Type (It.Typ) /= Base_Type (T) then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end if;
end Analyze_Qualified_Expression;
-----------------------------------
-- Analyze_Quantified_Expression --
-----------------------------------
procedure Analyze_Quantified_Expression (N : Node_Id) is
function Is_Empty_Range (Typ : Entity_Id) return Boolean;
-- Return True if the iterator is part of a quantified expression and
-- the range is known to be statically empty.
function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
-- Determine whether if expression If_Expr lacks an else part or if it
-- has one, it evaluates to True.
--------------------
-- Is_Empty_Range --
--------------------
function Is_Empty_Range (Typ : Entity_Id) return Boolean is
begin
return Is_Array_Type (Typ)
and then Compile_Time_Known_Bounds (Typ)
and then
Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
Expr_Value (Type_High_Bound (Etype (First_Index (Typ))));
end Is_Empty_Range;
-----------------------------
-- No_Else_Or_Trivial_True --
-----------------------------
function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
Else_Expr : constant Node_Id :=
Next (Next (First (Expressions (If_Expr))));
begin
return
No (Else_Expr)
or else (Compile_Time_Known_Value (Else_Expr)
and then Is_True (Expr_Value (Else_Expr)));
end No_Else_Or_Trivial_True;
-- Local variables
Cond : constant Node_Id := Condition (N);
Loc : constant Source_Ptr := Sloc (N);
Loop_Id : Entity_Id;
QE_Scop : Entity_Id;
-- Start of processing for Analyze_Quantified_Expression
begin
-- Create a scope to emulate the loop-like behavior of the quantified
-- expression. The scope is needed to provide proper visibility of the
-- loop variable.
QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L');
Set_Etype (QE_Scop, Standard_Void_Type);
Set_Scope (QE_Scop, Current_Scope);
Set_Parent (QE_Scop, N);
Push_Scope (QE_Scop);
-- All constituents are preanalyzed and resolved to avoid untimely
-- generation of various temporaries and types. Full analysis and
-- expansion is carried out when the quantified expression is
-- transformed into an expression with actions.
if Present (Iterator_Specification (N)) then
Preanalyze (Iterator_Specification (N));
-- Do not proceed with the analysis when the range of iteration is
-- empty.
if Is_Entity_Name (Name (Iterator_Specification (N)))
and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
then
Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
End_Scope;
-- Emit a warning and replace expression with its static value
if All_Present (N) then
Error_Msg_N
("??quantified expression with ALL "
& "over a null range has value True", N);
Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
else
Error_Msg_N
("??quantified expression with SOME "
& "over a null range has value False", N);
Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
end if;
Analyze (N);
return;
end if;
else pragma Assert (Present (Loop_Parameter_Specification (N)));
declare
Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
begin
Preanalyze (Loop_Par);
if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
and then Parent (Loop_Par) /= N
then
-- The parser cannot distinguish between a loop specification
-- and an iterator specification. If after preanalysis the
-- proper form has been recognized, rewrite the expression to
-- reflect the right kind. This is needed for proper ASIS
-- navigation. If expansion is enabled, the transformation is
-- performed when the expression is rewritten as a loop.
-- Is this still needed???
Set_Iterator_Specification (N,
New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
Set_Defining_Identifier (Iterator_Specification (N),
Relocate_Node (Defining_Identifier (Loop_Par)));
Set_Name (Iterator_Specification (N),
Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
Set_Comes_From_Source (Iterator_Specification (N),
Comes_From_Source (Loop_Parameter_Specification (N)));
Set_Loop_Parameter_Specification (N, Empty);
end if;
end;
end if;
Preanalyze_And_Resolve (Cond, Standard_Boolean);
End_Scope;
Set_Etype (N, Standard_Boolean);
-- Verify that the loop variable is used within the condition of the
-- quantified expression.
if Present (Iterator_Specification (N)) then
Loop_Id := Defining_Identifier (Iterator_Specification (N));
else
Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
end if;
declare
type Subexpr_Kind is (Full, Conjunct, Disjunct);
procedure Check_Subexpr (Expr : Node_Id; Kind : Subexpr_Kind);
-- Check that the quantified variable appears in every sub-expression
-- of the quantified expression. If Kind is Full, Expr is the full
-- expression. If Kind is Conjunct (resp. Disjunct), Expr is a
-- conjunct (resp. disjunct) of the full expression.
-------------------
-- Check_Subexpr --
-------------------
procedure Check_Subexpr (Expr : Node_Id; Kind : Subexpr_Kind) is
begin
if Nkind (Expr) in N_Op_And | N_And_Then
and then Kind /= Disjunct
then
Check_Subexpr (Left_Opnd (Expr), Conjunct);
Check_Subexpr (Right_Opnd (Expr), Conjunct);
elsif Nkind (Expr) in N_Op_Or | N_Or_Else
and then Kind /= Conjunct
then
Check_Subexpr (Left_Opnd (Expr), Disjunct);
Check_Subexpr (Right_Opnd (Expr), Disjunct);
elsif Kind /= Full
and then not Referenced (Loop_Id, Expr)
then
declare
Sub : constant String :=
(if Kind = Conjunct then "conjunct" else "disjunct");
begin
Error_Msg_NE
("?.t?unused variable & in " & Sub, Expr, Loop_Id);
Error_Msg_NE
("\consider extracting " & Sub & " from quantified "
& "expression", Expr, Loop_Id);
end;
end if;
end Check_Subexpr;
begin
if Warn_On_Suspicious_Contract
and then not Is_Internal_Name (Chars (Loop_Id))
-- Generating C, this check causes spurious warnings on inlined
-- postconditions; we can safely disable it because this check
-- was previously performed when analyzing the internally built
-- postconditions procedure.
and then not (Modify_Tree_For_C and In_Inlined_Body)
then
if not Referenced (Loop_Id, Cond) then
Error_Msg_N ("?.t?unused variable &", Loop_Id);
else
Check_Subexpr (Cond, Kind => Full);
end if;
end if;
end;
-- Diagnose a possible misuse of the SOME existential quantifier. When
-- we have a quantified expression of the form:
-- for some X => (if P then Q [else True])
-- any value for X that makes P False results in the if expression being
-- trivially True, and so also results in the quantified expression
-- being trivially True.
if Warn_On_Suspicious_Contract
and then not All_Present (N)
and then Nkind (Cond) = N_If_Expression
and then No_Else_Or_Trivial_True (Cond)
then
Error_Msg_N ("?.t?suspicious expression", N);
Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
end if;
end Analyze_Quantified_Expression;
-------------------
-- Analyze_Range --
-------------------
procedure Analyze_Range (N : Node_Id) is
L : constant Node_Id := Low_Bound (N);
H : constant Node_Id := High_Bound (N);
I1, I2 : Interp_Index;
It1, It2 : Interp;
procedure Check_Common_Type (T1, T2 : Entity_Id);
-- Verify the compatibility of two types, and choose the
-- non universal one if the other is universal.
procedure Check_High_Bound (T : Entity_Id);
-- Test one interpretation of the low bound against all those
-- of the high bound.
procedure Check_Universal_Expression (N : Node_Id);
-- In Ada 83, reject bounds of a universal range that are not literals
-- or entity names.
-----------------------
-- Check_Common_Type --
-----------------------
procedure Check_Common_Type (T1, T2 : Entity_Id) is
begin
if Covers (T1 => T1, T2 => T2)
or else
Covers (T1 => T2, T2 => T1)
then
if Is_Universal_Numeric_Type (T1)
or else T1 = Any_Character
then
Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
elsif T1 = T2 then
Add_One_Interp (N, T1, T1);
else
Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
end if;
end if;
end Check_Common_Type;
----------------------
-- Check_High_Bound --
----------------------
procedure Check_High_Bound (T : Entity_Id) is
begin
if not Is_Overloaded (H) then
Check_Common_Type (T, Etype (H));
else
Get_First_Interp (H, I2, It2);
while Present (It2.Typ) loop
Check_Common_Type (T, It2.Typ);
Get_Next_Interp (I2, It2);
end loop;
end if;
end Check_High_Bound;
--------------------------------
-- Check_Universal_Expression --
--------------------------------
procedure Check_Universal_Expression (N : Node_Id) is
begin
if Etype (N) = Universal_Integer
and then Nkind (N) /= N_Integer_Literal
and then not Is_Entity_Name (N)
and then Nkind (N) /= N_Attribute_Reference
then
Error_Msg_N ("illegal bound in discrete range", N);
end if;
end Check_Universal_Expression;
-- Start of processing for Analyze_Range
begin
Set_Etype (N, Any_Type);
Analyze_Expression (L);
Analyze_Expression (H);
if Etype (L) = Any_Type or else Etype (H) = Any_Type then
return;
else
if not Is_Overloaded (L) then
Check_High_Bound (Etype (L));
else
Get_First_Interp (L, I1, It1);
while Present (It1.Typ) loop
Check_High_Bound (It1.Typ);
Get_Next_Interp (I1, It1);
end loop;
end if;
-- If result is Any_Type, then we did not find a compatible pair
if Etype (N) = Any_Type then
Error_Msg_N ("incompatible types in range", N);
end if;
end if;
if Ada_Version = Ada_83
and then
(Nkind (Parent (N)) = N_Loop_Parameter_Specification
or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
then
Check_Universal_Expression (L);
Check_Universal_Expression (H);
end if;
Check_Function_Writable_Actuals (N);
end Analyze_Range;
-----------------------
-- Analyze_Reference --
-----------------------
procedure Analyze_Reference (N : Node_Id) is
P : constant Node_Id := Prefix (N);
E : Entity_Id;
T : Entity_Id;
Acc_Type : Entity_Id;
begin
Analyze (P);
-- An interesting error check, if we take the 'Ref of an object for
-- which a pragma Atomic or Volatile has been given, and the type of the
-- object is not Atomic or Volatile, then we are in trouble. The problem
-- is that no trace of the atomic/volatile status will remain for the
-- backend to respect when it deals with the resulting pointer, since
-- the pointer type will not be marked atomic (it is a pointer to the
-- base type of the object).
-- It is not clear if that can ever occur, but in case it does, we will
-- generate an error message. Not clear if this message can ever be
-- generated, and pretty clear that it represents a bug if it is, still
-- seems worth checking, except in CodePeer mode where we do not really
-- care and don't want to bother the user.
T := Etype (P);
if Is_Entity_Name (P)
and then Is_Object_Reference (P)
and then not CodePeer_Mode
then
E := Entity (P);
T := Etype (P);
if (Has_Atomic_Components (E)
and then not Has_Atomic_Components (T))
or else
(Has_Volatile_Components (E)
and then not Has_Volatile_Components (T))
or else (Is_Atomic (E) and then not Is_Atomic (T))
or else (Is_Volatile (E) and then not Is_Volatile (T))
then
Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
end if;
end if;
-- Carry on with normal processing
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Etype (P));
Set_Etype (N, Acc_Type);
end Analyze_Reference;
--------------------------------
-- Analyze_Selected_Component --
--------------------------------
-- Prefix is a record type or a task or protected type. In the latter case,
-- the selector must denote a visible entry.
procedure Analyze_Selected_Component (N : Node_Id) is
Name : constant Node_Id := Prefix (N);
Sel : constant Node_Id := Selector_Name (N);
Act_Decl : Node_Id;
Comp : Entity_Id := Empty;
Has_Candidate : Boolean := False;
Hidden_Comp : Entity_Id;
In_Scope : Boolean;
Is_Private_Op : Boolean;
Parent_N : Node_Id;
Prefix_Type : Entity_Id;
Type_To_Use : Entity_Id;
-- In most cases this is the Prefix_Type, but if the Prefix_Type is
-- a class-wide type, we use its root type, whose components are
-- present in the class-wide type.
Is_Single_Concurrent_Object : Boolean;
-- Set True if the prefix is a single task or a single protected object
function Constraint_Has_Unprefixed_Discriminant_Reference
(Typ : Entity_Id) return Boolean;
-- Given a subtype that is subject to a discriminant-dependent
-- constraint, returns True if any of the values of the constraint
-- (i.e., any of the index values for an index constraint, any of
-- the discriminant values for a discriminant constraint)
-- are unprefixed discriminant names.
procedure Find_Component_In_Instance (Rec : Entity_Id);
-- In an instance, a component of a private extension may not be visible
-- while it was visible in the generic. Search candidate scope for a
-- component with the proper identifier. This is only done if all other
-- searches have failed. If a match is found, the Etype of both N and
-- Sel are set from this component, and the entity of Sel is set to
-- reference this component. If no match is found, Entity (Sel) remains
-- unset. For a derived type that is an actual of the instance, the
-- desired component may be found in any ancestor.
function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
-- It is known that the parent of N denotes a subprogram call. Comp
-- is an overloadable component of the concurrent type of the prefix.
-- Determine whether all formals of the parent of N and Comp are mode
-- conformant. If the parent node is not analyzed yet it may be an
-- indexed component rather than a function call.
function Has_Dereference (Nod : Node_Id) return Boolean;
-- Check whether prefix includes a dereference, explicit or implicit,
-- at any recursive level.
function Try_By_Protected_Procedure_Prefixed_View return Boolean;
-- Return True if N is an access attribute whose prefix is a prefixed
-- class-wide (synchronized or protected) interface view for which some
-- interpretation is a procedure with synchronization kind By_Protected
-- _Procedure, and collect all its interpretations (since it may be an
-- overloaded interface primitive); otherwise return False.
------------------------------------------------------
-- Constraint_Has_Unprefixed_Discriminant_Reference --
------------------------------------------------------
function Constraint_Has_Unprefixed_Discriminant_Reference
(Typ : Entity_Id) return Boolean
is
function Is_Discriminant_Name (N : Node_Id) return Boolean is
((Nkind (N) = N_Identifier)
and then (Ekind (Entity (N)) = E_Discriminant));
begin
if Is_Array_Type (Typ) then
declare
Index : Node_Id := First_Index (Typ);
Rng : Node_Id;
begin
while Present (Index) loop
Rng := Index;
if Nkind (Rng) = N_Subtype_Indication then
Rng := Range_Expression (Constraint (Rng));
end if;
if Nkind (Rng) = N_Range then
if Is_Discriminant_Name (Low_Bound (Rng))
or else Is_Discriminant_Name (High_Bound (Rng))
then
return True;
end if;
end if;
Next_Index (Index);
end loop;
end;
else
declare
Elmt : Elmt_Id := First_Elmt (Discriminant_Constraint (Typ));
begin
while Present (Elmt) loop
if Is_Discriminant_Name (Node (Elmt)) then
return True;
end if;
Next_Elmt (Elmt);
end loop;
end;
end if;
return False;
end Constraint_Has_Unprefixed_Discriminant_Reference;
--------------------------------
-- Find_Component_In_Instance --
--------------------------------
procedure Find_Component_In_Instance (Rec : Entity_Id) is
Comp : Entity_Id;
Typ : Entity_Id;
begin
Typ := Rec;
while Present (Typ) loop
Comp := First_Component (Typ);
while Present (Comp) loop
if Chars (Comp) = Chars (Sel) then
Set_Entity_With_Checks (Sel, Comp);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
return;
end if;
Next_Component (Comp);
end loop;
-- If not found, the component may be declared in the parent
-- type or its full view, if any.
if Is_Derived_Type (Typ) then
Typ := Etype (Typ);
if Is_Private_Type (Typ) then
Typ := Full_View (Typ);
end if;
else
return;
end if;
end loop;
-- If we fall through, no match, so no changes made
return;
end Find_Component_In_Instance;
------------------------------
-- Has_Mode_Conformant_Spec --
------------------------------
function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
Comp_Param : Entity_Id;
Param : Node_Id;
Param_Typ : Entity_Id;
begin
Comp_Param := First_Formal (Comp);
if Nkind (Parent (N)) = N_Indexed_Component then
Param := First (Expressions (Parent (N)));
else
Param := First (Parameter_Associations (Parent (N)));
end if;
while Present (Comp_Param)
and then Present (Param)
loop
Param_Typ := Find_Parameter_Type (Param);
if Present (Param_Typ)
and then
not Conforming_Types
(Etype (Comp_Param), Param_Typ, Mode_Conformant)
then
return False;
end if;
Next_Formal (Comp_Param);
Next (Param);
end loop;
-- One of the specs has additional formals; there is no match, unless
-- this may be an indexing of a parameterless call.
-- Note that when expansion is disabled, the corresponding record
-- type of synchronized types is not constructed, so that there is
-- no point is attempting an interpretation as a prefixed call, as
-- this is bound to fail because the primitive operations will not
-- be properly located.
if Present (Comp_Param) or else Present (Param) then
if Needs_No_Actuals (Comp)
and then Is_Array_Type (Etype (Comp))
and then not Expander_Active
then
return True;
else
return False;
end if;
end if;
return True;
end Has_Mode_Conformant_Spec;
---------------------
-- Has_Dereference --
---------------------
function Has_Dereference (Nod : Node_Id) return Boolean is
begin
if Nkind (Nod) = N_Explicit_Dereference then
return True;
elsif Is_Access_Type (Etype (Nod)) then
return True;
elsif Nkind (Nod) in N_Indexed_Component | N_Selected_Component then
return Has_Dereference (Prefix (Nod));
else
return False;
end if;
end Has_Dereference;
----------------------------------------------
-- Try_By_Protected_Procedure_Prefixed_View --
----------------------------------------------
function Try_By_Protected_Procedure_Prefixed_View return Boolean is
Candidate : Node_Id := Empty;
Elmt : Elmt_Id;
Prim : Node_Id;
begin
if Nkind (Parent (N)) = N_Attribute_Reference
and then Attribute_Name (Parent (N)) in
Name_Access
| Name_Unchecked_Access
| Name_Unrestricted_Access
and then Is_Class_Wide_Type (Prefix_Type)
and then (Is_Synchronized_Interface (Prefix_Type)
or else Is_Protected_Interface (Prefix_Type))
then
-- If we have not found yet any interpretation then mark this
-- one as the first interpretation (cf. Add_One_Interp).
if No (Etype (Sel)) then
Set_Etype (Sel, Any_Type);
end if;
Elmt := First_Elmt (Primitive_Operations (Etype (Prefix_Type)));
while Present (Elmt) loop
Prim := Node (Elmt);
if Chars (Prim) = Chars (Sel)
and then Is_By_Protected_Procedure (Prim)
then
Candidate := New_Copy (Prim);
-- Skip the controlling formal; required to check type
-- conformance of the target access to protected type
-- (see Conforming_Types).
Set_First_Entity (Candidate,
Next_Entity (First_Entity (Prim)));
Add_One_Interp (Sel, Candidate, Etype (Prim));
Set_Etype (N, Etype (Prim));
end if;
Next_Elmt (Elmt);
end loop;
end if;
-- Propagate overloaded attribute
if Present (Candidate) and then Is_Overloaded (Sel) then
Set_Is_Overloaded (N);
end if;
return Present (Candidate);
end Try_By_Protected_Procedure_Prefixed_View;
-- Start of processing for Analyze_Selected_Component
begin
Set_Etype (N, Any_Type);
if Is_Overloaded (Name) then
Analyze_Overloaded_Selected_Component (N);
return;
elsif Etype (Name) = Any_Type then
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
return;
else
Prefix_Type := Etype (Name);
end if;
if Is_Access_Type (Prefix_Type) then
-- A RACW object can never be used as prefix of a selected component
-- since that means it is dereferenced without being a controlling
-- operand of a dispatching operation (RM E.2.2(16/1)). Before
-- reporting an error, we must check whether this is actually a
-- dispatching call in prefix form.
if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
and then Comes_From_Source (N)
then
if Try_Object_Operation (N) then
return;
else
Error_Msg_N
("invalid dereference of a remote access-to-class-wide value",
N);
end if;
-- Normal case of selected component applied to access type
else
Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
Prefix_Type := Implicitly_Designated_Type (Prefix_Type);
end if;
-- If we have an explicit dereference of a remote access-to-class-wide
-- value, then issue an error (see RM-E.2.2(16/1)). However we first
-- have to check for the case of a prefix that is a controlling operand
-- of a prefixed dispatching call, as the dereference is legal in that
-- case. Normally this condition is checked in Validate_Remote_Access_
-- To_Class_Wide_Type, but we have to defer the checking for selected
-- component prefixes because of the prefixed dispatching call case.
-- Note that implicit dereferences are checked for this just above.
elsif Nkind (Name) = N_Explicit_Dereference
and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
and then Comes_From_Source (N)
then
if Try_Object_Operation (N) then
return;
else
Error_Msg_N
("invalid dereference of a remote access-to-class-wide value",
N);
end if;
end if;
-- (Ada 2005): if the prefix is the limited view of a type, and
-- the context already includes the full view, use the full view
-- in what follows, either to retrieve a component of to find
-- a primitive operation. If the prefix is an explicit dereference,
-- set the type of the prefix to reflect this transformation.
-- If the nonlimited view is itself an incomplete type, get the
-- full view if available.
if From_Limited_With (Prefix_Type)
and then Has_Non_Limited_View (Prefix_Type)
then
Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
if Nkind (N) = N_Explicit_Dereference then
Set_Etype (Prefix (N), Prefix_Type);
end if;
end if;
if Ekind (Prefix_Type) = E_Private_Subtype then
Prefix_Type := Base_Type (Prefix_Type);
end if;
Type_To_Use := Prefix_Type;
-- For class-wide types, use the entity list of the root type. This
-- indirection is specially important for private extensions because
-- only the root type get switched (not the class-wide type).
if Is_Class_Wide_Type (Prefix_Type) then
Type_To_Use := Root_Type (Prefix_Type);
end if;
-- If the prefix is a single concurrent object, use its name in error
-- messages, rather than that of its anonymous type.
Is_Single_Concurrent_Object :=
Is_Concurrent_Type (Prefix_Type)
and then Is_Internal_Name (Chars (Prefix_Type))
and then not Is_Derived_Type (Prefix_Type)
and then Is_Entity_Name (Name);
-- Avoid initializing Comp if that initialization is not needed
-- (and, more importantly, if the call to First_Entity could fail).
if Has_Discriminants (Type_To_Use)
or else Is_Record_Type (Type_To_Use)
or else Is_Private_Type (Type_To_Use)
or else Is_Concurrent_Type (Type_To_Use)
then
Comp := First_Entity (Type_To_Use);
end if;
-- If the selector has an original discriminant, the node appears in
-- an instance. Replace the discriminant with the corresponding one
-- in the current discriminated type. For nested generics, this must
-- be done transitively, so note the new original discriminant.
if Nkind (Sel) = N_Identifier
and then In_Instance
and then Present (Original_Discriminant (Sel))
then
Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
-- Mark entity before rewriting, for completeness and because
-- subsequent semantic checks might examine the original node.
Set_Entity (Sel, Comp);
Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
Set_Original_Discriminant (Selector_Name (N), Comp);
Set_Etype (N, Etype (Comp));
Check_Implicit_Dereference (N, Etype (Comp));
elsif Is_Record_Type (Prefix_Type) then
-- Find a component with the given name. If the node is a prefixed
-- call, do not examine components whose visibility may be
-- accidental.
while Present (Comp)
and then not Is_Prefixed_Call (N)
-- When the selector has been resolved to a function then we may be
-- looking at a prefixed call which has been preanalyzed already as
-- part of a class condition. In such cases it is possible for a
-- derived type to declare a component which has the same name as
-- a primitive used in a parent's class condition.
-- Avoid seeing components as possible interpretations of the
-- selected component when this is true.
and then not (Inside_Class_Condition_Preanalysis
and then Present (Entity (Sel))
and then Ekind (Entity (Sel)) = E_Function)
loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp, N)
then
Set_Entity_With_Checks (Sel, Comp);
Set_Etype (Sel, Etype (Comp));
if Ekind (Comp) = E_Discriminant then
if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
Error_Msg_N
("cannot reference discriminant of unchecked union",
Sel);
end if;
if Is_Generic_Type (Prefix_Type)
or else
Is_Generic_Type (Root_Type (Prefix_Type))
then
Set_Original_Discriminant (Sel, Comp);
end if;
end if;
-- Resolve the prefix early otherwise it is not possible to
-- build the actual subtype of the component: it may need
-- to duplicate this prefix and duplication is only allowed
-- on fully resolved expressions.
Resolve (Name);
-- Ada 2005 (AI-50217): Check wrong use of incomplete types or
-- subtypes in a package specification.
-- Example:
-- limited with Pkg;
-- package Pkg is
-- type Acc_Inc is access Pkg.T;
-- X : Acc_Inc;
-- N : Natural := X.all.Comp; -- ERROR, limited view
-- end Pkg; -- Comp is not visible
if Nkind (Name) = N_Explicit_Dereference
and then From_Limited_With (Etype (Prefix (Name)))
and then not Is_Potentially_Use_Visible (Etype (Name))
and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
N_Package_Specification
then
Error_Msg_NE
("premature usage of incomplete}", Prefix (Name),
Etype (Prefix (Name)));
end if;
-- We never need an actual subtype for the case of a selection
-- for a indexed component of a non-packed array, since in
-- this case gigi generates all the checks and can find the
-- necessary bounds information.
-- We also do not need an actual subtype for the case of a
-- first, last, length, or range attribute applied to a
-- non-packed array, since gigi can again get the bounds in
-- these cases (gigi cannot handle the packed case, since it
-- has the bounds of the packed array type, not the original
-- bounds of the type). However, if the prefix is itself a
-- selected component, as in a.b.c (i), gigi may regard a.b.c
-- as a dynamic-sized temporary, so we do generate an actual
-- subtype for this case.
Parent_N := Parent (N);
if not Is_Packed (Etype (Comp))
and then
((Nkind (Parent_N) = N_Indexed_Component
and then Nkind (Name) /= N_Selected_Component)
or else
(Nkind (Parent_N) = N_Attribute_Reference
and then
Attribute_Name (Parent_N) in Name_First
| Name_Last
| Name_Length
| Name_Range))
then
Set_Etype (N, Etype (Comp));
-- If full analysis is not enabled, we do not generate an
-- actual subtype, because in the absence of expansion
-- reference to a formal of a protected type, for example,
-- will not be properly transformed, and will lead to
-- out-of-scope references in gigi.
-- In all other cases, we currently build an actual subtype.
-- It seems likely that many of these cases can be avoided,
-- but right now, the front end makes direct references to the
-- bounds (e.g. in generating a length check), and if we do
-- not make an actual subtype, we end up getting a direct
-- reference to a discriminant, which will not do.
elsif Full_Analysis then
Act_Decl :=
Build_Actual_Subtype_Of_Component (Etype (Comp), N);
Insert_Action (N, Act_Decl);
if No (Act_Decl) then
Set_Etype (N, Etype (Comp));
else
-- If discriminants were present in the component
-- declaration, they have been replaced by the
-- actual values in the prefix object.
declare
Subt : constant Entity_Id :=
Defining_Identifier (Act_Decl);
begin
Set_Etype (Subt, Base_Type (Etype (Comp)));
Set_Etype (N, Subt);
end;
end if;
-- If Etype (Comp) is an access type whose designated subtype
-- is constrained by an unprefixed discriminant value,
-- then ideally we would build a new subtype with an
-- appropriately prefixed discriminant value and use that
-- instead, as is done in Build_Actual_Subtype_Of_Component.
-- That turns out to be difficult in this context (with
-- Full_Analysis = False, we could be processing a selected
-- component that occurs in a Postcondition pragma;
-- PPC pragmas are odd because they can contain references
-- to formal parameters that occur outside the subprogram).
-- So instead we punt on building a new subtype and we
-- use the base type instead. This might introduce
-- correctness problems if N were the target of an
-- assignment (because a required check might be omitted);
-- fortunately, that's impossible because a reference to the
-- current instance of a type does not denote a variable view
-- when the reference occurs within an aspect_specification.
-- GNAT's Precondition and Postcondition pragmas follow the
-- same rules as a Pre or Post aspect_specification.
elsif Has_Discriminant_Dependent_Constraint (Comp)
and then Ekind (Etype (Comp)) = E_Access_Subtype
and then Constraint_Has_Unprefixed_Discriminant_Reference
(Designated_Type (Etype (Comp)))
then
Set_Etype (N, Base_Type (Etype (Comp)));
-- If Full_Analysis not enabled, just set the Etype
else
Set_Etype (N, Etype (Comp));
end if;
Check_Implicit_Dereference (N, Etype (N));
return;
end if;
-- If the prefix is a private extension, check only the visible
-- components of the partial view. This must include the tag,
-- which can appear in expanded code in a tag check.
if Ekind (Type_To_Use) = E_Record_Type_With_Private
and then Chars (Selector_Name (N)) /= Name_uTag
then
exit when Comp = Last_Entity (Type_To_Use);
end if;
Next_Entity (Comp);
end loop;
-- Ada 2005 (AI-252): The selected component can be interpreted as
-- a prefixed view of a subprogram. Depending on the context, this is
-- either a name that can appear in a renaming declaration, or part
-- of an enclosing call given in prefix form.
-- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
-- selected component should resolve to a name.
-- Extension feature: Also support calls with prefixed views for
-- untagged record types.
if Ada_Version >= Ada_2005
and then (Is_Tagged_Type (Prefix_Type)
or else Core_Extensions_Allowed)
and then not Is_Concurrent_Type (Prefix_Type)
then
if Nkind (Parent (N)) = N_Generic_Association
or else Nkind (Parent (N)) = N_Requeue_Statement
or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
then
if Find_Primitive_Operation (N) then
return;
end if;
elsif Try_By_Protected_Procedure_Prefixed_View then
return;
elsif Try_Object_Operation (N) then
return;
end if;
-- If the transformation fails, it will be necessary to redo the
-- analysis with all errors enabled, to indicate candidate
-- interpretations and reasons for each failure ???
end if;
elsif Is_Private_Type (Prefix_Type) then
-- Allow access only to discriminants of the type. If the type has
-- no full view, gigi uses the parent type for the components, so we
-- do the same here.
if No (Full_View (Prefix_Type)) then
Type_To_Use := Root_Type (Base_Type (Prefix_Type));
Comp := First_Entity (Type_To_Use);
end if;
while Present (Comp) loop
if Chars (Comp) = Chars (Sel) then
if Ekind (Comp) = E_Discriminant then
Set_Entity_With_Checks (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
Check_Implicit_Dereference (N, Etype (N));
if Is_Generic_Type (Prefix_Type)
or else Is_Generic_Type (Root_Type (Prefix_Type))
then
Set_Original_Discriminant (Sel, Comp);
end if;
-- Before declaring an error, check whether this is tagged
-- private type and a call to a primitive operation.
elsif Ada_Version >= Ada_2005
and then Is_Tagged_Type (Prefix_Type)
and then Try_Object_Operation (N)
then
return;
else
Error_Msg_Node_2 := First_Subtype (Prefix_Type);
Error_Msg_NE ("invisible selector& for }", N, Sel);
Set_Entity (Sel, Any_Id);
Set_Etype (N, Any_Type);
end if;
return;
end if;
Next_Entity (Comp);
end loop;
-- Extension feature: Also support calls with prefixed views for
-- untagged private types.
if Core_Extensions_Allowed then
if Try_Object_Operation (N) then
return;
end if;
end if;
elsif Is_Concurrent_Type (Prefix_Type) then
-- Find visible operation with given name. For a protected type,
-- the possible candidates are discriminants, entries or protected
-- subprograms. For a task type, the set can only include entries or
-- discriminants if the task type is not an enclosing scope. If it
-- is an enclosing scope (e.g. in an inner task) then all entities
-- are visible, but the prefix must denote the enclosing scope, i.e.
-- can only be a direct name or an expanded name.
Set_Etype (Sel, Any_Type);
Hidden_Comp := Empty;
In_Scope := In_Open_Scopes (Prefix_Type);
Is_Private_Op := False;
while Present (Comp) loop
-- Do not examine private operations of the type if not within
-- its scope.
if Chars (Comp) = Chars (Sel) then
if Is_Overloadable (Comp)
and then (In_Scope
or else Comp /= First_Private_Entity (Type_To_Use))
then
Add_One_Interp (Sel, Comp, Etype (Comp));
if Comp = First_Private_Entity (Type_To_Use) then
Is_Private_Op := True;
end if;
-- If the prefix is tagged, the correct interpretation may
-- lie in the primitive or class-wide operations of the
-- type. Perform a simple conformance check to determine
-- whether Try_Object_Operation should be invoked even if
-- a visible entity is found.
if Is_Tagged_Type (Prefix_Type)
and then Nkind (Parent (N)) in N_Function_Call
| N_Indexed_Component
| N_Procedure_Call_Statement
and then Has_Mode_Conformant_Spec (Comp)
then
Has_Candidate := True;
end if;
-- Note: a selected component may not denote a component of a
-- protected type (4.1.3(7)).
elsif Ekind (Comp) in E_Discriminant | E_Entry_Family
or else (In_Scope
and then not Is_Protected_Type (Prefix_Type)
and then Is_Entity_Name (Name))
then
Set_Entity_With_Checks (Sel, Comp);
Generate_Reference (Comp, Sel);
-- The selector is not overloadable, so we have a candidate
-- interpretation.
Has_Candidate := True;
else
if Ekind (Comp) = E_Component then
Hidden_Comp := Comp;
end if;
goto Next_Comp;
end if;
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
if Ekind (Comp) = E_Discriminant then
Set_Original_Discriminant (Sel, Comp);
end if;
end if;
<<Next_Comp>>
if Comp = First_Private_Entity (Type_To_Use) then
if Etype (Sel) /= Any_Type then
-- If the first private entity's name matches, then treat
-- it as a private op: needed for the error check for
-- illegal selection of private entities further below.
if Chars (Comp) = Chars (Sel) then
Is_Private_Op := True;
end if;
-- We have a candidate, so exit the loop
exit;
else
-- Indicate that subsequent operations are private,
-- for better error reporting.
Is_Private_Op := True;
end if;
end if;
-- Do not examine private operations if not within scope of
-- the synchronized type.
exit when not In_Scope
and then
Comp = First_Private_Entity (Base_Type (Prefix_Type));
Next_Entity (Comp);
end loop;
-- If the scope is a current instance, the prefix cannot be an
-- expression of the same type, unless the selector designates a
-- public operation (otherwise that would represent an attempt to
-- reach an internal entity of another synchronized object).
-- This is legal if prefix is an access to such type and there is
-- a dereference, or is a component with a dereferenced prefix.
-- It is also legal if the prefix is a component of a task type,
-- and the selector is one of the task operations.
if In_Scope
and then not Is_Entity_Name (Name)
and then not Has_Dereference (Name)
then
if Is_Task_Type (Prefix_Type)
and then Present (Entity (Sel))
and then Is_Entry (Entity (Sel))
then
null;
elsif Is_Protected_Type (Prefix_Type)
and then Is_Overloadable (Entity (Sel))
and then not Is_Private_Op
then
null;
else
Error_Msg_NE
("invalid reference to internal operation of some object of "
& "type &", N, Type_To_Use);
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
return;
end if;
-- Another special case: the prefix may denote an object of the type
-- (but not a type) in which case this is an external call and the
-- operation must be public.
elsif In_Scope
and then Is_Object_Reference (Original_Node (Prefix (N)))
and then Comes_From_Source (N)
and then Is_Private_Op
then
if Present (Hidden_Comp) then
Error_Msg_NE
("invalid reference to private component of object of type "
& "&", N, Type_To_Use);
else
Error_Msg_NE
("invalid reference to private operation of some object of "
& "type &", N, Type_To_Use);
end if;
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
return;
end if;
-- If there is no visible entity with the given name or none of the
-- visible entities are plausible interpretations, check whether
-- there is some other primitive operation with that name.
if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
if (Etype (N) = Any_Type
or else not Has_Candidate)
and then Try_Object_Operation (N)
then
return;
-- If the context is not syntactically a procedure call, it
-- may be a call to a primitive function declared outside of
-- the synchronized type.
-- If the context is a procedure call, there might still be
-- an overloading between an entry and a primitive procedure
-- declared outside of the synchronized type, called in prefix
-- notation. This is harder to disambiguate because in one case
-- the controlling formal is implicit ???
elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
and then Nkind (Parent (N)) /= N_Indexed_Component
and then Try_Object_Operation (N)
then
return;
end if;
-- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
-- entry or procedure of a tagged concurrent type we must check
-- if there are class-wide subprograms covering the primitive. If
-- true then Try_Object_Operation reports the error.
if Has_Candidate
and then Is_Concurrent_Type (Prefix_Type)
and then Nkind (Parent (N)) = N_Procedure_Call_Statement
then
-- Duplicate the call. This is required to avoid problems with
-- the tree transformations performed by Try_Object_Operation.
-- Set properly the parent of the copied call, because it is
-- about to be reanalyzed.
declare
Par : constant Node_Id := New_Copy_Tree (Parent (N));
begin
Set_Parent (Par, Parent (Parent (N)));
if Try_Object_Operation
(Sinfo.Nodes.Name (Par), CW_Test_Only => True)
then
return;
end if;
end;
end if;
end if;
if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
-- Case of a prefix of a protected type: selector might denote
-- an invisible private component.
Comp := First_Private_Entity (Base_Type (Prefix_Type));
while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
Next_Entity (Comp);
end loop;
if Present (Comp) then
if Is_Single_Concurrent_Object then
Error_Msg_Node_2 := Entity (Name);
Error_Msg_NE ("invisible selector& for &", N, Sel);
else
Error_Msg_Node_2 := First_Subtype (Prefix_Type);
Error_Msg_NE ("invisible selector& for }", N, Sel);
end if;
return;
end if;
end if;
Set_Is_Overloaded (N, Is_Overloaded (Sel));
-- Extension feature: Also support calls with prefixed views for
-- untagged types.
elsif Core_Extensions_Allowed
and then Try_Object_Operation (N)
then
return;
else
-- Invalid prefix
Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
end if;
-- If N still has no type, the component is not defined in the prefix
if Etype (N) = Any_Type then
if Is_Single_Concurrent_Object then
Error_Msg_Node_2 := Entity (Name);
Error_Msg_NE ("no selector& for&", N, Sel);
Check_Misspelled_Selector (Type_To_Use, Sel);
-- If this is a derived formal type, the parent may have different
-- visibility at this point. Try for an inherited component before
-- reporting an error.
elsif Is_Generic_Type (Prefix_Type)
and then Ekind (Prefix_Type) = E_Record_Type_With_Private
and then Prefix_Type /= Etype (Prefix_Type)
and then Is_Record_Type (Etype (Prefix_Type))
then
Set_Etype (Prefix (N), Etype (Prefix_Type));
Analyze_Selected_Component (N);
return;
-- Similarly, if this is the actual for a formal derived type, or
-- a derived type thereof, the component inherited from the generic
-- parent may not be visible in the actual, but the selected
-- component is legal. Climb up the derivation chain of the generic
-- parent type until we find the proper ancestor type.
elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
declare
Par : Entity_Id := Prefix_Type;
begin
-- Climb up derivation chain to generic actual subtype
while not Is_Generic_Actual_Type (Par) loop
if Ekind (Par) = E_Record_Type then
Par := Parent_Subtype (Par);
exit when No (Par);
else
exit when Par = Etype (Par);
Par := Etype (Par);
end if;
end loop;
if Present (Par) and then Is_Generic_Actual_Type (Par) then
-- Now look for component in ancestor types
Par := Generic_Parent_Type (Declaration_Node (Par));
loop
Find_Component_In_Instance (Par);
exit when Present (Entity (Sel))
or else Par = Etype (Par);
Par := Etype (Par);
end loop;
-- Another special case: the type is an extension of a private
-- type T, either is an actual in an instance or is immediately
-- visible, and we are in the body of the instance, which means
-- the generic body had a full view of the type declaration for
-- T or some ancestor that defines the component in question.
-- This happens because Is_Visible_Component returned False on
-- this component, as T or the ancestor is still private since
-- the Has_Private_View mechanism is bypassed because T or the
-- ancestor is not directly referenced in the generic body.
elsif Is_Derived_Type (Type_To_Use)
and then (Used_As_Generic_Actual (Type_To_Use)
or else Is_Immediately_Visible (Type_To_Use))
and then In_Instance_Body
then
Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
end if;
end;
-- The search above must have eventually succeeded, since the
-- selected component was legal in the generic.
if No (Entity (Sel)) then
raise Program_Error;
end if;
return;
-- Component not found, specialize error message when appropriate
else
if Ekind (Prefix_Type) = E_Record_Subtype then
-- Check whether this is a component of the base type which
-- is absent from a statically constrained subtype. This will
-- raise constraint error at run time, but is not a compile-
-- time error. When the selector is illegal for base type as
-- well fall through and generate a compilation error anyway.
Comp := First_Component (Base_Type (Prefix_Type));
while Present (Comp) loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp, Sel)
then
Set_Entity_With_Checks (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
-- Emit appropriate message. The node will be replaced
-- by an appropriate raise statement.
-- Note that in SPARK mode, as with all calls to apply a
-- compile time constraint error, this will be made into
-- an error to simplify the processing of the formal
-- verification backend.
Apply_Compile_Time_Constraint_Error
(N, "component not present in }??",
CE_Discriminant_Check_Failed,
Ent => Prefix_Type,
Emit_Message =>
SPARK_Mode = On or not In_Instance_Not_Visible);
return;
end if;
Next_Component (Comp);
end loop;
end if;
Error_Msg_Node_2 := First_Subtype (Prefix_Type);
Error_Msg_NE ("no selector& for}", N, Sel);
-- Add information in the case of an incomplete prefix
if Is_Incomplete_Type (Type_To_Use) then
declare
Inc : constant Entity_Id := First_Subtype (Type_To_Use);
begin
if From_Limited_With (Scope (Type_To_Use)) then
Error_Msg_NE
("\limited view of& has no components", N, Inc);
else
Error_Msg_NE
("\premature usage of incomplete type&", N, Inc);
if Nkind (Parent (Inc)) =
N_Incomplete_Type_Declaration
then
-- Record location of premature use in entity so that
-- a continuation message is generated when the
-- completion is seen.
Set_Premature_Use (Parent (Inc), N);
end if;
end if;
end;
end if;
Check_Misspelled_Selector (Type_To_Use, Sel);
end if;
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
end if;
end Analyze_Selected_Component;
---------------------------
-- Analyze_Short_Circuit --
---------------------------
procedure Analyze_Short_Circuit (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Ind : Interp_Index;
It : Interp;
begin
Set_Etype (N, Any_Type);
Analyze_Expression (L);
Analyze_Expression (R);
if not Is_Overloaded (L) then
if Root_Type (Etype (L)) = Standard_Boolean
and then Has_Compatible_Type (R, Etype (L))
then
Add_One_Interp (N, Etype (L), Etype (L));
end if;
else
Get_First_Interp (L, Ind, It);
while Present (It.Typ) loop
if Root_Type (It.Typ) = Standard_Boolean
and then Has_Compatible_Type (R, It.Typ)
then
Add_One_Interp (N, It.Typ, It.Typ);
end if;
Get_Next_Interp (Ind, It);
end loop;
end if;
-- Here we have failed to find an interpretation. Clearly we know that
-- it is not the case that both operands can have an interpretation of
-- Boolean, but this is by far the most likely intended interpretation.
-- So we simply resolve both operands as Booleans, and at least one of
-- these resolutions will generate an error message, and we do not need
-- to give another error message on the short circuit operation itself.
if Etype (N) = Any_Type then
Resolve (L, Standard_Boolean);
Resolve (R, Standard_Boolean);
Set_Etype (N, Standard_Boolean);
end if;
end Analyze_Short_Circuit;
-------------------
-- Analyze_Slice --
-------------------
procedure Analyze_Slice (N : Node_Id) is
D : constant Node_Id := Discrete_Range (N);
P : constant Node_Id := Prefix (N);
Array_Type : Entity_Id;
Index_Type : Entity_Id;
procedure Analyze_Overloaded_Slice;
-- If the prefix is overloaded, select those interpretations that
-- yield a one-dimensional array type.
------------------------------
-- Analyze_Overloaded_Slice --
------------------------------
procedure Analyze_Overloaded_Slice is
I : Interp_Index;
It : Interp;
Typ : Entity_Id;
begin
Set_Etype (N, Any_Type);
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
Typ := It.Typ;
if Is_Access_Type (Typ) then
Typ := Designated_Type (Typ);
Error_Msg_NW
(Warn_On_Dereference, "?d?implicit dereference", N);
end if;
if Is_Array_Type (Typ)
and then Number_Dimensions (Typ) = 1
and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
then
Add_One_Interp (N, Typ, Typ);
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type then
Error_Msg_N ("expect array type in prefix of slice", N);
end if;
end Analyze_Overloaded_Slice;
-- Start of processing for Analyze_Slice
begin
Analyze (P);
Analyze (D);
if Is_Overloaded (P) then
Analyze_Overloaded_Slice;
else
Array_Type := Etype (P);
Set_Etype (N, Any_Type);
if Is_Access_Type (Array_Type) then
Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
Array_Type := Implicitly_Designated_Type (Array_Type);
end if;
if not Is_Array_Type (Array_Type) then
Wrong_Type (P, Any_Array);
elsif Number_Dimensions (Array_Type) > 1 then
Error_Msg_N
("type is not one-dimensional array in slice prefix", N);
else
if Ekind (Array_Type) = E_String_Literal_Subtype then
Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
else
Index_Type := Etype (First_Index (Array_Type));
end if;
if not Has_Compatible_Type (D, Index_Type) then
Wrong_Type (D, Index_Type);
else
Set_Etype (N, Array_Type);
end if;
end if;
end if;
end Analyze_Slice;
-----------------------------
-- Analyze_Type_Conversion --
-----------------------------
procedure Analyze_Type_Conversion (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
Mark : constant Entity_Id := Subtype_Mark (N);
Typ : Entity_Id;
begin
-- If Conversion_OK is set, then the Etype is already set, and the only
-- processing required is to analyze the expression. This is used to
-- construct certain "illegal" conversions which are not allowed by Ada
-- semantics, but can be handled by Gigi, see Sinfo for further details.
if Conversion_OK (N) then
Analyze (Expr);
return;
end if;
-- Otherwise full type analysis is required, as well as some semantic
-- checks to make sure the argument of the conversion is appropriate.
Find_Type (Mark);
Typ := Entity (Mark);
Set_Etype (N, Typ);
Analyze_Expression (Expr);
Check_Fully_Declared (Typ, N);
Validate_Remote_Type_Type_Conversion (N);
-- Only remaining step is validity checks on the argument. These
-- are skipped if the conversion does not come from the source.
if not Comes_From_Source (N) then
return;
-- If there was an error in a generic unit, no need to replicate the
-- error message. Conversely, constant-folding in the generic may
-- transform the argument of a conversion into a string literal, which
-- is legal. Therefore the following tests are not performed in an
-- instance. The same applies to an inlined body.
elsif In_Instance or In_Inlined_Body then
return;
elsif Nkind (Expr) = N_Null then
Error_Msg_N ("argument of conversion cannot be null", N);
Error_Msg_N ("\use qualified expression instead", N);
Set_Etype (N, Any_Type);
elsif Nkind (Expr) = N_Aggregate then
Error_Msg_N ("argument of conversion cannot be aggregate", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_Allocator then
Error_Msg_N ("argument of conversion cannot be allocator", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_String_Literal then
Error_Msg_N ("argument of conversion cannot be string literal", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_Character_Literal then
if Ada_Version = Ada_83 then
Resolve (Expr, Typ);
else
Error_Msg_N
("argument of conversion cannot be character literal", N);
Error_Msg_N ("\use qualified expression instead", N);
end if;
elsif Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) in Name_Access
| Name_Unchecked_Access
| Name_Unrestricted_Access
then
Error_Msg_N
("argument of conversion cannot be access attribute", N);
Error_Msg_N ("\use qualified expression instead", N);
end if;
-- A formal parameter of a specific tagged type whose related subprogram
-- is subject to pragma Extensions_Visible with value "False" cannot
-- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
-- internally generated expressions.
if Is_Class_Wide_Type (Typ)
and then Comes_From_Source (Expr)
and then Is_EVF_Expression (Expr)
then
Error_Msg_N
("formal parameter cannot be converted to class-wide type when "
& "Extensions_Visible is False", Expr);
end if;
end Analyze_Type_Conversion;
----------------------
-- Analyze_Unary_Op --
----------------------
procedure Analyze_Unary_Op (N : Node_Id) is
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (R);
-- If the entity is already set, the node is the instantiation of a
-- generic node with a non-local reference, or was manufactured by a
-- call to Make_Op_xxx. In either case the entity is known to be valid,
-- and we do not need to collect interpretations, instead we just get
-- the single possible interpretation.
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Find_Unary_Types (R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
if No (Next_Entity (First_Entity (Op_Id))) then
Find_Unary_Types (R, Op_Id, N);
end if;
elsif Is_Overloadable (Op_Id) then
Analyze_User_Defined_Unary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Unary_Op;
----------------------------------
-- Analyze_Unchecked_Expression --
----------------------------------
procedure Analyze_Unchecked_Expression (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
begin
Analyze (Expr, Suppress => All_Checks);
Set_Etype (N, Etype (Expr));
Save_Interps (Expr, N);
end Analyze_Unchecked_Expression;
---------------------------------------
-- Analyze_Unchecked_Type_Conversion --
---------------------------------------
procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
Mark : constant Entity_Id := Subtype_Mark (N);
begin
Find_Type (Mark);
Set_Etype (N, Entity (Mark));
Analyze_Expression (Expr);
end Analyze_Unchecked_Type_Conversion;
------------------------------------
-- Analyze_User_Defined_Binary_Op --
------------------------------------
procedure Analyze_User_Defined_Binary_Op
(N : Node_Id;
Op_Id : Entity_Id) is
begin
declare
F1 : constant Entity_Id := First_Formal (Op_Id);
F2 : constant Entity_Id := Next_Formal (F1);
begin
-- Verify that Op_Id is a visible binary function. Note that since
-- we know Op_Id is overloaded, potentially use visible means use
-- visible for sure (RM 9.4(11)). Be prepared for previous errors.
if Ekind (Op_Id) = E_Function
and then Present (F2)
and then (Is_Immediately_Visible (Op_Id)
or else Is_Potentially_Use_Visible (Op_Id))
and then (Has_Compatible_Type (Left_Opnd (N), Etype (F1))
or else Etype (F1) = Any_Type)
and then (Has_Compatible_Type (Right_Opnd (N), Etype (F2))
or else Etype (F2) = Any_Type)
then
Add_One_Interp (N, Op_Id, Base_Type (Etype (Op_Id)));
-- If the operands are overloaded, indicate that the current
-- type is a viable candidate. This is redundant in most cases,
-- but for equality and comparison operators where the context
-- does not impose a type on the operands, setting the proper
-- type is necessary to avoid subsequent ambiguities during
-- resolution, when both user-defined and predefined operators
-- may be candidates.
if Is_Overloaded (Left_Opnd (N)) then
Set_Etype (Left_Opnd (N), Etype (F1));
end if;
if Is_Overloaded (Right_Opnd (N)) then
Set_Etype (Right_Opnd (N), Etype (F2));
end if;
if Debug_Flag_E then
Write_Str ("user defined operator ");
Write_Name (Chars (Op_Id));
Write_Str (" on node ");
Write_Int (Int (N));
Write_Eol;
end if;
end if;
end;
end Analyze_User_Defined_Binary_Op;
-----------------------------------
-- Analyze_User_Defined_Unary_Op --
-----------------------------------
procedure Analyze_User_Defined_Unary_Op
(N : Node_Id;
Op_Id : Entity_Id)
is
begin
-- Only do analysis if the operator Comes_From_Source, since otherwise
-- the operator was generated by the expander, and all such operators
-- always refer to the operators in package Standard.
if Comes_From_Source (N) then
declare
F : constant Entity_Id := First_Formal (Op_Id);
begin
-- Verify that Op_Id is a visible unary function. Note that since
-- we know Op_Id is overloaded, potentially use visible means use
-- visible for sure (RM 9.4(11)).
if Ekind (Op_Id) = E_Function
and then No (Next_Formal (F))
and then (Is_Immediately_Visible (Op_Id)
or else Is_Potentially_Use_Visible (Op_Id))
and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
then
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
end;
end if;
end Analyze_User_Defined_Unary_Op;
---------------------------
-- Check_Arithmetic_Pair --
---------------------------
procedure Check_Arithmetic_Pair
(T1, T2 : Entity_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Op_Name : constant Name_Id := Chars (Op_Id);
function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
-- Check whether the fixed-point type Typ has a user-defined operator
-- (multiplication or division) that should hide the corresponding
-- predefined operator. Used to implement Ada 2005 AI-264, to make
-- such operators more visible and therefore useful.
--
-- If the name of the operation is an expanded name with prefix
-- Standard, the predefined universal fixed operator is available,
-- as specified by AI-420 (RM 4.5.5 (19.1/2)).
------------------
-- Has_Fixed_Op --
------------------
function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
Bas : constant Entity_Id := Base_Type (Typ);
Ent : Entity_Id;
F1 : Entity_Id;
F2 : Entity_Id;
begin
-- If the universal_fixed operation is given explicitly the rule
-- concerning primitive operations of the type do not apply.
if Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Expanded_Name
and then Entity (Prefix (Name (N))) = Standard_Standard
then
return False;
end if;
-- The operation is treated as primitive if it is declared in the
-- same scope as the type, and therefore on the same entity chain.
Ent := Next_Entity (Typ);
while Present (Ent) loop
if Chars (Ent) = Chars (Op) then
F1 := First_Formal (Ent);
F2 := Next_Formal (F1);
-- The operation counts as primitive if either operand or
-- result are of the given base type, and both operands are
-- fixed point types.
if (Base_Type (Etype (F1)) = Bas
and then Is_Fixed_Point_Type (Etype (F2)))
or else
(Base_Type (Etype (F2)) = Bas
and then Is_Fixed_Point_Type (Etype (F1)))
or else
(Base_Type (Etype (Ent)) = Bas
and then Is_Fixed_Point_Type (Etype (F1))
and then Is_Fixed_Point_Type (Etype (F2)))
then
return True;
end if;
end if;
Next_Entity (Ent);
end loop;
return False;
end Has_Fixed_Op;
-- Start of processing for Check_Arithmetic_Pair
begin
if Op_Name in Name_Op_Add | Name_Op_Subtract then
if Is_Numeric_Type (T1)
and then Is_Numeric_Type (T2)
and then (Covers (T1 => T1, T2 => T2)
or else
Covers (T1 => T2, T2 => T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
end if;
elsif Op_Name in Name_Op_Multiply | Name_Op_Divide then
if Is_Fixed_Point_Type (T1)
and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
then
-- Add one interpretation with universal fixed result
if not Has_Fixed_Op (T1, Op_Id)
or else Nkind (Parent (N)) = N_Type_Conversion
then
Add_One_Interp (N, Op_Id, Universal_Fixed);
end if;
elsif Is_Fixed_Point_Type (T2)
and then T1 = Universal_Real
and then
(not Has_Fixed_Op (T1, Op_Id)
or else Nkind (Parent (N)) = N_Type_Conversion)
then
Add_One_Interp (N, Op_Id, Universal_Fixed);
elsif Is_Numeric_Type (T1)
and then Is_Numeric_Type (T2)
and then (Covers (T1 => T1, T2 => T2)
or else
Covers (T1 => T2, T2 => T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
elsif Is_Fixed_Point_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, T1);
elsif T2 = Universal_Real
and then Base_Type (T1) = Base_Type (Standard_Integer)
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, Any_Fixed);
elsif T1 = Universal_Real
and then Base_Type (T2) = Base_Type (Standard_Integer)
then
Add_One_Interp (N, Op_Id, Any_Fixed);
elsif Is_Fixed_Point_Type (T2)
and then (Base_Type (T1) = Base_Type (Standard_Integer)
or else T1 = Universal_Integer)
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, T2);
elsif T1 = Universal_Real and then T2 = Universal_Integer then
Add_One_Interp (N, Op_Id, T1);
elsif T2 = Universal_Real
and then T1 = Universal_Integer
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, T2);
end if;
elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
if Is_Integer_Type (T1)
and then (Covers (T1 => T1, T2 => T2)
or else
Covers (T1 => T2, T2 => T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
end if;
elsif Op_Name = Name_Op_Expon then
if Is_Numeric_Type (T1)
and then not Is_Fixed_Point_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, Base_Type (T1));
end if;
else pragma Assert (Nkind (N) in N_Op_Shift);
-- If not one of the predefined operators, the node may be one
-- of the intrinsic functions. Its kind is always specific, and
-- we can use it directly, rather than the name of the operation.
if Is_Integer_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, Base_Type (T1));
end if;
end if;
end Check_Arithmetic_Pair;
-------------------------------
-- Check_Misspelled_Selector --
-------------------------------
procedure Check_Misspelled_Selector
(Prefix : Entity_Id;
Sel : Node_Id)
is
Max_Suggestions : constant := 2;
Nr_Of_Suggestions : Natural := 0;
Suggestion_1 : Entity_Id := Empty;
Suggestion_2 : Entity_Id := Empty;
Comp : Entity_Id;
begin
-- All the components of the prefix of selector Sel are matched against
-- Sel and a count is maintained of possible misspellings. When at
-- the end of the analysis there are one or two (not more) possible
-- misspellings, these misspellings will be suggested as possible
-- correction.
if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
-- Concurrent types should be handled as well ???
return;
end if;
Comp := First_Entity (Prefix);
while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
if Is_Visible_Component (Comp, Sel) then
if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
case Nr_Of_Suggestions is
when 1 => Suggestion_1 := Comp;
when 2 => Suggestion_2 := Comp;
when others => null;
end case;
end if;
end if;
Next_Entity (Comp);
end loop;
-- Report at most two suggestions
if Nr_Of_Suggestions = 1 then
Error_Msg_NE -- CODEFIX
("\possible misspelling of&", Sel, Suggestion_1);
elsif Nr_Of_Suggestions = 2 then
Error_Msg_Node_2 := Suggestion_2;
Error_Msg_NE -- CODEFIX
("\possible misspelling of& or&", Sel, Suggestion_1);
end if;
end Check_Misspelled_Selector;
-------------------
-- Diagnose_Call --
-------------------
procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
Actual : Node_Id;
X : Interp_Index;
It : Interp;
Err_Mode : Boolean;
New_Nam : Node_Id;
Num_Actuals : Natural;
Num_Interps : Natural;
Void_Interp_Seen : Boolean := False;
Success : Boolean;
pragma Warnings (Off, Boolean);
begin
Num_Actuals := 0;
Actual := First_Actual (N);
while Present (Actual) loop
-- Ada 2005 (AI-50217): Post an error in case of premature
-- usage of an entity from the limited view.
if not Analyzed (Etype (Actual))
and then From_Limited_With (Etype (Actual))
and then Ada_Version >= Ada_2005
then
Error_Msg_Qual_Level := 1;
Error_Msg_NE
("missing with_clause for scope of imported type&",
Actual, Etype (Actual));
Error_Msg_Qual_Level := 0;
end if;
Num_Actuals := Num_Actuals + 1;
Next_Actual (Actual);
end loop;
-- Before listing the possible candidates, check whether this is
-- a prefix of a selected component that has been rewritten as a
-- parameterless function call because there is a callable candidate
-- interpretation. If there is a hidden package in the list of homonyms
-- of the function name (bad programming style in any case) suggest that
-- this is the intended entity.
if No (Parameter_Associations (N))
and then Nkind (Parent (N)) = N_Selected_Component
and then Nkind (Parent (Parent (N))) in N_Declaration
and then Is_Overloaded (Nam)
then
declare
Ent : Entity_Id;
begin
Ent := Current_Entity (Nam);
while Present (Ent) loop
if Ekind (Ent) = E_Package then
Error_Msg_N
("no legal interpretations as function call,!", Nam);
Error_Msg_NE ("\package& is not visible", N, Ent);
Rewrite (Parent (N),
New_Occurrence_Of (Any_Type, Sloc (N)));
return;
end if;
Ent := Homonym (Ent);
end loop;
end;
end if;
-- If this is a call to an operation of a concurrent type, the failed
-- interpretations have been removed from the name. Recover them now
-- in order to provide full diagnostics.
if Nkind (Parent (Nam)) = N_Selected_Component then
Set_Entity (Nam, Empty);
New_Nam := New_Copy_Tree (Parent (Nam));
Set_Is_Overloaded (New_Nam, False);
Set_Is_Overloaded (Selector_Name (New_Nam), False);
Set_Parent (New_Nam, Parent (Parent (Nam)));
Analyze_Selected_Component (New_Nam);
Get_First_Interp (Selector_Name (New_Nam), X, It);
else
Get_First_Interp (Nam, X, It);
end if;
-- If the number of actuals is 2, then remove interpretations involving
-- a unary "+" operator as they might yield confusing errors downstream.
if Num_Actuals = 2
and then Nkind (Parent (Nam)) /= N_Selected_Component
then
Num_Interps := 0;
while Present (It.Nam) loop
if Ekind (It.Nam) = E_Operator
and then Chars (It.Nam) = Name_Op_Add
and then (No (First_Formal (It.Nam))
or else No (Next_Formal (First_Formal (It.Nam))))
then
Remove_Interp (X);
else
Num_Interps := Num_Interps + 1;
end if;
Get_Next_Interp (X, It);
end loop;
if Num_Interps = 0 then
Error_Msg_N ("!too many arguments in call to&", Nam);
return;
end if;
Get_First_Interp (Nam, X, It);
else
Num_Interps := 2; -- at least
end if;
-- Analyze each candidate call again with full error reporting for each
if Num_Interps > 1 then
Error_Msg_N ("!no candidate interpretations match the actuals:", Nam);
end if;
Err_Mode := All_Errors_Mode;
All_Errors_Mode := True;
while Present (It.Nam) loop
if Etype (It.Nam) = Standard_Void_Type then
Void_Interp_Seen := True;
end if;
Analyze_One_Call (N, It.Nam, True, Success);
Get_Next_Interp (X, It);
end loop;
if Nkind (N) = N_Function_Call then
Get_First_Interp (Nam, X, It);
if No (It.Typ)
and then Ekind (Entity (Name (N))) = E_Function
and then Present (Homonym (Entity (Name (N))))
then
-- A name may appear overloaded if it has a homonym, even if that
-- homonym is non-overloadable, in which case the overload list is
-- in fact empty. This specialized case deserves a special message
-- if the homonym is a child package.
declare
Nam : constant Node_Id := Name (N);
H : constant Entity_Id := Homonym (Entity (Nam));
begin
if Ekind (H) = E_Package and then Is_Child_Unit (H) then
Error_Msg_Qual_Level := 2;
Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
Error_Msg_NE ("\use a fully qualified name", Nam, H);
Error_Msg_Qual_Level := 0;
end if;
end;
else
while Present (It.Nam) loop
if Ekind (It.Nam) in E_Function | E_Operator then
return;
else
Get_Next_Interp (X, It);
end if;
end loop;
-- If all interpretations are procedures, this deserves a more
-- precise message. Ditto if this appears as the prefix of a
-- selected component, which may be a lexical error.
Error_Msg_N
("\context requires function call, found procedure name", Nam);
if Nkind (Parent (N)) = N_Selected_Component
and then N = Prefix (Parent (N))
then
Error_Msg_N -- CODEFIX
("\period should probably be semicolon", Parent (N));
end if;
end if;
elsif Nkind (N) = N_Procedure_Call_Statement
and then not Void_Interp_Seen
then
Error_Msg_N ("\function name found in procedure call", Nam);
end if;
All_Errors_Mode := Err_Mode;
end Diagnose_Call;
---------------------------
-- Find_Arithmetic_Types --
---------------------------
procedure Find_Arithmetic_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
procedure Check_Right_Argument (T : Entity_Id);
-- Check right operand of operator
--------------------------
-- Check_Right_Argument --
--------------------------
procedure Check_Right_Argument (T : Entity_Id) is
I : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (R) then
Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
else
Get_First_Interp (R, I, It);
while Present (It.Typ) loop
Check_Arithmetic_Pair (T, It.Typ, Op_Id, N);
Get_Next_Interp (I, It);
end loop;
end if;
end Check_Right_Argument;
-- Local variables
I : Interp_Index;
It : Interp;
-- Start of processing for Find_Arithmetic_Types
begin
if not Is_Overloaded (L) then
Check_Right_Argument (Etype (L));
else
Get_First_Interp (L, I, It);
while Present (It.Typ) loop
Check_Right_Argument (It.Typ);
Get_Next_Interp (I, It);
end loop;
end if;
end Find_Arithmetic_Types;
------------------------
-- Find_Boolean_Types --
------------------------
procedure Find_Boolean_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
procedure Check_Boolean_Pair (T1, T2 : Entity_Id);
-- Check operand pair of operator
procedure Check_Right_Argument (T : Entity_Id);
-- Check right operand of operator
------------------------
-- Check_Boolean_Pair --
------------------------
procedure Check_Boolean_Pair (T1, T2 : Entity_Id) is
T : Entity_Id;
begin
if Valid_Boolean_Arg (T1)
and then Valid_Boolean_Arg (T2)
and then (Covers (T1 => T1, T2 => T2)
or else Covers (T1 => T2, T2 => T1))
then
T := Specific_Type (T1, T2);
if T = Universal_Integer then
T := Any_Modular;
end if;
Add_One_Interp (N, Op_Id, T);
end if;
end Check_Boolean_Pair;
--------------------------
-- Check_Right_Argument --
--------------------------
procedure Check_Right_Argument (T : Entity_Id) is
I : Interp_Index;
It : Interp;
begin
-- Defend against previous error
if Nkind (R) = N_Error then
null;
elsif not Is_Overloaded (R) then
Check_Boolean_Pair (T, Etype (R));
else
Get_First_Interp (R, I, It);
while Present (It.Typ) loop
Check_Boolean_Pair (T, It.Typ);
Get_Next_Interp (I, It);
end loop;
end if;
end Check_Right_Argument;
-- Local variables
I : Interp_Index;
It : Interp;
-- Start of processing for Find_Boolean_Types
begin
if not Is_Overloaded (L) then
Check_Right_Argument (Etype (L));
else
Get_First_Interp (L, I, It);
while Present (It.Typ) loop
Check_Right_Argument (It.Typ);
Get_Next_Interp (I, It);
end loop;
end if;
end Find_Boolean_Types;
------------------------------------
-- Find_Comparison_Equality_Types --
------------------------------------
-- The context of the operator plays no role in resolving the operands,
-- so that if there is more than one interpretation of the operands that
-- is compatible with the comparison or equality, then the operation is
-- ambiguous, but this cannot be reported at this point because there is
-- no guarantee that the operation will be resolved to this operator yet.
procedure Find_Comparison_Equality_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Op_Name : constant Name_Id := Chars (Op_Id);
Op_Typ : Entity_Id renames Standard_Boolean;
function Try_Left_Interp (T : Entity_Id) return Entity_Id;
-- Try an interpretation of the left operand with type T. Return the
-- type of the interpretation of the right operand making up a valid
-- operand pair, or else Any_Type if the right operand is ambiguous,
-- otherwise Empty if no such pair exists.
function Is_Valid_Comparison_Type (T : Entity_Id) return Boolean;
-- Return true if T is a valid comparison type
function Is_Valid_Equality_Type
(T : Entity_Id;
Anon_Access : Boolean) return Boolean;
-- Return true if T is a valid equality type
function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean;
-- Return true if T1 and T2 constitute a valid pair of operand types for
-- L and R respectively.
---------------------
-- Try_Left_Interp --
---------------------
function Try_Left_Interp (T : Entity_Id) return Entity_Id is
I : Interp_Index;
It : Interp;
R_Typ : Entity_Id;
Valid_I : Interp_Index;
begin
-- Defend against previous error
if Nkind (R) = N_Error then
null;
-- Loop through the interpretations of the right operand
elsif not Is_Overloaded (R) then
if Is_Valid_Pair (T, Etype (R)) then
return Etype (R);
end if;
else
R_Typ := Empty;
Valid_I := 0;
Get_First_Interp (R, I, It);
while Present (It.Typ) loop
if Is_Valid_Pair (T, It.Typ) then
-- If several interpretations are possible, disambiguate
if Present (R_Typ)
and then Base_Type (It.Typ) /= Base_Type (R_Typ)
then
It := Disambiguate (R, Valid_I, I, Any_Type);
if It = No_Interp then
R_Typ := Any_Type;
exit;
end if;
else
Valid_I := I;
end if;
R_Typ := It.Typ;
end if;
Get_Next_Interp (I, It);
end loop;
if Present (R_Typ) then
return R_Typ;
end if;
end if;
return Empty;
end Try_Left_Interp;
------------------------------
-- Is_Valid_Comparison_Type --
------------------------------
function Is_Valid_Comparison_Type (T : Entity_Id) return Boolean is
begin
-- The operation must be performed in a context where the operators
-- of the base type are visible.
if Is_Visible_Operator (N, Base_Type (T)) then
null;
-- Save candidate type for subsequent error message, if any
else
if Valid_Comparison_Arg (T) then
Candidate_Type := T;
end if;
return False;
end if;
-- Defer to the common implementation for the rest
return Valid_Comparison_Arg (T);
end Is_Valid_Comparison_Type;
----------------------------
-- Is_Valid_Equality_Type --
----------------------------
function Is_Valid_Equality_Type
(T : Entity_Id;
Anon_Access : Boolean) return Boolean
is
begin
-- The operation must be performed in a context where the operators
-- of the base type are visible. Deal with special types used with
-- access types before type resolution is done.
if Ekind (T) = E_Access_Attribute_Type
or else (Ekind (T) in E_Access_Subprogram_Type
| E_Access_Protected_Subprogram_Type
and then
Ekind (Designated_Type (T)) /= E_Subprogram_Type)
or else Is_Visible_Operator (N, Base_Type (T))
then
null;
-- AI95-0230: Keep restriction imposed by Ada 83 and 95, do not allow
-- anonymous access types in universal_access equality operators.
elsif Anon_Access then
if Ada_Version < Ada_2005 then
return False;
end if;
-- Save candidate type for subsequent error message, if any
else
if Valid_Equality_Arg (T) then
Candidate_Type := T;
end if;
return False;
end if;
-- For the use of a "/=" operator on a tagged type, several possible
-- interpretations of equality need to be considered, we don't want
-- the default inequality declared in Standard to be chosen, and the
-- "/=" operator will be rewritten as a negation of "=" (see the end
-- of Analyze_Comparison_Equality_Op). This ensures the rewriting
-- occurs during analysis rather than being delayed until expansion.
-- Note that, if the node is N_Op_Ne but Op_Id is Name_Op_Eq, then we
-- still proceed with the interpretation, because this indicates
-- the aforementioned rewriting case where the interpretation to be
-- considered is actually that of the "=" operator.
if Nkind (N) = N_Op_Ne
and then Op_Name /= Name_Op_Eq
and then Is_Tagged_Type (T)
then
return False;
-- Defer to the common implementation for the rest
else
return Valid_Equality_Arg (T);
end if;
end Is_Valid_Equality_Type;
-------------------
-- Is_Valid_Pair --
-------------------
function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean is
begin
if Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
declare
Anon_Access : constant Boolean :=
Is_Anonymous_Access_Type (T1)
or else Is_Anonymous_Access_Type (T2);
-- RM 4.5.2(9.1/2): At least one of the operands of an equality
-- operator for universal_access shall be of specific anonymous
-- access type.
begin
if not Is_Valid_Equality_Type (T1, Anon_Access)
or else not Is_Valid_Equality_Type (T2, Anon_Access)
then
return False;
end if;
end;
else
if not Is_Valid_Comparison_Type (T1)
or else not Is_Valid_Comparison_Type (T2)
then
return False;
end if;
end if;
return Covers (T1 => T1, T2 => T2)
or else Covers (T1 => T2, T2 => T1)
or else Is_User_Defined_Literal (L, T2)
or else Is_User_Defined_Literal (R, T1);
end Is_Valid_Pair;
-- Local variables
I : Interp_Index;
It : Interp;
L_Typ : Entity_Id;
R_Typ : Entity_Id;
T : Entity_Id;
Valid_I : Interp_Index;
-- Start of processing for Find_Comparison_Equality_Types
begin
-- Loop through the interpretations of the left operand
if not Is_Overloaded (L) then
T := Try_Left_Interp (Etype (L));
if Present (T) then
Set_Etype (R, T);
Add_One_Interp (N, Op_Id, Op_Typ, Find_Unique_Type (L, R));
end if;
else
L_Typ := Empty;
R_Typ := Empty;
Valid_I := 0;
Get_First_Interp (L, I, It);
while Present (It.Typ) loop
T := Try_Left_Interp (It.Typ);
if Present (T) then
-- If several interpretations are possible, disambiguate
if Present (L_Typ)
and then Base_Type (It.Typ) /= Base_Type (L_Typ)
then
It := Disambiguate (L, Valid_I, I, Any_Type);
if It = No_Interp then
L_Typ := Any_Type;
R_Typ := T;
exit;
end if;
else
Valid_I := I;
end if;
L_Typ := It.Typ;
R_Typ := T;
end if;
Get_Next_Interp (I, It);
end loop;
if Present (L_Typ) then
Set_Etype (L, L_Typ);
Set_Etype (R, R_Typ);
Add_One_Interp (N, Op_Id, Op_Typ, Find_Unique_Type (L, R));
end if;
end if;
end Find_Comparison_Equality_Types;
------------------------------
-- Find_Concatenation_Types --
------------------------------
procedure Find_Concatenation_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Is_String : constant Boolean := Nkind (L) = N_String_Literal
or else
Nkind (R) = N_String_Literal;
Op_Type : constant Entity_Id := Etype (Op_Id);
begin
if Is_Array_Type (Op_Type)
-- Small but very effective optimization: if at least one operand is a
-- string literal, then the type of the operator must be either array
-- of characters or array of strings.
and then (not Is_String
or else
Is_Character_Type (Component_Type (Op_Type))
or else
Is_String_Type (Component_Type (Op_Type)))
and then not Is_Limited_Type (Op_Type)
and then (Has_Compatible_Type (L, Op_Type)
or else
Has_Compatible_Type (L, Component_Type (Op_Type)))
and then (Has_Compatible_Type (R, Op_Type)
or else
Has_Compatible_Type (R, Component_Type (Op_Type)))
then
Add_One_Interp (N, Op_Id, Op_Type);
end if;
end Find_Concatenation_Types;
-------------------------
-- Find_Negation_Types --
-------------------------
procedure Find_Negation_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (R) then
if Etype (R) = Universal_Integer then
Add_One_Interp (N, Op_Id, Any_Modular);
elsif Valid_Boolean_Arg (Etype (R)) then
Add_One_Interp (N, Op_Id, Etype (R));
end if;
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
if Valid_Boolean_Arg (It.Typ) then
Add_One_Interp (N, Op_Id, It.Typ);
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Negation_Types;
------------------------------
-- Find_Primitive_Operation --
------------------------------
function Find_Primitive_Operation (N : Node_Id) return Boolean is
Obj : constant Node_Id := Prefix (N);
Op : constant Node_Id := Selector_Name (N);
Prim : Elmt_Id;
Prims : Elist_Id;
Typ : Entity_Id;
begin
Set_Etype (Op, Any_Type);
if Is_Access_Type (Etype (Obj)) then
Typ := Designated_Type (Etype (Obj));
else
Typ := Etype (Obj);
end if;
if Is_Class_Wide_Type (Typ) then
Typ := Root_Type (Typ);
end if;
Prims := Primitive_Operations (Typ);
Prim := First_Elmt (Prims);
while Present (Prim) loop
if Chars (Node (Prim)) = Chars (Op) then
Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
Set_Etype (N, Etype (Node (Prim)));
end if;
Next_Elmt (Prim);
end loop;
-- Now look for class-wide operations of the type or any of its
-- ancestors by iterating over the homonyms of the selector.
declare
Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
Hom : Entity_Id;
begin
Hom := Current_Entity (Op);
while Present (Hom) loop
if (Ekind (Hom) = E_Procedure
or else
Ekind (Hom) = E_Function)
and then Scope (Hom) = Scope (Typ)
and then Present (First_Formal (Hom))
and then
(Base_Type (Etype (First_Formal (Hom))) = Cls_Type
or else
(Is_Access_Type (Etype (First_Formal (Hom)))
and then
Ekind (Etype (First_Formal (Hom))) =
E_Anonymous_Access_Type
and then
Base_Type
(Designated_Type (Etype (First_Formal (Hom)))) =
Cls_Type))
then
Add_One_Interp (Op, Hom, Etype (Hom));
Set_Etype (N, Etype (Hom));
end if;
Hom := Homonym (Hom);
end loop;
end;
return Etype (Op) /= Any_Type;
end Find_Primitive_Operation;
----------------------
-- Find_Unary_Types --
----------------------
procedure Find_Unary_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (R) then
if Is_Numeric_Type (Etype (R)) then
-- In an instance a generic actual may be a numeric type even if
-- the formal in the generic unit was not. In that case, the
-- predefined operator was not a possible interpretation in the
-- generic, and cannot be one in the instance, unless the operator
-- is an actual of an instance.
if In_Instance
and then
not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
then
null;
else
Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
end if;
end if;
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
if Is_Numeric_Type (It.Typ) then
if In_Instance
and then
not Is_Numeric_Type
(Corresponding_Generic_Type (Etype (It.Typ)))
then
null;
else
Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
end if;
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Unary_Types;
------------------
-- Junk_Operand --
------------------
function Junk_Operand (N : Node_Id) return Boolean is
Enode : Node_Id;
begin
if Error_Posted (N) then
return False;
end if;
-- Get entity to be tested
if Is_Entity_Name (N)
and then Present (Entity (N))
then
Enode := N;
-- An odd case, a procedure name gets converted to a very peculiar
-- function call, and here is where we detect this happening.
elsif Nkind (N) = N_Function_Call
and then Is_Entity_Name (Name (N))
and then Present (Entity (Name (N)))
then
Enode := Name (N);
-- Another odd case, there are at least some cases of selected
-- components where the selected component is not marked as having
-- an entity, even though the selector does have an entity
elsif Nkind (N) = N_Selected_Component
and then Present (Entity (Selector_Name (N)))
then
Enode := Selector_Name (N);
else
return False;
end if;
-- Now test the entity we got to see if it is a bad case
case Ekind (Entity (Enode)) is
when E_Package =>
Error_Msg_N
("package name cannot be used as operand", Enode);
when Generic_Unit_Kind =>
Error_Msg_N
("generic unit name cannot be used as operand", Enode);
when Type_Kind =>
Error_Msg_N
("subtype name cannot be used as operand", Enode);
when Entry_Kind =>
Error_Msg_N
("entry name cannot be used as operand", Enode);
when E_Procedure =>
Error_Msg_N
("procedure name cannot be used as operand", Enode);
when E_Exception =>
Error_Msg_N
("exception name cannot be used as operand", Enode);
when E_Block
| E_Label
| E_Loop
=>
Error_Msg_N
("label name cannot be used as operand", Enode);
when others =>
return False;
end case;
return True;
end Junk_Operand;
--------------------
-- Operator_Check --
--------------------
procedure Operator_Check (N : Node_Id) is
begin
Remove_Abstract_Operations (N);
-- Test for case of no interpretation found for operator
if Etype (N) = Any_Type then
declare
L : Node_Id;
R : Node_Id;
Op_Id : Entity_Id := Empty;
begin
R := Right_Opnd (N);
if Nkind (N) in N_Binary_Op then
L := Left_Opnd (N);
else
L := Empty;
end if;
-- If either operand has no type, then don't complain further,
-- since this simply means that we have a propagated error.
if R = Error
or else Etype (R) = Any_Type
or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
then
-- For the rather unusual case where one of the operands is
-- a Raise_Expression, whose initial type is Any_Type, use
-- the type of the other operand.
if Nkind (L) = N_Raise_Expression then
Set_Etype (L, Etype (R));
Set_Etype (N, Etype (R));
elsif Nkind (R) = N_Raise_Expression then
Set_Etype (R, Etype (L));
Set_Etype (N, Etype (L));
end if;
return;
-- We explicitly check for the case of concatenation of component
-- with component to avoid reporting spurious matching array types
-- that might happen to be lurking in distant packages (such as
-- run-time packages). This also prevents inconsistencies in the
-- messages for certain ACVC B tests, which can vary depending on
-- types declared in run-time interfaces. Another improvement when
-- aggregates are present is to look for a well-typed operand.
elsif Present (Candidate_Type)
and then (Nkind (N) /= N_Op_Concat
or else Is_Array_Type (Etype (L))
or else Is_Array_Type (Etype (R)))
then
if Nkind (N) = N_Op_Concat then
if Etype (L) /= Any_Composite
and then Is_Array_Type (Etype (L))
then
Candidate_Type := Etype (L);
elsif Etype (R) /= Any_Composite
and then Is_Array_Type (Etype (R))
then
Candidate_Type := Etype (R);
end if;
end if;
Error_Msg_NE -- CODEFIX
("operator for} is not directly visible!",
N, First_Subtype (Candidate_Type));
declare
U : constant Node_Id :=
Cunit (Get_Source_Unit (Candidate_Type));
begin
if Unit_Is_Visible (U) then
Error_Msg_N -- CODEFIX
("use clause would make operation legal!", N);
else
Error_Msg_NE -- CODEFIX
("add with_clause and use_clause for&!",
N, Defining_Entity (Unit (U)));
end if;
end;
return;
-- If either operand is a junk operand (e.g. package name), then
-- post appropriate error messages, but do not complain further.
-- Note that the use of OR in this test instead of OR ELSE is
-- quite deliberate, we may as well check both operands in the
-- binary operator case.
elsif Junk_Operand (R)
or -- really mean OR here and not OR ELSE, see above
(Nkind (N) in N_Binary_Op and then Junk_Operand (L))
then
return;
elsif Present (Entity (N))
and then Has_Possible_Literal_Aspects (N)
then
return;
-- If we have a logical operator, one of whose operands is
-- Boolean, then we know that the other operand cannot resolve to
-- Boolean (since we got no interpretations), but in that case we
-- pretty much know that the other operand should be Boolean, so
-- resolve it that way (generating an error).
elsif Nkind (N) in N_Op_And | N_Op_Or | N_Op_Xor then
if Etype (L) = Standard_Boolean then
Resolve (R, Standard_Boolean);
return;
elsif Etype (R) = Standard_Boolean then
Resolve (L, Standard_Boolean);
return;
end if;
-- For an arithmetic operator or comparison operator, if one
-- of the operands is numeric, then we know the other operand
-- is not the same numeric type. If it is a non-numeric type,
-- then probably it is intended to match the other operand.
elsif Nkind (N) in N_Op_Add
| N_Op_Divide
| N_Op_Ge
| N_Op_Gt
| N_Op_Le
| N_Op_Lt
| N_Op_Mod
| N_Op_Multiply
| N_Op_Rem
| N_Op_Subtract
then
-- If Allow_Integer_Address is active, check whether the
-- operation becomes legal after converting an operand.
if Is_Numeric_Type (Etype (L))
and then not Is_Numeric_Type (Etype (R))
then
if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
Rewrite (L,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (L)));
Rewrite (R,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (R)));
if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
Analyze_Comparison_Equality_Op (N);
else
Analyze_Arithmetic_Op (N);
end if;
else
Resolve (R, Etype (L));
end if;
return;
elsif Is_Numeric_Type (Etype (R))
and then not Is_Numeric_Type (Etype (L))
then
if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
Rewrite (L,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (L)));
Rewrite (R,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (R)));
if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
Analyze_Comparison_Equality_Op (N);
else
Analyze_Arithmetic_Op (N);
end if;
return;
else
Resolve (L, Etype (R));
end if;
return;
elsif Allow_Integer_Address
and then Is_Descendant_Of_Address (Etype (L))
and then Is_Descendant_Of_Address (Etype (R))
and then not Error_Posted (N)
then
declare
Addr_Type : constant Entity_Id := Etype (L);
begin
Rewrite (L,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (L)));
Rewrite (R,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (R)));
if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
Analyze_Comparison_Equality_Op (N);
else
Analyze_Arithmetic_Op (N);
end if;
-- If this is an operand in an enclosing arithmetic
-- operation, Convert the result as an address so that
-- arithmetic folding of address can continue.
if Nkind (Parent (N)) in N_Op then
Rewrite (N,
Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
end if;
return;
end;
-- Under relaxed RM semantics silently replace occurrences of
-- null by System.Address_Null.
elsif Null_To_Null_Address_Convert_OK (N) then
Replace_Null_By_Null_Address (N);
if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
Analyze_Comparison_Equality_Op (N);
else
Analyze_Arithmetic_Op (N);
end if;
return;
end if;
-- Comparisons on A'Access are common enough to deserve a
-- special message.
elsif Nkind (N) in N_Op_Eq | N_Op_Ne
and then Ekind (Etype (L)) = E_Access_Attribute_Type
and then Ekind (Etype (R)) = E_Access_Attribute_Type
then
Error_Msg_N
("two access attributes cannot be compared directly", N);
Error_Msg_N
("\use qualified expression for one of the operands",
N);
return;
-- Another one for C programmers
elsif Nkind (N) = N_Op_Concat
and then Valid_Boolean_Arg (Etype (L))
and then Valid_Boolean_Arg (Etype (R))
then
Error_Msg_N ("invalid operands for concatenation", N);
Error_Msg_N -- CODEFIX
("\maybe AND was meant", N);
return;
-- A special case for comparison of access parameter with null
elsif Nkind (N) = N_Op_Eq
and then Is_Entity_Name (L)
and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
and then Nkind (Parameter_Type (Parent (Entity (L)))) =
N_Access_Definition
and then Nkind (R) = N_Null
then
Error_Msg_N ("access parameter is not allowed to be null", L);
Error_Msg_N ("\(call would raise Constraint_Error)", L);
return;
-- Another special case for exponentiation, where the right
-- operand must be Natural, independently of the base.
elsif Nkind (N) = N_Op_Expon
and then Is_Numeric_Type (Etype (L))
and then not Is_Overloaded (R)
and then
First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
and then Base_Type (Etype (R)) /= Universal_Integer
then
if Ada_Version >= Ada_2012
and then Has_Dimension_System (Etype (L))
then
Error_Msg_NE
("exponent for dimensioned type must be a rational" &
", found}", R, Etype (R));
else
Error_Msg_NE
("exponent must be of type Natural, found}", R, Etype (R));
end if;
return;
elsif Nkind (N) in N_Op_Eq | N_Op_Ne then
if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
Rewrite (L,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (L)));
Rewrite (R,
Unchecked_Convert_To (
Standard_Address, Relocate_Node (R)));
Analyze_Comparison_Equality_Op (N);
return;
-- Under relaxed RM semantics silently replace occurrences of
-- null by System.Address_Null.
elsif Null_To_Null_Address_Convert_OK (N) then
Replace_Null_By_Null_Address (N);
Analyze_Comparison_Equality_Op (N);
return;
end if;
end if;
-- If we fall through then just give general message. Note that in
-- the following messages, if the operand is overloaded we choose
-- an arbitrary type to complain about, but that is probably more
-- useful than not giving a type at all.
if Nkind (N) in N_Unary_Op then
Error_Msg_Node_2 := Etype (R);
Error_Msg_N ("operator& not defined for}", N);
return;
else
if Nkind (N) in N_Binary_Op then
if not Is_Overloaded (L)
and then not Is_Overloaded (R)
and then Base_Type (Etype (L)) = Base_Type (Etype (R))
then
Error_Msg_Node_2 := First_Subtype (Etype (R));
Error_Msg_N ("there is no applicable operator& for}", N);
else
-- Another attempt to find a fix: one of the candidate
-- interpretations may not be use-visible. This has
-- already been checked for predefined operators, so
-- we examine only user-defined functions.
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) /= E_Operator
and then Is_Overloadable (Op_Id)
then
if not Is_Immediately_Visible (Op_Id)
and then not In_Use (Scope (Op_Id))
and then not Is_Abstract_Subprogram (Op_Id)
and then not Is_Hidden (Op_Id)
and then Ekind (Scope (Op_Id)) = E_Package
and then
Has_Compatible_Type
(L, Etype (First_Formal (Op_Id)))
and then Present
(Next_Formal (First_Formal (Op_Id)))
and then
Has_Compatible_Type
(R,
Etype (Next_Formal (First_Formal (Op_Id))))
then
Error_Msg_N
("no legal interpretation for operator&", N);
Error_Msg_NE
("\use clause on& would make operation legal",
N, Scope (Op_Id));
exit;
end if;
end if;
Op_Id := Homonym (Op_Id);
end loop;
if No (Op_Id) then
Error_Msg_N ("invalid operand types for operator&", N);
if Nkind (N) /= N_Op_Concat then
Error_Msg_NE ("\left operand has}!", N, Etype (L));
Error_Msg_NE ("\right operand has}!", N, Etype (R));
-- For multiplication and division operators with
-- a fixed-point operand and an integer operand,
-- indicate that the integer operand should be of
-- type Integer.
if Nkind (N) in N_Op_Multiply | N_Op_Divide
and then Is_Fixed_Point_Type (Etype (L))
and then Is_Integer_Type (Etype (R))
then
Error_Msg_N
("\convert right operand to `Integer`", N);
elsif Nkind (N) = N_Op_Multiply
and then Is_Fixed_Point_Type (Etype (R))
and then Is_Integer_Type (Etype (L))
then
Error_Msg_N
("\convert left operand to `Integer`", N);
end if;
-- For concatenation operators it is more difficult to
-- determine which is the wrong operand. It is worth
-- flagging explicitly an access type, for those who
-- might think that a dereference happens here.
elsif Is_Access_Type (Etype (L)) then
Error_Msg_N ("\left operand is access type", N);
elsif Is_Access_Type (Etype (R)) then
Error_Msg_N ("\right operand is access type", N);
end if;
end if;
end if;
end if;
end if;
end;
end if;
end Operator_Check;
----------------------------------
-- Has_Possible_Literal_Aspects --
----------------------------------
function Has_Possible_Literal_Aspects (N : Node_Id) return Boolean is
R : constant Node_Id := Right_Opnd (N);
L : Node_Id := Empty;
procedure Check_Literal_Opnd (Opnd : Node_Id);
-- If an operand is a literal to which an aspect may apply,
-- add the corresponding type to operator node.
------------------------
-- Check_Literal_Opnd --
------------------------
procedure Check_Literal_Opnd (Opnd : Node_Id) is
begin
if Nkind (Opnd) in N_Numeric_Or_String_Literal
or else (Is_Entity_Name (Opnd)
and then Present (Entity (Opnd))
and then Is_Named_Number (Entity (Opnd)))
then
Add_One_Interp (N, Etype (Opnd), Etype (Opnd));
end if;
end Check_Literal_Opnd;
-- Start of processing for Has_Possible_Literal_Aspects
begin
if Ada_Version < Ada_2022 then
return False;
end if;
if Nkind (N) in N_Binary_Op then
L := Left_Opnd (N);
else
L := Empty;
end if;
Check_Literal_Opnd (R);
-- Check left operand only if right one did not provide a
-- possible interpretation. Note that literal types are not
-- overloadable, in the sense that there is no overloadable
-- entity name whose several interpretations can be used to
-- indicate possible resulting types, so there is no way to
-- provide more than one interpretation to the operator node.
-- The choice of one operand over the other is arbitrary at
-- this point, and may lead to spurious resolution when both
-- operands are literals of different kinds, but the second
-- pass of resolution will examine anew both operands to
-- determine whether a user-defined literal may apply to
-- either or both.
if Present (L)
and then Etype (N) = Any_Type
then
Check_Literal_Opnd (L);
end if;
return Etype (N) /= Any_Type;
end Has_Possible_Literal_Aspects;
-----------------------------------------------
-- Nondispatching_Call_To_Abstract_Operation --
-----------------------------------------------
procedure Nondispatching_Call_To_Abstract_Operation
(N : Node_Id;
Abstract_Op : Entity_Id)
is
Typ : constant Entity_Id := Etype (N);
begin
-- In an instance body, this is a runtime check, but one we know will
-- fail, so give an appropriate warning. As usual this kind of warning
-- is an error in SPARK mode.
Error_Msg_Sloc := Sloc (Abstract_Op);
if In_Instance_Body and then SPARK_Mode /= On then
Error_Msg_NE
("??cannot call abstract operation& declared#",
N, Abstract_Op);
Error_Msg_N ("\Program_Error [??", N);
Rewrite (N,
Make_Raise_Program_Error (Sloc (N),
Reason => PE_Explicit_Raise));
Analyze (N);
Set_Etype (N, Typ);
else
Error_Msg_NE
("cannot call abstract operation& declared#",
N, Abstract_Op);
Set_Etype (N, Any_Type);
end if;
end Nondispatching_Call_To_Abstract_Operation;
----------------------------------------------
-- Possible_Type_For_Conditional_Expression --
----------------------------------------------
function Possible_Type_For_Conditional_Expression
(T1, T2 : Entity_Id) return Entity_Id
is
function Is_Access_Protected_Subprogram_Attribute
(T : Entity_Id) return Boolean;
-- Return true if T is the type of an access-to-protected-subprogram
-- attribute.
function Is_Access_Subprogram_Attribute (T : Entity_Id) return Boolean;
-- Return true if T is the type of an access-to-subprogram attribute
----------------------------------------------
-- Is_Access_Protected_Subprogram_Attribute --
----------------------------------------------
function Is_Access_Protected_Subprogram_Attribute
(T : Entity_Id) return Boolean
is
begin
return Ekind (T) = E_Access_Protected_Subprogram_Type
and then Ekind (Designated_Type (T)) /= E_Subprogram_Type;
end Is_Access_Protected_Subprogram_Attribute;
------------------------------------
-- Is_Access_Subprogram_Attribute --
------------------------------------
function Is_Access_Subprogram_Attribute (T : Entity_Id) return Boolean is
begin
return Ekind (T) = E_Access_Subprogram_Type
and then Ekind (Designated_Type (T)) /= E_Subprogram_Type;
end Is_Access_Subprogram_Attribute;
-- Start of processing for Possible_Type_For_Conditional_Expression
begin
-- If both types are those of similar access attributes or allocators,
-- pick one of them, for example the first.
if Ekind (T1) in E_Access_Attribute_Type | E_Allocator_Type
and then Ekind (T2) in E_Access_Attribute_Type | E_Allocator_Type
then
return T1;
elsif Is_Access_Subprogram_Attribute (T1)
and then Is_Access_Subprogram_Attribute (T2)
and then
Subtype_Conformant (Designated_Type (T1), Designated_Type (T2))
then
return T1;
elsif Is_Access_Protected_Subprogram_Attribute (T1)
and then Is_Access_Protected_Subprogram_Attribute (T2)
and then
Subtype_Conformant (Designated_Type (T1), Designated_Type (T2))
then
return T1;
-- The other case to be considered is a pair of tagged types
elsif Is_Tagged_Type (T1) and then Is_Tagged_Type (T2) then
-- Covers performs the same checks when T1 or T2 are a CW type, so
-- we don't need to do them again here.
if not Is_Class_Wide_Type (T1) and then Is_Ancestor (T1, T2) then
return T1;
elsif not Is_Class_Wide_Type (T2) and then Is_Ancestor (T2, T1) then
return T2;
-- Neither type is an ancestor of the other, but they may have one in
-- common, so we pick the first type as above. We could perform here
-- the computation of the nearest common ancestors of T1 and T2, but
-- this would require a significant amount of work and the practical
-- benefit would very likely be negligible.
else
return T1;
end if;
-- Otherwise no type is possible
else
return Empty;
end if;
end Possible_Type_For_Conditional_Expression;
--------------------------------
-- Remove_Abstract_Operations --
--------------------------------
procedure Remove_Abstract_Operations (N : Node_Id) is
Abstract_Op : Entity_Id := Empty;
Address_Descendant : Boolean := False;
I : Interp_Index;
It : Interp;
-- AI-310: If overloaded, remove abstract non-dispatching operations. We
-- activate this if either extensions are enabled, or if the abstract
-- operation in question comes from a predefined file. This latter test
-- allows us to use abstract to make operations invisible to users. In
-- particular, if type Address is non-private and abstract subprograms
-- are used to hide its operators, they will be truly hidden.
type Operand_Position is (First_Op, Second_Op);
Univ_Type : constant Entity_Id := Universal_Interpretation (N);
procedure Remove_Address_Interpretations (Op : Operand_Position);
-- Ambiguities may arise when the operands are literal and the address
-- operations in s-auxdec are visible. In that case, remove the
-- interpretation of a literal as Address, to retain the semantics
-- of Address as a private type.
------------------------------------
-- Remove_Address_Interpretations --
------------------------------------
procedure Remove_Address_Interpretations (Op : Operand_Position) is
Formal : Entity_Id;
begin
if Is_Overloaded (N) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
Formal := First_Entity (It.Nam);
if Op = Second_Op then
Next_Entity (Formal);
end if;
if Is_Descendant_Of_Address (Etype (Formal)) then
Address_Descendant := True;
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end Remove_Address_Interpretations;
-- Start of processing for Remove_Abstract_Operations
begin
if Is_Overloaded (N) then
if Debug_Flag_V then
Write_Line ("Remove_Abstract_Operations: ");
Write_Overloads (N);
end if;
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Is_Overloadable (It.Nam)
and then Is_Abstract_Subprogram (It.Nam)
and then not Is_Dispatching_Operation (It.Nam)
then
Abstract_Op := It.Nam;
if Is_Descendant_Of_Address (It.Typ) then
Address_Descendant := True;
Remove_Interp (I);
exit;
-- In Ada 2005, this operation does not participate in overload
-- resolution. If the operation is defined in a predefined
-- unit, it is one of the operations declared abstract in some
-- variants of System, and it must be removed as well.
elsif Ada_Version >= Ada_2005
or else In_Predefined_Unit (It.Nam)
then
Remove_Interp (I);
exit;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
if No (Abstract_Op) then
-- If some interpretation yields an integer type, it is still
-- possible that there are address interpretations. Remove them
-- if one operand is a literal, to avoid spurious ambiguities
-- on systems where Address is a visible integer type.
if Is_Overloaded (N)
and then Nkind (N) in N_Op
and then Is_Integer_Type (Etype (N))
then
if Nkind (N) in N_Binary_Op then
if Nkind (Right_Opnd (N)) = N_Integer_Literal then
Remove_Address_Interpretations (Second_Op);
elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
Remove_Address_Interpretations (First_Op);
end if;
end if;
end if;
elsif Nkind (N) in N_Op then
-- Remove interpretations that treat literals as addresses. This
-- is never appropriate, even when Address is defined as a visible
-- Integer type. The reason is that we would really prefer Address
-- to behave as a private type, even in this case. If Address is a
-- visible integer type, we get lots of overload ambiguities.
if Nkind (N) in N_Binary_Op then
declare
U1 : constant Boolean :=
Present (Universal_Interpretation (Right_Opnd (N)));
U2 : constant Boolean :=
Present (Universal_Interpretation (Left_Opnd (N)));
begin
if U1 then
Remove_Address_Interpretations (Second_Op);
end if;
if U2 then
Remove_Address_Interpretations (First_Op);
end if;
if not (U1 and U2) then
-- Remove corresponding predefined operator, which is
-- always added to the overload set.
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard
and then Base_Type (It.Typ) =
Base_Type (Etype (Abstract_Op))
then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
elsif Is_Overloaded (N)
and then Present (Univ_Type)
then
-- If both operands have a universal interpretation,
-- it is still necessary to remove interpretations that
-- yield Address. Any remaining ambiguities will be
-- removed in Disambiguate.
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Is_Descendant_Of_Address (It.Typ) then
Remove_Interp (I);
elsif not Is_Type (It.Nam) then
Set_Entity (N, It.Nam);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end;
end if;
elsif Nkind (N) = N_Function_Call
and then
(Nkind (Name (N)) = N_Operator_Symbol
or else
(Nkind (Name (N)) = N_Expanded_Name
and then
Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
then
declare
Arg1 : constant Node_Id := First (Parameter_Associations (N));
U1 : constant Boolean :=
Present (Universal_Interpretation (Arg1));
U2 : constant Boolean :=
Present (Next (Arg1)) and then
Present (Universal_Interpretation (Next (Arg1)));
begin
if U1 then
Remove_Address_Interpretations (First_Op);
end if;
if U2 then
Remove_Address_Interpretations (Second_Op);
end if;
if not (U1 and U2) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard
and then It.Typ = Base_Type (Etype (Abstract_Op))
then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end;
end if;
-- If the removal has left no valid interpretations, emit an error
-- message now and label node as illegal.
if Present (Abstract_Op) then
Get_First_Interp (N, I, It);
if No (It.Nam) then
-- Removal of abstract operation left no viable candidate
Nondispatching_Call_To_Abstract_Operation (N, Abstract_Op);
-- In Ada 2005, an abstract operation may disable predefined
-- operators. Since the context is not yet known, we mark the
-- predefined operators as potentially hidden. Do not include
-- predefined operators when addresses are involved since this
-- case is handled separately.
elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
while Present (It.Nam) loop
if Is_Numeric_Type (It.Typ)
and then Scope (It.Typ) = Standard_Standard
and then Ekind (It.Nam) = E_Operator
then
Set_Abstract_Op (I, Abstract_Op);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end if;
if Debug_Flag_V then
Write_Line ("Remove_Abstract_Operations done: ");
Write_Overloads (N);
end if;
end if;
end Remove_Abstract_Operations;
----------------------------
-- Try_Container_Indexing --
----------------------------
function Try_Container_Indexing
(N : Node_Id;
Prefix : Node_Id;
Exprs : List_Id) return Boolean
is
Pref_Typ : Entity_Id := Etype (Prefix);
function Constant_Indexing_OK return Boolean;
-- Constant_Indexing is legal if there is no Variable_Indexing defined
-- for the type, or else node not a target of assignment, or an actual
-- for an IN OUT or OUT formal (RM 4.1.6 (11)).
function Expr_Matches_In_Formal
(Subp : Entity_Id;
Par : Node_Id) return Boolean;
-- Find formal corresponding to given indexed component that is an
-- actual in a call. Note that the enclosing subprogram call has not
-- been analyzed yet, and the parameter list is not normalized, so
-- that if the argument is a parameter association we must match it
-- by name and not by position.
function Find_Indexing_Operations
(T : Entity_Id;
Nam : Name_Id;
Is_Constant : Boolean) return Node_Id;
-- Return a reference to the primitive operation of type T denoted by
-- name Nam. If the operation is overloaded, the reference carries all
-- interpretations. Flag Is_Constant should be set when the context is
-- constant indexing.
--------------------------
-- Constant_Indexing_OK --
--------------------------
function Constant_Indexing_OK return Boolean is
Par : Node_Id;
begin
if No (Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing)) then
return True;
elsif not Is_Variable (Prefix) then
return True;
end if;
Par := N;
while Present (Par) loop
if Nkind (Parent (Par)) = N_Assignment_Statement
and then Par = Name (Parent (Par))
then
return False;
-- The call may be overloaded, in which case we assume that its
-- resolution does not depend on the type of the parameter that
-- includes the indexing operation.
elsif Nkind (Parent (Par)) in N_Subprogram_Call
and then Is_Entity_Name (Name (Parent (Par)))
then
declare
Proc : Entity_Id;
begin
-- We should look for an interpretation with the proper
-- number of formals, and determine whether it is an
-- In_Parameter, but for now we examine the formal that
-- corresponds to the indexing, and assume that variable
-- indexing is required if some interpretation has an
-- assignable formal at that position. Still does not
-- cover the most complex cases ???
if Is_Overloaded (Name (Parent (Par))) then
declare
Proc : constant Node_Id := Name (Parent (Par));
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Proc, I, It);
while Present (It.Nam) loop
if not Expr_Matches_In_Formal (It.Nam, Par) then
return False;
end if;
Get_Next_Interp (I, It);
end loop;
end;
-- All interpretations have a matching in-mode formal
return True;
else
Proc := Entity (Name (Parent (Par)));
-- If this is an indirect call, get formals from
-- designated type.
if Is_Access_Subprogram_Type (Etype (Proc)) then
Proc := Designated_Type (Etype (Proc));
end if;
end if;
return Expr_Matches_In_Formal (Proc, Par);
end;
elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
return False;
-- If the indexed component is a prefix it may be the first actual
-- of a prefixed call. Retrieve the called entity, if any, and
-- check its first formal. Determine if the context is a procedure
-- or function call.
elsif Nkind (Parent (Par)) = N_Selected_Component then
declare
Sel : constant Node_Id := Selector_Name (Parent (Par));
Nam : constant Entity_Id := Current_Entity (Sel);
begin
if Present (Nam) and then Is_Overloadable (Nam) then
if Nkind (Parent (Parent (Par))) =
N_Procedure_Call_Statement
then
return False;
elsif Ekind (Nam) = E_Function
and then Present (First_Formal (Nam))
then
return Ekind (First_Formal (Nam)) = E_In_Parameter;
end if;
end if;
end;
elsif Nkind (Par) in N_Op then
return True;
end if;
Par := Parent (Par);
end loop;
-- In all other cases, constant indexing is legal
return True;
end Constant_Indexing_OK;
----------------------------
-- Expr_Matches_In_Formal --
----------------------------
function Expr_Matches_In_Formal
(Subp : Entity_Id;
Par : Node_Id) return Boolean
is
Actual : Node_Id;
Formal : Node_Id;
begin
Formal := First_Formal (Subp);
Actual := First (Parameter_Associations ((Parent (Par))));
if Nkind (Par) /= N_Parameter_Association then
-- Match by position
while Present (Actual) and then Present (Formal) loop
exit when Actual = Par;
Next (Actual);
if Present (Formal) then
Next_Formal (Formal);
-- Otherwise this is a parameter mismatch, the error is
-- reported elsewhere, or else variable indexing is implied.
else
return False;
end if;
end loop;
else
-- Match by name
while Present (Formal) loop
exit when Chars (Formal) = Chars (Selector_Name (Par));
Next_Formal (Formal);
if No (Formal) then
return False;
end if;
end loop;
end if;
return Present (Formal) and then Ekind (Formal) = E_In_Parameter;
end Expr_Matches_In_Formal;
------------------------------
-- Find_Indexing_Operations --
------------------------------
function Find_Indexing_Operations
(T : Entity_Id;
Nam : Name_Id;
Is_Constant : Boolean) return Node_Id
is
procedure Inspect_Declarations
(Typ : Entity_Id;
Ref : in out Node_Id);
-- Traverse the declarative list where type Typ resides and collect
-- all suitable interpretations in node Ref.
procedure Inspect_Primitives
(Typ : Entity_Id;
Ref : in out Node_Id);
-- Traverse the list of primitive operations of type Typ and collect
-- all suitable interpretations in node Ref.
function Is_OK_Candidate
(Subp_Id : Entity_Id;
Typ : Entity_Id) return Boolean;
-- Determine whether subprogram Subp_Id is a suitable indexing
-- operation for type Typ. To qualify as such, the subprogram must
-- be a function, have at least two parameters, and the type of the
-- first parameter must be either Typ, or Typ'Class, or access [to
-- constant] with designated type Typ or Typ'Class.
procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id);
-- Store subprogram Subp_Id as an interpretation in node Ref
--------------------------
-- Inspect_Declarations --
--------------------------
procedure Inspect_Declarations
(Typ : Entity_Id;
Ref : in out Node_Id)
is
Typ_Decl : constant Node_Id := Declaration_Node (Typ);
Decl : Node_Id;
Subp_Id : Entity_Id;
begin
-- Ensure that the routine is not called with itypes, which lack a
-- declarative node.
pragma Assert (Present (Typ_Decl));
pragma Assert (Is_List_Member (Typ_Decl));
Decl := First (List_Containing (Typ_Decl));
while Present (Decl) loop
if Nkind (Decl) = N_Subprogram_Declaration then
Subp_Id := Defining_Entity (Decl);
if Is_OK_Candidate (Subp_Id, Typ) then
Record_Interp (Subp_Id, Ref);
end if;
end if;
Next (Decl);
end loop;
end Inspect_Declarations;
------------------------
-- Inspect_Primitives --
------------------------
procedure Inspect_Primitives
(Typ : Entity_Id;
Ref : in out Node_Id)
is
Prim_Elmt : Elmt_Id;
Prim_Id : Entity_Id;
begin
Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Prim_Elmt) loop
Prim_Id := Node (Prim_Elmt);
if Is_OK_Candidate (Prim_Id, Typ) then
Record_Interp (Prim_Id, Ref);
end if;
Next_Elmt (Prim_Elmt);
end loop;
end Inspect_Primitives;
---------------------
-- Is_OK_Candidate --
---------------------
function Is_OK_Candidate
(Subp_Id : Entity_Id;
Typ : Entity_Id) return Boolean
is
Formal : Entity_Id;
Formal_Typ : Entity_Id;
Param_Typ : Node_Id;
begin
-- To classify as a suitable candidate, the subprogram must be a
-- function whose name matches the argument of aspect Constant or
-- Variable_Indexing.
if Ekind (Subp_Id) = E_Function and then Chars (Subp_Id) = Nam then
Formal := First_Formal (Subp_Id);
-- The candidate requires at least two parameters
if Present (Formal) and then Present (Next_Formal (Formal)) then
Formal_Typ := Empty;
Param_Typ := Parameter_Type (Parent (Formal));
-- Use the designated type when the first parameter is of an
-- access type.
if Nkind (Param_Typ) = N_Access_Definition
and then Present (Subtype_Mark (Param_Typ))
then
-- When the context is a constant indexing, the access
-- definition must be access-to-constant. This does not
-- apply to variable indexing.
if not Is_Constant
or else Constant_Present (Param_Typ)
then
Formal_Typ := Etype (Subtype_Mark (Param_Typ));
end if;
-- Otherwise use the parameter type
else
Formal_Typ := Etype (Param_Typ);
end if;
if Present (Formal_Typ) then
-- Use the specific type when the parameter type is
-- class-wide.
if Is_Class_Wide_Type (Formal_Typ) then
Formal_Typ := Etype (Base_Type (Formal_Typ));
end if;
-- Use the full view when the parameter type is private
-- or incomplete.
if Is_Incomplete_Or_Private_Type (Formal_Typ)
and then Present (Full_View (Formal_Typ))
then
Formal_Typ := Full_View (Formal_Typ);
end if;
-- The type of the first parameter must denote the type
-- of the container or acts as its ancestor type.
return
Formal_Typ = Typ
or else Is_Ancestor (Formal_Typ, Typ);
end if;
end if;
end if;
return False;
end Is_OK_Candidate;
-------------------
-- Record_Interp --
-------------------
procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id) is
begin
if Present (Ref) then
Add_One_Interp (Ref, Subp_Id, Etype (Subp_Id));
-- Otherwise this is the first interpretation. Create a reference
-- where all remaining interpretations will be collected.
else
Ref := New_Occurrence_Of (Subp_Id, Sloc (T));
end if;
end Record_Interp;
-- Local variables
Ref : Node_Id;
Typ : Entity_Id;
-- Start of processing for Find_Indexing_Operations
begin
Typ := T;
-- Use the specific type when the parameter type is class-wide
if Is_Class_Wide_Type (Typ) then
Typ := Root_Type (Typ);
end if;
Ref := Empty;
Typ := Underlying_Type (Base_Type (Typ));
Inspect_Primitives (Typ, Ref);
-- Now look for explicit declarations of an indexing operation.
-- If the type is private the operation may be declared in the
-- visible part that contains the partial view.
if Is_Private_Type (T) then
Inspect_Declarations (T, Ref);
end if;
Inspect_Declarations (Typ, Ref);
return Ref;
end Find_Indexing_Operations;
-- Local variables
Loc : constant Source_Ptr := Sloc (N);
Assoc : List_Id;
C_Type : Entity_Id;
Func : Entity_Id;
Func_Name : Node_Id;
Indexing : Node_Id;
Is_Constant_Indexing : Boolean := False;
-- This flag reflects the nature of the container indexing. Note that
-- the context may be suited for constant indexing, but the type may
-- lack a Constant_Indexing annotation.
-- Start of processing for Try_Container_Indexing
begin
-- Node may have been analyzed already when testing for a prefixed
-- call, in which case do not redo analysis.
if Present (Generalized_Indexing (N)) then
return True;
end if;
-- An explicit dereference needs to be created in the case of a prefix
-- that's an access.
-- It seems that this should be done elsewhere, but not clear where that
-- should happen. Normally Insert_Explicit_Dereference is called via
-- Resolve_Implicit_Dereference, called from Resolve_Indexed_Component,
-- but that won't be called in this case because we transform the
-- indexing to a call. Resolve_Call.Check_Prefixed_Call takes care of
-- implicit dereferencing and referencing on prefixed calls, but that
-- would be too late, even if we expanded to a prefix call, because
-- Process_Indexed_Component will flag an error before the resolution
-- happens. ???
if Is_Access_Type (Pref_Typ) then
Pref_Typ := Implicitly_Designated_Type (Pref_Typ);
Insert_Explicit_Dereference (Prefix);
Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
end if;
C_Type := Pref_Typ;
-- If indexing a class-wide container, obtain indexing primitive from
-- specific type.
if Is_Class_Wide_Type (C_Type) then
C_Type := Etype (Base_Type (C_Type));
end if;
-- Check whether the type has a specified indexing aspect
Func_Name := Empty;
-- The context is suitable for constant indexing, so obtain the name of
-- the indexing function from aspect Constant_Indexing.
if Constant_Indexing_OK then
Func_Name :=
Find_Value_Of_Aspect (Pref_Typ, Aspect_Constant_Indexing);
end if;
if Present (Func_Name) then
Is_Constant_Indexing := True;
-- Otherwise attempt variable indexing
else
Func_Name :=
Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing);
end if;
-- The type is not subject to either form of indexing, therefore the
-- indexed component does not denote container indexing. If this is a
-- true error, it is diagnosed by the caller.
if No (Func_Name) then
-- The prefix itself may be an indexing of a container. Rewrite it
-- as such and retry.
if Has_Implicit_Dereference (Pref_Typ) then
Build_Explicit_Dereference
(Prefix, Get_Reference_Discriminant (Pref_Typ));
return Try_Container_Indexing (N, Prefix, Exprs);
-- Otherwise this is definitely not container indexing
else
return False;
end if;
-- If the container type is derived from another container type, the
-- value of the inherited aspect is the Reference operation declared
-- for the parent type.
-- However, Reference is also a primitive operation of the type, and the
-- inherited operation has a different signature. We retrieve the right
-- ones (the function may be overloaded) from the list of primitive
-- operations of the derived type.
-- Note that predefined containers are typically all derived from one of
-- the Controlled types. The code below is motivated by containers that
-- are derived from other types with a Reference aspect.
-- Note as well that we need to examine the base type, given that
-- the container object may be a constrained subtype or itype that
-- does not have an explicit declaration.
elsif Is_Derived_Type (C_Type)
and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
then
Func_Name :=
Find_Indexing_Operations
(T => Base_Type (C_Type),
Nam => Chars (Func_Name),
Is_Constant => Is_Constant_Indexing);
end if;
Assoc := New_List (Relocate_Node (Prefix));
-- A generalized indexing may have nore than one index expression, so
-- transfer all of them to the argument list to be used in the call.
-- Note that there may be named associations, in which case the node
-- was rewritten earlier as a call, and has been transformed back into
-- an indexed expression to share the following processing.
-- The generalized indexing node is the one on which analysis and
-- resolution take place. Before expansion the original node is replaced
-- with the generalized indexing node, which is a call, possibly with a
-- dereference operation.
-- Create argument list for function call that represents generalized
-- indexing. Note that indices (i.e. actuals) may themselves be
-- overloaded.
declare
Arg : Node_Id;
New_Arg : Node_Id;
begin
Arg := First (Exprs);
while Present (Arg) loop
New_Arg := Relocate_Node (Arg);
-- The arguments can be parameter associations, in which case the
-- explicit actual parameter carries the overloadings.
if Nkind (New_Arg) /= N_Parameter_Association then
Save_Interps (Arg, New_Arg);
end if;
Append (New_Arg, Assoc);
Next (Arg);
end loop;
end;
if not Is_Overloaded (Func_Name) then
Func := Entity (Func_Name);
-- Can happen in case of e.g. cascaded errors
if No (Func) then
return False;
end if;
Indexing :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Func, Loc),
Parameter_Associations => Assoc);
Set_Parent (Indexing, Parent (N));
Set_Generalized_Indexing (N, Indexing);
Analyze (Indexing);
Set_Etype (N, Etype (Indexing));
-- If the return type of the indexing function is a reference type,
-- add the dereference as a possible interpretation. Note that the
-- indexing aspect may be a function that returns the element type
-- with no intervening implicit dereference, and that the reference
-- discriminant is not the first discriminant.
if Has_Discriminants (Etype (Func)) then
Check_Implicit_Dereference (N, Etype (Func));
end if;
else
-- If there are multiple indexing functions, build a function call
-- and analyze it for each of the possible interpretations.
Indexing :=
Make_Function_Call (Loc,
Name =>
Make_Identifier (Loc, Chars (Func_Name)),
Parameter_Associations => Assoc);
Set_Parent (Indexing, Parent (N));
Set_Generalized_Indexing (N, Indexing);
Set_Etype (N, Any_Type);
Set_Etype (Name (Indexing), Any_Type);
declare
I : Interp_Index;
It : Interp;
Success : Boolean;
begin
Get_First_Interp (Func_Name, I, It);
Set_Etype (Indexing, Any_Type);
-- Analyze each candidate function with the given actuals
while Present (It.Nam) loop
Analyze_One_Call (Indexing, It.Nam, False, Success);
Get_Next_Interp (I, It);
end loop;
-- If there are several successful candidates, resolution will
-- be by result. Mark the interpretations of the function name
-- itself.
if Is_Overloaded (Indexing) then
Get_First_Interp (Indexing, I, It);
while Present (It.Nam) loop
Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
Get_Next_Interp (I, It);
end loop;
else
Set_Etype (Name (Indexing), Etype (Indexing));
end if;
-- Now add the candidate interpretations to the indexing node
-- itself, to be replaced later by the function call.
if Is_Overloaded (Name (Indexing)) then
Get_First_Interp (Name (Indexing), I, It);
while Present (It.Nam) loop
Add_One_Interp (N, It.Nam, It.Typ);
-- Add dereference interpretation if the result type has
-- implicit reference discriminants.
if Has_Discriminants (Etype (It.Nam)) then
Check_Implicit_Dereference (N, Etype (It.Nam));
end if;
Get_Next_Interp (I, It);
end loop;
else
Set_Etype (N, Etype (Name (Indexing)));
if Has_Discriminants (Etype (N)) then
Check_Implicit_Dereference (N, Etype (N));
end if;
end if;
end;
end if;
if Etype (Indexing) = Any_Type then
Error_Msg_NE
("container cannot be indexed with&", N, Etype (First (Exprs)));
Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
end if;
return True;
end Try_Container_Indexing;
-----------------------
-- Try_Indirect_Call --
-----------------------
function Try_Indirect_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean
is
Actual : Node_Id;
Formal : Entity_Id;
Call_OK : Boolean;
pragma Warnings (Off, Call_OK);
begin
Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
Actual := First_Actual (N);
Formal := First_Formal (Designated_Type (Typ));
while Present (Actual) and then Present (Formal) loop
if not Has_Compatible_Type (Actual, Etype (Formal)) then
return False;
end if;
Next (Actual);
Next_Formal (Formal);
end loop;
if No (Actual) and then No (Formal) then
Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
-- Nam is a candidate interpretation for the name in the call,
-- if it is not an indirect call.
if not Is_Type (Nam)
and then Is_Entity_Name (Name (N))
then
Set_Entity (Name (N), Nam);
end if;
return True;
else
return False;
end if;
end Try_Indirect_Call;
----------------------
-- Try_Indexed_Call --
----------------------
function Try_Indexed_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id;
Skip_First : Boolean) return Boolean
is
Loc : constant Source_Ptr := Sloc (N);
Actuals : constant List_Id := Parameter_Associations (N);
Actual : Node_Id;
Index : Entity_Id;
begin
Actual := First (Actuals);
-- If the call was originally written in prefix form, skip the first
-- actual, which is obviously not defaulted.
if Skip_First then
Next (Actual);
end if;
Index := First_Index (Typ);
while Present (Actual) and then Present (Index) loop
-- If the parameter list has a named association, the expression
-- is definitely a call and not an indexed component.
if Nkind (Actual) = N_Parameter_Association then
return False;
end if;
if Is_Entity_Name (Actual)
and then Is_Type (Entity (Actual))
and then No (Next (Actual))
then
-- A single actual that is a type name indicates a slice if the
-- type is discrete, and an error otherwise.
if Is_Discrete_Type (Entity (Actual)) then
Rewrite (N,
Make_Slice (Loc,
Prefix =>
Make_Function_Call (Loc,
Name => Relocate_Node (Name (N))),
Discrete_Range =>
New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
Analyze (N);
else
Error_Msg_N ("invalid use of type in expression", Actual);
Set_Etype (N, Any_Type);
end if;
return True;
elsif not Has_Compatible_Type (Actual, Etype (Index)) then
return False;
end if;
Next (Actual);
Next_Index (Index);
end loop;
if No (Actual) and then No (Index) then
Add_One_Interp (N, Nam, Component_Type (Typ));
-- Nam is a candidate interpretation for the name in the call,
-- if it is not an indirect call.
if not Is_Type (Nam)
and then Is_Entity_Name (Name (N))
then
Set_Entity (Name (N), Nam);
end if;
return True;
else
return False;
end if;
end Try_Indexed_Call;
--------------------------
-- Try_Object_Operation --
--------------------------
function Try_Object_Operation
(N : Node_Id;
CW_Test_Only : Boolean := False;
Allow_Extensions : Boolean := False) return Boolean
is
K : constant Node_Kind := Nkind (Parent (N));
Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
Loc : constant Source_Ptr := Sloc (N);
Obj : constant Node_Id := Prefix (N);
Subprog : constant Node_Id :=
Make_Identifier (Sloc (Selector_Name (N)),
Chars => Chars (Selector_Name (N)));
-- Identifier on which possible interpretations will be collected
Report_Error : Boolean := False;
-- If no candidate interpretation matches the context, redo analysis
-- with Report_Error True to provide additional information.
Actual : Node_Id;
Candidate : Entity_Id := Empty;
New_Call_Node : Node_Id := Empty;
Node_To_Replace : Node_Id;
Obj_Type : Entity_Id := Etype (Obj);
Success : Boolean := False;
procedure Complete_Object_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id);
-- Make Subprog the name of Call_Node, replace Node_To_Replace with
-- Call_Node, insert the object (or its dereference) as the first actual
-- in the call, and complete the analysis of the call.
procedure Report_Ambiguity (Op : Entity_Id);
-- If a prefixed procedure call is ambiguous, indicate whether the call
-- includes an implicit dereference or an implicit 'Access.
procedure Transform_Object_Operation
(Call_Node : out Node_Id;
Node_To_Replace : out Node_Id);
-- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
-- Call_Node is the resulting subprogram call, Node_To_Replace is
-- either N or the parent of N, and Subprog is a reference to the
-- subprogram we are trying to match. Note that the transformation
-- may be partially destructive for the parent of N, so it needs to
-- be undone in the case where Try_Object_Operation returns false.
function Try_Class_Wide_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean;
-- Traverse all ancestor types looking for a class-wide subprogram for
-- which the current operation is a valid non-dispatching call.
procedure Try_One_Prefix_Interpretation (T : Entity_Id);
-- If prefix is overloaded, its interpretation may include different
-- tagged types, and we must examine the primitive operations and the
-- class-wide operations of each in order to find candidate
-- interpretations for the call as a whole.
function Try_Primitive_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean;
-- Traverse the list of primitive subprograms looking for a dispatching
-- operation for which the current node is a valid call.
function Valid_Candidate
(Success : Boolean;
Call : Node_Id;
Subp : Entity_Id) return Entity_Id;
-- If the subprogram is a valid interpretation, record it, and add to
-- the list of interpretations of Subprog. Otherwise return Empty.
-------------------------------
-- Complete_Object_Operation --
-------------------------------
procedure Complete_Object_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id)
is
Control : constant Entity_Id := First_Formal (Entity (Subprog));
Formal_Type : constant Entity_Id := Etype (Control);
First_Actual : Node_Id;
begin
-- Place the name of the operation, with its interpretations,
-- on the rewritten call.
Set_Name (Call_Node, Subprog);
First_Actual := First (Parameter_Associations (Call_Node));
-- For cross-reference purposes, treat the new node as being in the
-- source if the original one is. Set entity and type, even though
-- they may be overwritten during resolution if overloaded.
Set_Comes_From_Source (Subprog, Comes_From_Source (N));
Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
if Nkind (N) = N_Selected_Component
and then not Inside_A_Generic
then
Set_Entity (Selector_Name (N), Entity (Subprog));
Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
end if;
-- If need be, rewrite first actual as an explicit dereference. If
-- the call is overloaded, the rewriting can only be done once the
-- primitive operation is identified.
if Is_Overloaded (Subprog) then
-- The prefix itself may be overloaded, and its interpretations
-- must be propagated to the new actual in the call.
if Is_Overloaded (Obj) then
Save_Interps (Obj, First_Actual);
end if;
Rewrite (First_Actual, Obj);
elsif not Is_Access_Type (Formal_Type)
and then Is_Access_Type (Etype (Obj))
then
Rewrite (First_Actual,
Make_Explicit_Dereference (Sloc (Obj), Obj));
Analyze (First_Actual);
-- If we need to introduce an explicit dereference, verify that
-- the resulting actual is compatible with the mode of the formal.
if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
and then Is_Access_Constant (Etype (Obj))
then
Error_Msg_NE
("expect variable in call to&", Prefix (N), Entity (Subprog));
end if;
-- Conversely, if the formal is an access parameter and the object is
-- not an access type or a reference type (i.e. a type with the
-- Implicit_Dereference aspect specified), replace the actual with a
-- 'Access reference. Its analysis will check that the object is
-- aliased.
elsif Is_Access_Type (Formal_Type)
and then not Is_Access_Type (Etype (Obj))
and then
(not Has_Implicit_Dereference (Etype (Obj))
or else
not Is_Access_Type (Designated_Type (Etype
(Get_Reference_Discriminant (Etype (Obj))))))
then
-- A special case: A.all'Access is illegal if A is an access to a
-- constant and the context requires an access to a variable.
if not Is_Access_Constant (Formal_Type) then
if (Nkind (Obj) = N_Explicit_Dereference
and then Is_Access_Constant (Etype (Prefix (Obj))))
or else not Is_Variable (Obj)
then
Error_Msg_NE
("actual for & must be a variable", Obj, Control);
end if;
end if;
Rewrite (First_Actual,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Access,
Prefix => Relocate_Node (Obj)));
-- If the object is not overloaded verify that taking access of
-- it is legal. Otherwise check is made during resolution.
if not Is_Overloaded (Obj)
and then not Is_Aliased_View (Obj)
then
Error_Msg_NE
("object in prefixed call to & must be aliased "
& "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
end if;
Analyze (First_Actual);
else
if Is_Overloaded (Obj) then
Save_Interps (Obj, First_Actual);
end if;
Rewrite (First_Actual, Obj);
end if;
if In_Extended_Main_Source_Unit (Current_Scope) then
-- The operation is obtained from the dispatch table and not by
-- visibility, and may be declared in a unit that is not
-- explicitly referenced in the source, but is nevertheless
-- required in the context of the current unit. Indicate that
-- operation and its scope are referenced, to prevent spurious and
-- misleading warnings. If the operation is overloaded, all
-- primitives are in the same scope and we can use any of them.
-- Don't do that outside the main unit since otherwise this will
-- e.g. prevent the detection of some unused with clauses.
Set_Referenced (Entity (Subprog), True);
Set_Referenced (Scope (Entity (Subprog)), True);
end if;
Rewrite (Node_To_Replace, Call_Node);
-- Propagate the interpretations collected in subprog to the new
-- function call node, to be resolved from context.
if Is_Overloaded (Subprog) then
Save_Interps (Subprog, Node_To_Replace);
else
Analyze (Node_To_Replace);
-- If the operation has been rewritten into a call, which may get
-- subsequently an explicit dereference, preserve the type on the
-- original node (selected component or indexed component) for
-- subsequent legality tests, e.g. Is_Variable. which examines
-- the original node.
if Nkind (Node_To_Replace) = N_Function_Call then
Set_Etype
(Original_Node (Node_To_Replace), Etype (Node_To_Replace));
end if;
end if;
end Complete_Object_Operation;
----------------------
-- Report_Ambiguity --
----------------------
procedure Report_Ambiguity (Op : Entity_Id) is
Access_Actual : constant Boolean :=
Is_Access_Type (Etype (Prefix (N)));
Access_Formal : Boolean := False;
begin
Error_Msg_Sloc := Sloc (Op);
if Present (First_Formal (Op)) then
Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
end if;
if Access_Formal and then not Access_Actual then
if Nkind (Parent (Op)) = N_Full_Type_Declaration then
Error_Msg_N
("\possible interpretation "
& "(inherited, with implicit 'Access) #", N);
else
Error_Msg_N
("\possible interpretation (with implicit 'Access) #", N);
end if;
elsif not Access_Formal and then Access_Actual then
if Nkind (Parent (Op)) = N_Full_Type_Declaration then
Error_Msg_N
("\possible interpretation "
& "(inherited, with implicit dereference) #", N);
else
Error_Msg_N
("\possible interpretation (with implicit dereference) #", N);
end if;
else
if Nkind (Parent (Op)) = N_Full_Type_Declaration then
Error_Msg_N ("\possible interpretation (inherited)#", N);
else
Error_Msg_N -- CODEFIX
("\possible interpretation#", N);
end if;
end if;
end Report_Ambiguity;
--------------------------------
-- Transform_Object_Operation --
--------------------------------
procedure Transform_Object_Operation
(Call_Node : out Node_Id;
Node_To_Replace : out Node_Id)
is
Dummy : constant Node_Id := New_Copy (Obj);
-- Placeholder used as a first parameter in the call, replaced
-- eventually by the proper object.
Parent_Node : constant Node_Id := Parent (N);
Actual : Node_Id;
Actuals : List_Id;
begin
-- Common case covering 1) Call to a procedure and 2) Call to a
-- function that has some additional actuals.
if Nkind (Parent_Node) in N_Subprogram_Call
-- N is a selected component node containing the name of the
-- subprogram. If N is not the name of the parent node we must
-- not replace the parent node by the new construct. This case
-- occurs when N is a parameterless call to a subprogram that
-- is an actual parameter of a call to another subprogram. For
-- example:
-- Some_Subprogram (..., Obj.Operation, ...)
and then N = Name (Parent_Node)
then
Node_To_Replace := Parent_Node;
Actuals := Parameter_Associations (Parent_Node);
if Present (Actuals) then
Prepend (Dummy, Actuals);
else
Actuals := New_List (Dummy);
end if;
if Nkind (Parent_Node) = N_Procedure_Call_Statement then
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => New_Copy (Subprog),
Parameter_Associations => Actuals);
else
Call_Node :=
Make_Function_Call (Loc,
Name => New_Copy (Subprog),
Parameter_Associations => Actuals);
end if;
-- Before analysis, a function call appears as an indexed component
-- if there are no named associations.
elsif Nkind (Parent_Node) = N_Indexed_Component
and then N = Prefix (Parent_Node)
then
Node_To_Replace := Parent_Node;
Actuals := Expressions (Parent_Node);
Actual := First (Actuals);
while Present (Actual) loop
Analyze (Actual);
Next (Actual);
end loop;
Prepend (Dummy, Actuals);
Call_Node :=
Make_Function_Call (Loc,
Name => New_Copy (Subprog),
Parameter_Associations => Actuals);
-- Parameterless call: Obj.F is rewritten as F (Obj)
else
Node_To_Replace := N;
Call_Node :=
Make_Function_Call (Loc,
Name => New_Copy (Subprog),
Parameter_Associations => New_List (Dummy));
end if;
end Transform_Object_Operation;
------------------------------
-- Try_Class_Wide_Operation --
------------------------------
function Try_Class_Wide_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean
is
Anc_Type : Entity_Id;
Matching_Op : Entity_Id := Empty;
Error : Boolean;
procedure Traverse_Homonyms
(Anc_Type : Entity_Id;
Error : out Boolean);
-- Traverse the homonym chain of the subprogram searching for those
-- homonyms whose first formal has the Anc_Type's class-wide type,
-- or an anonymous access type designating the class-wide type. If
-- an ambiguity is detected, then Error is set to True.
procedure Traverse_Interfaces
(Anc_Type : Entity_Id;
Error : out Boolean);
-- Traverse the list of interfaces, if any, associated with Anc_Type
-- and search for acceptable class-wide homonyms associated with each
-- interface. If an ambiguity is detected, then Error is set to True.
-----------------------
-- Traverse_Homonyms --
-----------------------
procedure Traverse_Homonyms
(Anc_Type : Entity_Id;
Error : out Boolean)
is
function First_Formal_Match
(Subp_Id : Entity_Id;
Typ : Entity_Id) return Boolean;
-- Predicate to verify that the first foramal of class-wide
-- subprogram Subp_Id matches type Typ of the prefix.
------------------------
-- First_Formal_Match --
------------------------
function First_Formal_Match
(Subp_Id : Entity_Id;
Typ : Entity_Id) return Boolean
is
Ctrl : constant Entity_Id := First_Formal (Subp_Id);
begin
return
Present (Ctrl)
and then
(Base_Type (Etype (Ctrl)) = Typ
or else
(Ekind (Etype (Ctrl)) = E_Anonymous_Access_Type
and then
Base_Type (Designated_Type (Etype (Ctrl))) =
Typ));
end First_Formal_Match;
-- Local variables
CW_Typ : constant Entity_Id := Class_Wide_Type (Anc_Type);
Candidate : Entity_Id;
-- If homonym is a renaming, examine the renamed program
Hom : Entity_Id;
Hom_Ref : Node_Id;
Success : Boolean;
-- Start of processing for Traverse_Homonyms
begin
Error := False;
-- Find a non-hidden operation whose first parameter is of the
-- class-wide type, a subtype thereof, or an anonymous access
-- to same. If in an instance, the operation can be considered
-- even if hidden (it may be hidden because the instantiation
-- is expanded after the containing package has been analyzed).
-- If the subprogram is a generic actual in an enclosing instance,
-- it appears as a renaming that is a candidate interpretation as
-- well.
Hom := Current_Entity (Subprog);
while Present (Hom) loop
if Ekind (Hom) in E_Procedure | E_Function
and then Present (Renamed_Entity (Hom))
and then Is_Generic_Actual_Subprogram (Hom)
and then In_Open_Scopes (Scope (Hom))
then
Candidate := Renamed_Entity (Hom);
else
Candidate := Hom;
end if;
if Ekind (Candidate) in E_Function | E_Procedure
and then (not Is_Hidden (Candidate) or else In_Instance)
and then Scope (Candidate) = Scope (Base_Type (Anc_Type))
and then First_Formal_Match (Candidate, CW_Typ)
then
-- If the context is a procedure call, ignore functions
-- in the name of the call.
if Ekind (Candidate) = E_Function
and then Nkind (Parent (N)) = N_Procedure_Call_Statement
and then N = Name (Parent (N))
then
goto Next_Hom;
-- If the context is a function call, ignore procedures
-- in the name of the call.
elsif Ekind (Candidate) = E_Procedure
and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
then
goto Next_Hom;
end if;
Set_Etype (Call_Node, Any_Type);
Set_Is_Overloaded (Call_Node, False);
Success := False;
if No (Matching_Op) then
Hom_Ref := New_Occurrence_Of (Candidate, Sloc (Subprog));
Set_Etype (Call_Node, Any_Type);
Set_Name (Call_Node, Hom_Ref);
Set_Parent (Call_Node, Parent (Node_To_Replace));
Analyze_One_Call
(N => Call_Node,
Nam => Candidate,
Report => Report_Error,
Success => Success,
Skip_First => True);
Matching_Op :=
Valid_Candidate (Success, Call_Node, Candidate);
else
Analyze_One_Call
(N => Call_Node,
Nam => Candidate,
Report => Report_Error,
Success => Success,
Skip_First => True);
-- The same operation may be encountered on two homonym
-- traversals, before and after looking at interfaces.
-- Check for this case before reporting a real ambiguity.
if Present
(Valid_Candidate (Success, Call_Node, Candidate))
and then Nkind (Call_Node) /= N_Function_Call
and then Candidate /= Matching_Op
then
Error_Msg_NE ("ambiguous call to&", N, Hom);
Report_Ambiguity (Matching_Op);
Report_Ambiguity (Hom);
Check_Ambiguous_Aggregate (New_Call_Node);
Error := True;
return;
end if;
end if;
end if;
<<Next_Hom>>
Hom := Homonym (Hom);
end loop;
end Traverse_Homonyms;
-------------------------
-- Traverse_Interfaces --
-------------------------
procedure Traverse_Interfaces
(Anc_Type : Entity_Id;
Error : out Boolean)
is
Intface_List : constant List_Id :=
Abstract_Interface_List (Anc_Type);
Intface : Node_Id;
begin
Error := False;
Intface := First (Intface_List);
while Present (Intface) loop
-- Look for acceptable class-wide homonyms associated with the
-- interface.
Traverse_Homonyms (Etype (Intface), Error);
if Error then
return;
end if;
-- Continue the search by looking at each of the interface's
-- associated interface ancestors.
Traverse_Interfaces (Etype (Intface), Error);
if Error then
return;
end if;
Next (Intface);
end loop;
end Traverse_Interfaces;
-- Start of processing for Try_Class_Wide_Operation
begin
-- If we are searching only for conflicting class-wide subprograms
-- then initialize directly Matching_Op with the target entity.
if CW_Test_Only then
Matching_Op := Entity (Selector_Name (N));
end if;
-- Loop through ancestor types (including interfaces), traversing
-- the homonym chain of the subprogram, trying out those homonyms
-- whose first formal has the class-wide type of the ancestor, or
-- an anonymous access type designating the class-wide type.
Anc_Type := Obj_Type;
loop
-- Look for a match among homonyms associated with the ancestor
Traverse_Homonyms (Anc_Type, Error);
if Error then
return True;
end if;
-- Continue the search for matches among homonyms associated with
-- any interfaces implemented by the ancestor.
Traverse_Interfaces (Anc_Type, Error);
if Error then
return True;
end if;
exit when Etype (Anc_Type) = Anc_Type;
Anc_Type := Etype (Anc_Type);
end loop;
if Present (Matching_Op) then
Set_Etype (Call_Node, Etype (Matching_Op));
end if;
return Present (Matching_Op);
end Try_Class_Wide_Operation;
-----------------------------------
-- Try_One_Prefix_Interpretation --
-----------------------------------
procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
Prev_Obj_Type : constant Entity_Id := Obj_Type;
-- If the interpretation does not have a valid candidate type,
-- preserve current value of Obj_Type for subsequent errors.
begin
Obj_Type := T;
if Is_Access_Type (Obj_Type) then
Obj_Type := Designated_Type (Obj_Type);
end if;
if Ekind (Obj_Type)
in E_Private_Subtype | E_Record_Subtype_With_Private
then
Obj_Type := Base_Type (Obj_Type);
end if;
if Is_Class_Wide_Type (Obj_Type) then
Obj_Type := Etype (Class_Wide_Type (Obj_Type));
end if;
-- The type may have be obtained through a limited_with clause,
-- in which case the primitive operations are available on its
-- nonlimited view. If still incomplete, retrieve full view.
if Ekind (Obj_Type) = E_Incomplete_Type
and then From_Limited_With (Obj_Type)
and then Has_Non_Limited_View (Obj_Type)
then
Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
end if;
-- If the object is not tagged, or the type is still an incomplete
-- type, this is not a prefixed call. Restore the previous type as
-- the current one is not a legal candidate.
-- Extension feature: Calls with prefixed views are also supported
-- for untagged types, so skip the early return when extensions are
-- enabled, unless the type doesn't have a primitive operations list
-- (such as in the case of predefined types).
if (not Is_Tagged_Type (Obj_Type)
and then
(not (Core_Extensions_Allowed or Allow_Extensions)
or else not Present (Primitive_Operations (Obj_Type))))
or else Is_Incomplete_Type (Obj_Type)
then
Obj_Type := Prev_Obj_Type;
return;
end if;
declare
Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
Ignore : Boolean;
Prim_Result : Boolean := False;
begin
if not CW_Test_Only then
Prim_Result :=
Try_Primitive_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace);
-- Extension feature: In the case where the prefix is of an
-- access type, and a primitive wasn't found for the designated
-- type, then if the access type has primitives we attempt a
-- prefixed call using one of its primitives. (It seems that
-- this isn't quite right to give preference to the designated
-- type in the case where both the access and designated types
-- have homographic prefixed-view operations that could result
-- in an ambiguity, but handling properly may be tricky. ???)
if (Core_Extensions_Allowed or Allow_Extensions)
and then not Prim_Result
and then Is_Named_Access_Type (Prev_Obj_Type)
and then Present (Direct_Primitive_Operations (Prev_Obj_Type))
then
-- Temporarily reset Obj_Type to the original access type
Obj_Type := Prev_Obj_Type;
Prim_Result :=
Try_Primitive_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace);
-- Restore Obj_Type to the designated type (is this really
-- necessary, or should it only be done when Prim_Result is
-- still False?).
Obj_Type := Designated_Type (Obj_Type);
end if;
end if;
-- Check if there is a class-wide subprogram covering the
-- primitive. This check must be done even if a candidate
-- was found in order to report ambiguous calls.
if not Prim_Result then
Ignore :=
Try_Class_Wide_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace);
-- If we found a primitive we search for class-wide subprograms
-- using a duplicate of the call node (done to avoid missing its
-- decoration if there is no ambiguity).
else
Ignore :=
Try_Class_Wide_Operation
(Call_Node => Dup_Call_Node,
Node_To_Replace => Node_To_Replace);
end if;
end;
end Try_One_Prefix_Interpretation;
-----------------------------
-- Try_Primitive_Operation --
-----------------------------
function Try_Primitive_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean
is
Elmt : Elmt_Id;
Prim_Op : Entity_Id;
Matching_Op : Entity_Id := Empty;
Prim_Op_Ref : Node_Id := Empty;
Corr_Type : Entity_Id := Empty;
-- If the prefix is a synchronized type, the controlling type of
-- the primitive operation is the corresponding record type, else
-- this is the object type itself.
Success : Boolean := False;
function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
-- For tagged types the candidate interpretations are found in
-- the list of primitive operations of the type and its ancestors.
-- For formal tagged types we have to find the operations declared
-- in the same scope as the type (including in the generic formal
-- part) because the type itself carries no primitive operations,
-- except for formal derived types that inherit the operations of
-- the parent and progenitors.
--
-- If the context is a generic subprogram body, the generic formals
-- are visible by name, but are not in the entity list of the
-- subprogram because that list starts with the subprogram formals.
-- We retrieve the candidate operations from the generic declaration.
function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
-- Prefix notation can also be used on operations that are not
-- primitives of the type, but are declared in the same immediate
-- declarative part, which can only mean the corresponding package
-- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
-- list of primitives with body operations with the same name that
-- may be candidates, so that Try_Primitive_Operations can examine
-- them if no real primitive is found.
function Is_Private_Overriding (Op : Entity_Id) return Boolean;
-- An operation that overrides an inherited operation in the private
-- part of its package may be hidden, but if the inherited operation
-- is visible a direct call to it will dispatch to the private one,
-- which is therefore a valid candidate.
function Names_Match
(Obj_Type : Entity_Id;
Prim_Op : Entity_Id;
Subprog : Entity_Id) return Boolean;
-- Return True if the names of Prim_Op and Subprog match. If Obj_Type
-- is a protected type then compare also the original name of Prim_Op
-- with the name of Subprog (since the expander may have added a
-- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
-- Verify that the prefix, dereferenced if need be, is a valid
-- controlling argument in a call to Op. The remaining actuals
-- are checked in the subsequent call to Analyze_One_Call.
------------------------------
-- Collect_Generic_Type_Ops --
------------------------------
function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
Bas : constant Entity_Id := Base_Type (T);
Candidates : constant Elist_Id := New_Elmt_List;
Subp : Entity_Id;
Formal : Entity_Id;
procedure Check_Candidate;
-- The operation is a candidate if its first parameter is a
-- controlling operand of the desired type.
-----------------------
-- Check_Candidate; --
-----------------------
procedure Check_Candidate is
begin
Formal := First_Formal (Subp);
if Present (Formal)
and then Is_Controlling_Formal (Formal)
and then
(Base_Type (Etype (Formal)) = Bas
or else
(Is_Access_Type (Etype (Formal))
and then Designated_Type (Etype (Formal)) = Bas))
then
Append_Elmt (Subp, Candidates);
end if;
end Check_Candidate;
-- Start of processing for Collect_Generic_Type_Ops
begin
if Is_Derived_Type (T) then
return Primitive_Operations (T);
elsif Ekind (Scope (T)) in E_Procedure | E_Function then
-- Scan the list of generic formals to find subprograms
-- that may have a first controlling formal of the type.
if Nkind (Unit_Declaration_Node (Scope (T))) =
N_Generic_Subprogram_Declaration
then
declare
Decl : Node_Id;
begin
Decl :=
First (Generic_Formal_Declarations
(Unit_Declaration_Node (Scope (T))));
while Present (Decl) loop
if Nkind (Decl) in N_Formal_Subprogram_Declaration then
Subp := Defining_Entity (Decl);
Check_Candidate;
end if;
Next (Decl);
end loop;
end;
end if;
return Candidates;
else
-- Scan the list of entities declared in the same scope as
-- the type. In general this will be an open scope, given that
-- the call we are analyzing can only appear within a generic
-- declaration or body (either the one that declares T, or a
-- child unit).
-- For a subtype representing a generic actual type, go to the
-- base type.
if Is_Generic_Actual_Type (T) then
Subp := First_Entity (Scope (Base_Type (T)));
else
Subp := First_Entity (Scope (T));
end if;
while Present (Subp) loop
if Is_Overloadable (Subp) then
Check_Candidate;
end if;
Next_Entity (Subp);
end loop;
return Candidates;
end if;
end Collect_Generic_Type_Ops;
----------------------------
-- Extended_Primitive_Ops --
----------------------------
function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
Type_Scope : constant Entity_Id := Scope (T);
Op_List : Elist_Id := Primitive_Operations (T);
begin
if Is_Package_Or_Generic_Package (Type_Scope)
and then ((In_Package_Body (Type_Scope)
and then In_Open_Scopes (Type_Scope)) or else In_Instance_Body)
then
-- Retrieve list of declarations of package body if possible
declare
The_Body : constant Node_Id :=
Corresponding_Body (Unit_Declaration_Node (Type_Scope));
begin
if Present (The_Body) then
declare
Body_Decls : constant List_Id :=
Declarations (Unit_Declaration_Node (The_Body));
Op_Found : Boolean := False;
Op : Entity_Id := Current_Entity (Subprog);
begin
while Present (Op) loop
if Comes_From_Source (Op)
and then Is_Overloadable (Op)
-- Exclude overriding primitive operations of a
-- type extension declared in the package body,
-- to prevent duplicates in extended list.
and then not Is_Primitive (Op)
and then Is_List_Member
(Unit_Declaration_Node (Op))
and then List_Containing
(Unit_Declaration_Node (Op)) = Body_Decls
then
if not Op_Found then
-- Copy list of primitives so it is not
-- affected for other uses.
Op_List := New_Copy_Elist (Op_List);
Op_Found := True;
end if;
Append_Elmt (Op, Op_List);
end if;
Op := Homonym (Op);
end loop;
end;
end if;
end;
end if;
return Op_List;
end Extended_Primitive_Ops;
---------------------------
-- Is_Private_Overriding --
---------------------------
function Is_Private_Overriding (Op : Entity_Id) return Boolean is
Visible_Op : Entity_Id;
begin
-- The subprogram may be overloaded with both visible and private
-- entities with the same name. We have to scan the chain of
-- homonyms to determine whether there is a previous implicit
-- declaration in the same scope that is overridden by the
-- private candidate.
Visible_Op := Homonym (Op);
while Present (Visible_Op) loop
if Scope (Op) /= Scope (Visible_Op) then
return False;
elsif not Comes_From_Source (Visible_Op)
and then Alias (Visible_Op) = Op
and then not Is_Hidden (Visible_Op)
then
return True;
end if;
Visible_Op := Homonym (Visible_Op);
end loop;
return False;
end Is_Private_Overriding;
-----------------
-- Names_Match --
-----------------
function Names_Match
(Obj_Type : Entity_Id;
Prim_Op : Entity_Id;
Subprog : Entity_Id) return Boolean is
begin
-- Common case: exact match
if Chars (Prim_Op) = Chars (Subprog) then
return True;
-- For protected type primitives the expander may have built the
-- name of the dispatching primitive prepending the type name to
-- avoid conflicts with the name of the protected subprogram (see
-- Exp_Ch9.Build_Selected_Name).
elsif Is_Protected_Type (Obj_Type) then
return
Present (Original_Protected_Subprogram (Prim_Op))
and then Chars (Original_Protected_Subprogram (Prim_Op)) =
Chars (Subprog);
-- In an instance, the selector name may be a generic actual that
-- renames a primitive operation of the type of the prefix.
elsif In_Instance and then Present (Current_Entity (Subprog)) then
declare
Subp : constant Entity_Id := Current_Entity (Subprog);
begin
if Present (Subp)
and then Is_Subprogram (Subp)
and then Present (Renamed_Entity (Subp))
and then Is_Generic_Actual_Subprogram (Subp)
and then Chars (Renamed_Entity (Subp)) = Chars (Prim_Op)
then
return True;
end if;
end;
end if;
return False;
end Names_Match;
-----------------------------
-- Valid_First_Argument_Of --
-----------------------------
function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
Typ : Entity_Id := Etype (First_Formal (Op));
begin
if Is_Concurrent_Type (Typ)
and then Present (Corresponding_Record_Type (Typ))
then
Typ := Corresponding_Record_Type (Typ);
end if;
-- Simple case. Object may be a subtype of the tagged type or may
-- be the corresponding record of a synchronized type.
return Obj_Type = Typ
or else Base_Type (Obj_Type) = Base_Type (Typ)
or else Corr_Type = Typ
-- Object may be of a derived type whose parent has unknown
-- discriminants, in which case the type matches the underlying
-- record view of its base.
or else
(Has_Unknown_Discriminants (Typ)
and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
-- Prefix can be dereferenced
or else
(Is_Access_Type (Corr_Type)
and then Designated_Type (Corr_Type) = Typ)
-- Formal is an access parameter, for which the object can
-- provide an access.
or else
(Ekind (Typ) = E_Anonymous_Access_Type
and then
Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
end Valid_First_Argument_Of;
-- Start of processing for Try_Primitive_Operation
begin
-- Look for subprograms in the list of primitive operations. The name
-- must be identical, and the kind of call indicates the expected
-- kind of operation (function or procedure). If the type is a
-- (tagged) synchronized type, the primitive ops are attached to the
-- corresponding record (base) type.
if Is_Concurrent_Type (Obj_Type) then
if Present (Corresponding_Record_Type (Obj_Type)) then
Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
Elmt := First_Elmt (Primitive_Operations (Corr_Type));
else
Corr_Type := Obj_Type;
Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
end if;
elsif not Is_Generic_Type (Obj_Type) then
Corr_Type := Obj_Type;
Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
else
Corr_Type := Obj_Type;
Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
end if;
while Present (Elmt) loop
Prim_Op := Node (Elmt);
if Names_Match (Obj_Type, Prim_Op, Subprog)
and then Present (First_Formal (Prim_Op))
and then Valid_First_Argument_Of (Prim_Op)
and then
(Nkind (Call_Node) = N_Function_Call)
=
(Ekind (Prim_Op) = E_Function)
then
-- Ada 2005 (AI-251): If this primitive operation corresponds
-- to an immediate ancestor interface there is no need to add
-- it to the list of interpretations; the corresponding aliased
-- primitive is also in this list of primitive operations and
-- will be used instead.
if (Present (Interface_Alias (Prim_Op))
and then Is_Ancestor (Find_Dispatching_Type
(Alias (Prim_Op)), Corr_Type))
-- Do not consider hidden primitives unless the type is in an
-- open scope or we are within an instance, where visibility
-- is known to be correct, or else if this is an overriding
-- operation in the private part for an inherited operation.
or else (Is_Hidden (Prim_Op)
and then not Is_Immediately_Visible (Obj_Type)
and then not In_Instance
and then not Is_Private_Overriding (Prim_Op))
then
goto Continue;
end if;
Set_Etype (Call_Node, Any_Type);
Set_Is_Overloaded (Call_Node, False);
if No (Matching_Op) then
Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
Candidate := Prim_Op;
Set_Parent (Call_Node, Parent (Node_To_Replace));
Set_Name (Call_Node, Prim_Op_Ref);
Success := False;
Analyze_One_Call
(N => Call_Node,
Nam => Prim_Op,
Report => Report_Error,
Success => Success,
Skip_First => True);
Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
-- More than one interpretation, collect for subsequent
-- disambiguation. If this is a procedure call and there
-- is another match, report ambiguity now.
else
Analyze_One_Call
(N => Call_Node,
Nam => Prim_Op,
Report => Report_Error,
Success => Success,
Skip_First => True);
if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
and then Nkind (Call_Node) /= N_Function_Call
then
Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
Report_Ambiguity (Matching_Op);
Report_Ambiguity (Prim_Op);
Check_Ambiguous_Aggregate (Call_Node);
return True;
end if;
end if;
end if;
<<Continue>>
Next_Elmt (Elmt);
end loop;
if Present (Matching_Op) then
Set_Etype (Call_Node, Etype (Matching_Op));
end if;
return Present (Matching_Op);
end Try_Primitive_Operation;
---------------------
-- Valid_Candidate --
---------------------
function Valid_Candidate
(Success : Boolean;
Call : Node_Id;
Subp : Entity_Id) return Entity_Id
is
Arr_Type : Entity_Id;
Comp_Type : Entity_Id;
begin
-- If the subprogram is a valid interpretation, record it in global
-- variable Subprog, to collect all possible overloadings.
if Success then
if Subp /= Entity (Subprog) then
Add_One_Interp (Subprog, Subp, Etype (Subp));
end if;
end if;
-- If the call may be an indexed call, retrieve component type of
-- resulting expression, and add possible interpretation.
Arr_Type := Empty;
Comp_Type := Empty;
if Nkind (Call) = N_Function_Call
and then Nkind (Parent (N)) = N_Indexed_Component
and then Needs_One_Actual (Subp)
then
if Is_Array_Type (Etype (Subp)) then
Arr_Type := Etype (Subp);
elsif Is_Access_Type (Etype (Subp))
and then Is_Array_Type (Designated_Type (Etype (Subp)))
then
Arr_Type := Designated_Type (Etype (Subp));
end if;
end if;
if Present (Arr_Type) then
-- Verify that the actuals (excluding the object) match the types
-- of the indexes.
declare
Actual : Node_Id;
Index : Node_Id;
begin
Actual := Next (First_Actual (Call));
Index := First_Index (Arr_Type);
while Present (Actual) and then Present (Index) loop
if not Has_Compatible_Type (Actual, Etype (Index)) then
Arr_Type := Empty;
exit;
end if;
Next_Actual (Actual);
Next_Index (Index);
end loop;
if No (Actual)
and then No (Index)
and then Present (Arr_Type)
then
Comp_Type := Component_Type (Arr_Type);
end if;
end;
if Present (Comp_Type)
and then Etype (Subprog) /= Comp_Type
then
Add_One_Interp (Subprog, Subp, Comp_Type);
end if;
end if;
if Etype (Call) /= Any_Type then
return Subp;
else
return Empty;
end if;
end Valid_Candidate;
-- Start of processing for Try_Object_Operation
begin
Analyze_Expression (Obj);
-- Analyze the actuals if node is known to be a subprogram call
if Is_Subprg_Call and then N = Name (Parent (N)) then
Actual := First (Parameter_Associations (Parent (N)));
while Present (Actual) loop
Analyze_Expression (Actual);
Next (Actual);
end loop;
end if;
-- Build a subprogram call node, using a copy of Obj as its first
-- actual. This is a placeholder, to be replaced by an explicit
-- dereference when needed.
Transform_Object_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace);
Set_Etype (New_Call_Node, Any_Type);
Set_Etype (Subprog, Any_Type);
Set_Parent (New_Call_Node, Parent (Node_To_Replace));
if not Is_Overloaded (Obj) then
Try_One_Prefix_Interpretation (Obj_Type);
else
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Obj, I, It);
while Present (It.Nam) loop
Try_One_Prefix_Interpretation (It.Typ);
Get_Next_Interp (I, It);
end loop;
end;
end if;
if Etype (New_Call_Node) /= Any_Type then
-- No need to complete the tree transformations if we are only
-- searching for conflicting class-wide subprograms
if CW_Test_Only then
return False;
else
Complete_Object_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace);
return True;
end if;
elsif Present (Candidate) then
-- The argument list is not type correct. Re-analyze with error
-- reporting enabled, and use one of the possible candidates.
-- In All_Errors_Mode, re-analyze all failed interpretations.
if All_Errors_Mode then
Report_Error := True;
if Try_Primitive_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace)
or else
Try_Class_Wide_Operation
(Call_Node => New_Call_Node,
Node_To_Replace => Node_To_Replace)
then
null;
end if;
else
Analyze_One_Call
(N => New_Call_Node,
Nam => Candidate,
Report => True,
Success => Success,
Skip_First => True);
-- The error may hot have been reported yet for overloaded
-- prefixed calls, depending on the non-matching candidate,
-- in which case provide a concise error now.
if Serious_Errors_Detected = 0 then
Error_Msg_NE
("cannot resolve prefixed call to primitive operation of&",
N, Entity (Obj));
end if;
end if;
-- No need for further errors
return True;
else
-- There was no candidate operation, but Analyze_Selected_Component
-- may continue the analysis so we need to undo the change possibly
-- made to the Parent of N earlier by Transform_Object_Operation.
declare
Parent_Node : constant Node_Id := Parent (N);
begin
if Node_To_Replace = Parent_Node then
Remove (First (Parameter_Associations (New_Call_Node)));
Set_Parent
(Parameter_Associations (New_Call_Node), Parent_Node);
end if;
end;
return False;
end if;
end Try_Object_Operation;
---------
-- wpo --
---------
procedure wpo (T : Entity_Id) is
Op : Entity_Id;
E : Elmt_Id;
begin
if not Is_Tagged_Type (T) then
return;
end if;
E := First_Elmt (Primitive_Operations (Base_Type (T)));
while Present (E) loop
Op := Node (E);
Write_Int (Int (Op));
Write_Str (" === ");
Write_Name (Chars (Op));
Write_Str (" in ");
Write_Name (Chars (Scope (Op)));
Next_Elmt (E);
Write_Eol;
end loop;
end wpo;
end Sem_Ch4;
|