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 | ------------------------------------------------------------------------------
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2014-2022, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 3, or (at your option) any --
-- later version. This software is distributed in the hope that it will be --
-- useful but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are --
-- granted additional permissions described in the GCC Runtime Library --
-- Exception, version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and a --
-- copy of the GCC Runtime Library Exception along with this program; see --
-- the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
------------------------------------------------------------------------------
with GNATCOLL.Traces; use GNATCOLL.Traces;
with GNATCOLL.VFS; use GNATCOLL.VFS;
with Test.Common; use Test.Common;
with Test.Mapping; use Test.Mapping;
with Test.Skeleton.Source_Table;
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Langkit_Support.Errors;
with Langkit_Support.Text; use Langkit_Support.Text;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.SHA1;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.Traceback.Symbolic;
with Ada.Containers.Multiway_Trees;
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Containers.Indefinite_Vectors;
with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Directories;
with Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Utils.Command_Lines; use Utils.Command_Lines;
with Utils.Environment;
package body Test.Stub is
Me : constant Trace_Handle := Create ("Stubs", Default => Off);
Me_Mapping : constant Trace_Handle :=
Create ("Stubs.Mapping", Default => Off);
-----------------
-- LAL parsing --
-----------------
type Element_Node is record
Spec : Ada_Node;
Spec_Name : String_Access;
-- Not used for incomplete type declarations.
Inside_Generic : Boolean := False;
Inside_Protected : Boolean := False;
end record;
Tasks_Present : Boolean;
package Element_Node_Trees is new
Ada.Containers.Multiway_Trees (Element_Node);
use Element_Node_Trees;
package Element_Node_Lists is new
Ada.Containers.Doubly_Linked_Lists (Element_Node);
use Element_Node_Lists;
Nil_Element_Node : constant Element_Node :=
(Spec => No_Ada_Node,
Spec_Name => null,
Inside_Generic => False,
Inside_Protected => False);
type Data_Holder is record
Elem_Tree : Element_Node_Trees.Tree;
Flat_List : Element_Node_Lists.List;
Limited_Withed_Units : String_Set.Set;
-- All limited withed units from the spec should have a cooresponding
-- regular with clause in the body.
end record;
procedure Gather_Data
(The_Unit : Ada_Node;
Data : out Data_Holder);
-- Gathers all LAL info for stub generation
-- Arguments & result profile analysis
type Stubbed_Parameter_Kinds is (Access_Kind, Constrained, Not_Constrained);
type Stubbed_Parameter is record
Name : String_Access;
Type_Image : String_Access;
Type_Full_Name_Image : String_Access; -- for nested types
Kind : Stubbed_Parameter_Kinds;
Type_Elem : Ada_Node;
end record;
package Stubbed_Parameter_Lists is new
Ada.Containers.Doubly_Linked_Lists (Stubbed_Parameter);
use Stubbed_Parameter_Lists;
function Get_Args_List (Node : Element_Node)
return Stubbed_Parameter_Lists.List;
-- Returns info on access, out and in out parameters of the subprogram and
-- on result profile in case of functions.
function Get_Type_Image (Param_Type : Type_Expr) return String;
-- Returns exact image is the argument type is not declared in nested
-- package. Otherwise replaces whatever name of the type is given with
-- corresponding full ada name.
function Is_Abstract (Param_Type : Type_Expr) return Boolean;
-- Analyzes type definition and detects is it's private or public
-- declaration is abstract.
function Is_Fully_Private (Param_Type : Type_Expr) return Boolean;
-- Analyzes type definition and detects if corresponding type is declared
-- only in the private declaration part.
function Is_Limited (Param_Type : Type_Expr) return Boolean;
-- Analyzes type definition and detects is it's private or public
-- declaration is limited.
function Is_Only_Limited_Withed (Param_Type : Type_Expr) return Boolean;
-- Analyzes type definition and detects if only the limited view is
-- available. If so, Is_Limited and Is_Abstract are not to be applied.
function Filter_Private_Parameters
(Param_List : Stubbed_Parameter_Lists.List)
return Stubbed_Parameter_Lists.List;
-- Filer out parameters of private types.
function Requires_Body (N : Ada_Node) return Boolean;
-- Checks if a body sample should be created for an element
function Get_Declaration
(Elem : Subtype_Indication)
return Base_Type_Decl
is
(Elem.F_Name.P_Relative_Name.As_Name.P_Referenced_Decl.As_Base_Type_Decl);
-- Returns declaration of corresponding parameter type
-------------------------------
-- Setter package generation --
-------------------------------
procedure Generate_Default_Setter_Spec (Node : Element_Node);
-- Generate stub data type and object and a setter spec
procedure Generate_Default_Setter_Body (Node : Element_Node);
-- Generate setter body
function Get_Access_Type_Name (Elem : Subtype_Indication) return String;
-- Returns full ada name for given type definition with "." and "'"
-- replaced with underscores and an "_Access" suffix.
type Access_Dictionary_Entry is record
Entry_Str : String_Access := null;
Type_Decl : Ada_Node := No_Ada_Node;
end record;
function "<" (L, R : Access_Dictionary_Entry) return Boolean is
(L.Entry_Str.all < R.Entry_Str.all);
package Access_Dictionaries is new
Ada.Containers.Indefinite_Ordered_Sets (Access_Dictionary_Entry);
use Access_Dictionaries;
Dictionary : Access_Dictionaries.Set;
-- A set of all unrestricted types that we need to make access types for
procedure Add_Unconstrained_Type_To_Dictionary (Elem : Subtype_Indication);
-- Updates the dictionary of unconstrained-to-access types if needed
------------------------------
-- Markered Mata processing --
------------------------------
type Markered_Data_Kinds is
(
-- with clauses, code 00
Import_MD,
-- incomplete type, code 01
Type_MD,
-- task type or single task, code 02
Task_MD,
-- local declarations in packages, code 03
Package_MD,
-- subprogram, code 04
Subprogram_MD,
-- entry, code 05
Entry_MD,
-- possible elaboration code, code 06
Elaboration_MD,
-- used in attempts to partially recover corrupted packages, code 99
Unknown_MD);
function MD_Kind_To_String (MD : Markered_Data_Kinds) return String;
-- Returns string with corresponding code
function MD_Kind_From_String (Str : String) return Markered_Data_Kinds;
-- And back (Unknown for "99" and any illegal argument)
type Markered_Data_Id is record
Kind : Markered_Data_Kinds;
Self_Hash : String_Access;
Nesting_Hash : String_Access;
Hash_Version : String_Access;
Name : String_Access;
end record;
function "<" (L, R : Markered_Data_Id) return Boolean;
function Hash_Suffix (ID : Markered_Data_Id) return String;
-- Returns hash suffix from given ID
package String_Vectors is new
Ada.Containers.Indefinite_Vectors (Natural, String);
type Markered_Data_Type is record
Commneted_Out : Boolean := False;
Lines : String_Vectors.Vector := String_Vectors.Empty_Vector;
end record;
function Generate_MD_Id_String
(Element : Ada_Node;
Commented_Out : Boolean := False) return String;
function Generate_MD_Id_String
(Id : Markered_Data_Id;
Commented_Out : Boolean := False) return String;
function Generate_MD_Id
(Element : Ada_Node)
return Markered_Data_Id;
package Markered_Data_Maps is new
Ada.Containers.Indefinite_Ordered_Maps
(Markered_Data_Id, Markered_Data_Type, "<");
use Markered_Data_Maps;
Markered_Data : Markered_Data_Maps.Map;
-- Main MD storage for stub body
Markered_Subp_Data : Markered_Data_Maps.Map;
-- Used to keep MD for subprograms that are actually present in the spec
-- so that unused setters could be reported.
procedure Gather_Markered_Data
(File : String; Map : in out Markered_Data_Maps.Map);
-----------------------------
-- Stub package generation --
-----------------------------
Level : Integer := 0;
-- Nesting level of a spec being processed
Indent_Level : constant Natural := 3;
-- Indentation level
procedure Generate_Body_Stub
(Body_File_Name : String;
Data : Data_Holder);
-- Generates stub body
procedure Generate_Stub_Data
(Stub_Data_File_Spec : String;
Stub_Data_File_Body : String;
Data : Data_Holder);
-- Generates Stub_Data package which contains setters
procedure Put_Stub_Header
(Unit_Name : String;
Stub_Data : Boolean := True;
Limited_Withed : String_Set.Set);
-- Puts header of generated stub explaining where user code should be put
procedure Put_Import_Section
(Markered_Data : in out Markered_Data_Maps.Map;
Add_Import : Boolean := False;
Add_Pragma_05 : Boolean := False);
-- Puts or regenerates markered section for with clauses
procedure Put_Lines (MD : Markered_Data_Type; Comment_Out : Boolean);
procedure Process_Siblings (Cursor : Element_Node_Trees.Cursor);
procedure Process_Node (Cursor : Element_Node_Trees.Cursor);
procedure Generate_Package_Body
(Node : Element_Node; Cursor : Element_Node_Trees.Cursor);
procedure Generate_Protected_Body
(Node : Element_Node; Cursor : Element_Node_Trees.Cursor);
procedure Generate_Procedure_Body (Node : Element_Node);
procedure Generate_Function_Body (Node : Element_Node);
procedure Generate_Entry_Body (Node : Element_Node);
procedure Generate_Task_Body (Node : Element_Node);
procedure Generate_Full_Type_Declaration (Node : Element_Node);
procedure Put_Dangling_Elements;
-------------
-- Mapping --
-------------
use Entity_Stub_Mapping_List;
Local_Stub_Unit_Mapping : Stub_Unit_Mapping;
procedure Add_Entity_To_Local_List
(Node : Element_Node; New_First_Line, New_First_Column : Natural);
-- Adds mapping info to Local_Stub_Unit_Mapping
procedure Update_Local_Entity_With_Setter
(Node : Element_Node; New_First_Line, New_First_Column : Natural);
-- Adds mapping info on setter to corresponding item in the list
------------------
-- Process_Unit --
------------------
procedure Process_Unit
(Pack : Libadalang.Analysis.Ada_Node;
Body_File_Name : String;
Stub_Data_File_Spec : String;
Stub_Data_File_Body : String)
is
Data : Data_Holder;
procedure Cleanup;
-- Frees global and temporary variables
procedure Report_And_Exclude (Ex : Ada.Exceptions.Exception_Occurrence);
-- Reports problematic source with exception information and exludes
-- the source from furter attempts at stubbing it.
-------------
-- Cleanup --
-------------
procedure Cleanup is
begin
Dictionary.Clear;
Free (Local_Stub_Unit_Mapping.Stub_Data_File_Name);
Free (Local_Stub_Unit_Mapping.Orig_Body_File_Name);
Free (Local_Stub_Unit_Mapping.Stub_Body_File_Name);
Local_Stub_Unit_Mapping.Entities.Clear;
Local_Stub_Unit_Mapping.D_Setters.Clear;
Local_Stub_Unit_Mapping.D_Bodies.Clear;
Data.Elem_Tree.Clear;
Data.Flat_List.Clear;
Data.Limited_Withed_Units.Clear;
end Cleanup;
------------------------
-- Report_And_Exclude --
------------------------
procedure Report_And_Exclude
(Ex : Ada.Exceptions.Exception_Occurrence) is
begin
if Strict_Execution then
Report_Err
(Ada.Exceptions.Exception_Name (Ex)
& " : "
& Ada.Exceptions.Exception_Message (Ex)
& ASCII.LF
& GNAT.Traceback.Symbolic.Symbolic_Traceback (Ex));
end if;
-- If it failed once it will fail again most likely, no point
-- in duplicating the errors. Adding the unit to default stub
-- exclusion list to avoid further attempts to process it.
Store_Default_Excluded_Stub (Base_Name (Pack.Unit.Get_Filename));
end Report_And_Exclude;
begin
Gather_Data (Pack, Data);
Gather_Markered_Data (Body_File_Name, Markered_Data);
Local_Stub_Unit_Mapping.Stub_Data_File_Name :=
new String'(Stub_Data_File_Body);
Local_Stub_Unit_Mapping.Orig_Body_File_Name := new String'
(Test.Skeleton.Source_Table.Get_Source_Body
(Pack.Unit.Get_Filename));
Local_Stub_Unit_Mapping.Stub_Body_File_Name :=
new String'(Body_File_Name);
Generate_Body_Stub (Body_File_Name, Data);
Generate_Stub_Data
(Stub_Data_File_Spec,
Stub_Data_File_Body,
Data);
Add_Stub_List (Pack.Unit.Get_Filename, Local_Stub_Unit_Mapping);
Cleanup;
exception
when Ex : Langkit_Support.Errors.Property_Error =>
Source_Processing_Failed := True;
Report_Err ("lal error while creating stub for "
& Base_Name (Pack.Unit.Get_Filename));
Report_Err ("source file may be incomplete/invalid");
Report_And_Exclude (Ex);
Cleanup;
raise Stub_Processing_Error;
when Ex : others =>
Source_Processing_Failed := True;
Report_Err ("unexpected error while creating stub for "
& Base_Name (Pack.Unit.Get_Filename));
Report_And_Exclude (Ex);
Cleanup;
raise Stub_Processing_Error;
end Process_Unit;
-----------------
-- Gather_Data --
-----------------
procedure Gather_Data
(The_Unit : Ada_Node;
Data : out Data_Holder)
is
Spec_Base_File_Name : constant String := The_Unit.Unit.Get_Filename;
Generic_Layers_Counter : Natural := 0;
-- All subprograms inside nested generic packages cannot have setters.
-- This counter is used to know how many nested generic packages are
-- enclosing current element.
State_Cur : Element_Node_Trees.Cursor;
procedure Process_Nodes
(Element : Ada_Node'Class);
procedure Create_Element_Node
(Element : Ada_Node'Class;
Inside_Protected : Boolean := False);
-- When visiting an Element representing something for which a body
-- sample may be required, we check if the body is really required
-- and insert the corresponding Element on the right place in Data
-- if it is.
procedure Process_Nodes (Element : Ada_Node'Class)
is
Pub_Part : Public_Part;
Priv_Part : Private_Part;
Inside_Protected : Boolean := False;
begin
if Element.Kind in Ada_Base_Package_Decl then
Pub_Part := Element.As_Base_Package_Decl.F_Public_Part;
Priv_Part := Element.As_Base_Package_Decl.F_Private_Part;
elsif Element.Kind = Ada_Generic_Package_Decl then
Pub_Part :=
Element.As_Generic_Package_Decl.F_Package_Decl.F_Public_Part;
Priv_Part :=
Element.As_Generic_Package_Decl.F_Package_Decl.F_Private_Part;
elsif Element.Kind = Ada_Protected_Type_Decl then
Pub_Part :=
Element.As_Protected_Type_Decl.F_Definition.F_Public_Part;
Priv_Part :=
Element.As_Protected_Type_Decl.F_Definition.F_Private_Part;
Inside_Protected := True;
elsif Element.Kind = Ada_Single_Protected_Decl then
Pub_Part :=
Element.As_Single_Protected_Decl.F_Definition.F_Public_Part;
Priv_Part :=
Element.As_Single_Protected_Decl.F_Definition.F_Private_Part;
Inside_Protected := True;
end if;
if not Pub_Part.Is_Null then
for El of Pub_Part.As_Declarative_Part.F_Decls loop
Create_Element_Node (El, Inside_Protected);
end loop;
end if;
if not Priv_Part.Is_Null then
for El of Priv_Part.As_Declarative_Part.F_Decls loop
Create_Element_Node (El, Inside_Protected);
end loop;
end if;
end Process_Nodes;
procedure Create_Element_Node
(Element : Ada_Node'Class;
Inside_Protected : Boolean := False)
is
Elem_Node : Element_Node := Nil_Element_Node;
Cur : Element_Node_Trees.Cursor;
begin
if Element.Kind = Ada_Generic_Package_Decl then
Generic_Layers_Counter := Generic_Layers_Counter + 1;
end if;
if Element.Kind in Ada_Base_Type_Decl then
if not Element.As_Basic_Decl.F_Aspects.Is_Null then
for Assoc of Element.As_Basic_Decl.F_Aspects.F_Aspect_Assocs
loop
if To_Lower (Node_Image (Assoc.F_Id)) = "type_invariant" then
Report_Std
("warning: (gnattest) "
& Base_Name (Assoc.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Assoc)'Img, Both)
& ":"
& Trim (First_Column_Number (Assoc)'Img, Both)
& ": type_invariant aspect");
Report_Std
("this can cause circularity in the test harness", 1);
end if;
end loop;
end if;
end if;
Elem_Node.Inside_Protected := Inside_Protected;
if Requires_Body (Element.As_Ada_Node) then
Elem_Node.Spec := Element.As_Ada_Node;
if Element.Kind = Ada_Subp_Decl then
Elem_Node.Spec_Name := new String'(Get_Subp_Name (Element));
else
Elem_Node.Spec_Name := new String'
(Node_Image (Element.As_Basic_Decl.P_Defining_Name));
end if;
if Generic_Layers_Counter > 0 then
Elem_Node.Inside_Generic := True;
else
Elem_Node.Inside_Generic := False;
end if;
Data.Elem_Tree.Insert_Child
(State_Cur, Element_Node_Trees.No_Element, Elem_Node, Cur);
if
Element.Kind = Ada_Subp_Decl
and then Generic_Layers_Counter = 0
and then not Inside_Protected
then
Data.Flat_List.Append (Elem_Node);
end if;
if Element.Kind in Ada_Task_Type_Decl | Ada_Single_Task_Decl then
Tasks_Present := True;
end if;
if
Element.Kind in Ada_Package_Decl | Ada_Generic_Package_Decl
| Ada_Protected_Type_Decl | Ada_Single_Protected_Decl
then
State_Cur := Cur;
Process_Nodes (Element);
State_Cur := Parent (State_Cur);
end if;
end if;
if Element.Kind = Ada_Generic_Package_Decl then
Generic_Layers_Counter := Generic_Layers_Counter - 1;
end if;
end Create_Element_Node;
Clauses : constant Ada_Node_List :=
The_Unit.Unit.Root.As_Compilation_Unit.F_Prelude;
begin
Trace (Me, "gathering data from " & Spec_Base_File_Name);
for Cl of Clauses loop
if
Cl.Kind = Ada_With_Clause
and then Cl.As_With_Clause.F_Has_Limited
then
for WN of Cl.As_With_Clause.F_Packages loop
Data.Limited_Withed_Units.Include (Node_Image (WN));
end loop;
end if;
end loop;
Tasks_Present := False;
State_Cur := Data.Elem_Tree.Root;
Create_Element_Node (The_Unit);
end Gather_Data;
-------------------
-- Requires_Body --
-------------------
function Requires_Body (N : Ada_Node) return Boolean is
begin
case N.Kind is
when Ada_Package_Decl | Ada_Generic_Package_Decl |
Ada_Single_Protected_Decl | Ada_Protected_Type_Decl |
Ada_Single_Task_Decl | Ada_Task_Type_Decl => return True;
when Ada_Entry_Decl =>
return N.Parent.Parent.Parent.Kind = Ada_Protected_Def;
when Ada_Subp_Decl =>
if not N.As_Subp_Decl.P_Next_Part_For_Decl.Is_Null
and then N.As_Subp_Decl.P_Next_Part_For_Decl.Unit = N.Unit
then
return False;
end if;
return not N.As_Basic_Subp_Decl.P_Is_Imported;
when Ada_Generic_Subp_Decl =>
return not N.As_Generic_Subp_Decl.P_Is_Imported;
when Ada_Incomplete_Type_Decl | Ada_Incomplete_Tagged_Type_Decl =>
declare
Next_Part : constant Base_Type_Decl :=
N.As_Base_Type_Decl.P_Next_Part;
begin
if Next_Part.Is_Null then
return True;
else
return N.Unit /= Next_Part.Unit;
end if;
end;
when others => return False;
end case;
end Requires_Body;
------------------------
-- Generate_Body_Stub --
------------------------
procedure Generate_Body_Stub
(Body_File_Name : String;
Data : Data_Holder)
is
Tmp_File_Name : constant String :=
Ada.Directories.Compose
(Utils.Environment.Tool_Temp_Dir.all, "gnattest_tmp_stub_body");
Success : Boolean;
begin
Trace (Me, "generating body of " & Body_File_Name);
Increase_Indent (Me);
Create (Tmp_File_Name);
Reset_Line_Counter;
Put_Stub_Header
(Element_Node_Trees.Element
(First_Child (Data.Elem_Tree.Root)).Spec_Name.all,
not Data.Flat_List.Is_Empty,
Data.Limited_Withed_Units);
Put_Import_Section (Markered_Data, Add_Import => True);
Process_Siblings (First_Child (Data.Elem_Tree.Root));
Close_File;
declare
F : File_Array_Access;
begin
Append (F, Dir (GNATCOLL.VFS.Create (+(Body_File_Name))));
Create_Dirs (F);
end;
-- At this point temp package is coplete and it is safe
-- to replace the old one with it.
if Is_Regular_File (Body_File_Name) then
Delete_File (Body_File_Name, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete " & Body_File_Name);
end if;
end if;
Copy_File (Tmp_File_Name, Body_File_Name, Success);
if not Success then
Cmd_Error_No_Help ("cannot copy tmp test package to "
& Body_File_Name);
end if;
Delete_File (Tmp_File_Name, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete tmp test package");
end if;
Decrease_Indent (Me);
end Generate_Body_Stub;
---------------------
-- Put_Stub_Header --
---------------------
procedure Put_Stub_Header
(Unit_Name : String;
Stub_Data : Boolean := True;
Limited_Withed : String_Set.Set)
is
Cur : String_Set.Cursor := Limited_Withed.First;
use String_Set;
begin
S_Put
(0,
"-- This package has been generated "
& "automatically by GNATtest.");
New_Line_Count;
S_Put
(0,
"-- You are allowed to add your code to "
& "designated areas between read-only");
New_Line_Count;
S_Put
(0,
"-- sections. Such changes will be kept during "
& "further regeneration of this");
New_Line_Count;
S_Put
(0,
"-- file. All code placed outside of such "
& "areas will be lost during");
New_Line_Count;
S_Put
(0,
"-- regeneration of this package.");
New_Line_Count;
New_Line_Count;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
if Stub_Data then
S_Put
(0,
"with "
& Unit_Name
& "."
& Stub_Data_Unit_Name
& "; use "
& Unit_Name
& "."
& Stub_Data_Unit_Name
& ";");
end if;
New_Line_Count;
-- We need to put a regular with into the body for every limited with
-- from the spec.
while Cur /= String_Set.No_Element loop
S_Put (0, "with " & String_Set.Element (Cur) & ";");
New_Line_Count;
Next (Cur);
end loop;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Put_Stub_Header;
------------------------
-- Put_Import_Section --
------------------------
procedure Put_Import_Section
(Markered_Data : in out Markered_Data_Maps.Map;
Add_Import : Boolean := False;
Add_Pragma_05 : Boolean := False)
is
ID : constant Markered_Data_Id :=
(Import_MD,
new String'(""),
new String'(""),
new String'(Hash_Version),
new String'(""));
MD : Markered_Data_Type;
begin
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put
(0,
"-- id:"
& Hash_Version
& "/"
& MD_Kind_To_String (Import_MD)
& "/");
-- No need for hashes here
New_Line_Count;
S_Put
(0, "--");
New_Line_Count;
S_Put
(0, "-- This section can be used to add with clauses if necessary.");
New_Line_Count;
S_Put
(0, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
if Add_Pragma_05 then
New_Line_Count;
S_Put (0, "pragma Ada_2005;");
end if;
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
if Add_Import and then Tasks_Present then
S_Put (3, "with Ada.Real_Time;");
New_Line_Count;
end if;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Put_Import_Section;
--------------------------
-- Gather_Markered_Data --
--------------------------
procedure Gather_Markered_Data
(File : String; Map : in out Markered_Data_Maps.Map)
is
Line : String_Access;
Line_Counter : Natural := 0;
ID_Found, Commented_Out : Boolean;
MD : Markered_Data_Type;
ID : Markered_Data_Id := (Unknown_MD, null, null, null, null);
Input_File : Ada.Text_IO.File_Type;
type Parsing_Modes is (Code, Marker, Other);
Parsing_Mode : Parsing_Modes := Other;
Prev_Parsing_Mode : Parsing_Modes := Other;
function Is_Marker_Start (S : String) return Boolean is
(Trim (S, Both) = GT_Marker_Begin);
function Is_Marker_End (S : String) return Boolean is
(Trim (S, Both) = GT_Marker_End);
function Is_Id_String (S : String) return Boolean is
(Head (Trim (S, Both), 7) = "-- id:");
procedure Parse_Id_String
(S : String;
MD : out Markered_Data_Id;
Commented_Out : out Boolean);
procedure Parse_Id_String
(S : String;
MD : out Markered_Data_Id;
Commented_Out : out Boolean)
is
Str : constant String := Trim (S, Both);
Idx1, Idx2 : Natural;
begin
Commented_Out := False;
Idx1 := Str'First + 7;
Idx2 := Index (Str, "/", Idx1 + 1);
MD.Hash_Version := new String'(Str (Idx1 .. Idx2 - 1));
Idx1 := Idx2 + 1;
Idx2 := Index (Str, "/", Idx1 + 1);
MD.Kind := MD_Kind_From_String (Str (Idx1 .. Idx2 - 1));
if MD.Kind = Import_MD then
-- Nothing else to parse for this type
MD.Self_Hash := new String'("");
MD.Nesting_Hash := new String'("");
return;
end if;
Idx1 := Idx2 + 1;
Idx2 := Index (Str, "/", Idx1 + 1);
MD.Self_Hash := new String'(Str (Idx1 .. Idx2 - 1));
Idx1 := Idx2 + 1;
Idx2 := Index (Str, "/", Idx1 + 1);
MD.Nesting_Hash := new String'(Str (Idx1 .. Idx2 - 1));
Idx1 := Idx2 + 1;
Idx2 := Index (Str, "/", Idx1 + 1);
if Str (Idx1 .. Idx2 - 1) = "1" then
Commented_Out := True;
end if;
Idx1 := Idx2 + 1;
Idx2 := Index (Str, "/", Idx1 + 1);
MD.Name := new String'(Str (Idx1 .. Idx2 - 1));
end Parse_Id_String;
begin
if not Is_Regular_File (File) then
return;
end if;
Open (Input_File, In_File, File);
Trace (Me, "parsing " & File & " for markered blocks");
Increase_Indent (Me);
while not End_Of_File (Input_File) loop
Line := new String'(Get_Line (Input_File));
Line_Counter := Line_Counter + 1;
case Parsing_Mode is
when Code =>
if Is_Marker_Start (Line.all) then
Map.Include (ID, MD);
Prev_Parsing_Mode := Code;
Parsing_Mode := Marker;
MD.Lines := String_Vectors.Empty_Vector;
Trace
(Me,
"closing marker found at line"
& Natural'Image (Line_Counter));
else
MD.Lines.Append (Line.all);
end if;
when Marker =>
case Prev_Parsing_Mode is
when Other =>
if Is_Id_String (Line.all) then
Parse_Id_String (Line.all, ID, Commented_Out);
MD.Commneted_Out := Commented_Out;
ID_Found := True;
Trace
(Me,
"id string found at line"
& Natural'Image (Line_Counter));
end if;
if Is_Marker_End (Line.all) then
if ID_Found then
Prev_Parsing_Mode := Marker;
Parsing_Mode := Code;
Trace
(Me,
"switching to 'Code' at line"
& Natural'Image (Line_Counter));
else
Prev_Parsing_Mode := Marker;
Parsing_Mode := Other;
Trace
(Me,
"switching to 'Other' at line"
& Natural'Image (Line_Counter));
end if;
end if;
when Code =>
if Is_Marker_End (Line.all) then
Prev_Parsing_Mode := Marker;
Parsing_Mode := Other;
Trace
(Me,
"switching to 'Other' at line"
& Natural'Image (Line_Counter));
end if;
when Marker =>
-- Can't happen.
null;
end case;
when Other =>
if Is_Marker_Start (Line.all) then
Parsing_Mode := Marker;
Prev_Parsing_Mode := Other;
ID_Found := False;
Trace
(Me,
"opening marker found at line"
& Natural'Image (Line_Counter));
end if;
end case;
Free (Line);
end loop;
Decrease_Indent (Me);
Close (Input_File);
end Gather_Markered_Data;
-------------------------
-- MD_Kind_From_String --
-------------------------
function MD_Kind_From_String (Str : String) return Markered_Data_Kinds is
begin
if Str = "00" then
return Import_MD;
end if;
if Str = "01" then
return Type_MD;
end if;
if Str = "02" then
return Task_MD;
end if;
if Str = "03" then
return Package_MD;
end if;
if Str = "04" then
return Subprogram_MD;
end if;
if Str = "05" then
return Entry_MD;
end if;
if Str = "06" then
return Elaboration_MD;
end if;
return Unknown_MD;
end MD_Kind_From_String;
-----------------------
-- MD_Kind_To_String --
-----------------------
function MD_Kind_To_String (MD : Markered_Data_Kinds) return String is
begin
case MD is
when Import_MD =>
return "00";
when Type_MD =>
return "01";
when Task_MD =>
return "02";
when Package_MD =>
return "03";
when Subprogram_MD =>
return "04";
when Entry_MD =>
return "05";
when Elaboration_MD =>
return "06";
when Unknown_MD =>
return "99";
end case;
end MD_Kind_To_String;
---------
-- "<" --
---------
function "<" (L, R : Markered_Data_Id) return Boolean is
begin
if L.Kind < R.Kind then
return True;
end if;
if L.Kind = R.Kind then
if L.Self_Hash.all < R.Self_Hash.all then
return True;
end if;
if L.Self_Hash.all = R.Self_Hash.all then
if L.Nesting_Hash.all < R.Nesting_Hash.all then
return True;
end if;
if L.Nesting_Hash.all = R.Nesting_Hash.all then
if L.Hash_Version.all < R.Hash_Version.all then
return True;
end if;
end if;
end if;
end if;
return False;
end "<";
---------------------------
-- Generate_MD_Id_String --
---------------------------
function Generate_MD_Id_String
(Element : Ada_Node;
Commented_Out : Boolean := False) return String
is
Id : constant Markered_Data_Id := Generate_MD_Id (Element);
begin
return Generate_MD_Id_String (Id, Commented_Out);
end Generate_MD_Id_String;
---------------
-- Put_Lines --
---------------
procedure Put_Lines (MD : Markered_Data_Type; Comment_Out : Boolean) is
function Comment_Line (S : String) return String is ("-- " & S);
function Uncomment_Line (S : String) return String;
--------------------
-- Uncomment_Line --
--------------------
function Uncomment_Line (S : String) return String is
begin
if S = "-- " then
return "";
end if;
if S'Length < 5 then
return S;
end if;
if S (S'First .. S'First + 3) = "-- " then
return S (S'First + 4 .. S'Last);
end if;
return S;
end Uncomment_Line;
begin
if MD.Commneted_Out = Comment_Out then
for I in MD.Lines.First_Index .. MD.Lines.Last_Index loop
S_Put (0, MD.Lines.Element (I));
New_Line_Count;
end loop;
else
if Comment_Out then
for I in MD.Lines.First_Index .. MD.Lines.Last_Index loop
S_Put (0, Comment_Line (MD.Lines.Element (I)));
New_Line_Count;
end loop;
else
for I in MD.Lines.First_Index .. MD.Lines.Last_Index loop
S_Put (0, Uncomment_Line (MD.Lines.Element (I)));
New_Line_Count;
end loop;
end if;
end if;
end Put_Lines;
----------------------
-- Process_Siblings --
----------------------
procedure Process_Siblings (Cursor : Element_Node_Trees.Cursor)
is
Cur : Element_Node_Trees.Cursor := Cursor;
begin
while Cur /= Element_Node_Trees.No_Element loop
Process_Node (Cur);
Next_Sibling (Cur);
end loop;
end Process_Siblings;
------------------
-- Process_Node --
------------------
procedure Process_Node
(Cursor : Element_Node_Trees.Cursor)
is
Node : constant Element_Node := Element_Node_Trees.Element (Cursor);
Node_Kind : constant Ada_Node_Kind_Type := Node.Spec.Kind;
begin
case Node_Kind is
when Ada_Package_Decl | Ada_Generic_Package_Decl =>
Generate_Package_Body (Node, Cursor);
when Ada_Subp_Decl =>
if Node.Spec.As_Basic_Subp_Decl.P_Subp_Decl_Spec.
As_Subp_Spec.F_Subp_Kind = Ada_Subp_Kind_Function
then
Generate_Function_Body (Node);
else
Generate_Procedure_Body (Node);
end if;
when Ada_Generic_Subp_Decl =>
if Node.Spec.As_Generic_Subp_Decl.F_Subp_Decl.As_Basic_Subp_Decl.
P_Subp_Decl_Spec.As_Subp_Spec.F_Subp_Kind =
Ada_Subp_Kind_Function
then
Generate_Function_Body (Node);
else
Generate_Procedure_Body (Node);
end if;
when Ada_Entry_Decl =>
Generate_Entry_Body (Node);
when Ada_Single_Protected_Decl | Ada_Protected_Type_Decl =>
Generate_Protected_Body (Node, Cursor);
when Ada_Single_Task_Decl | Ada_Task_Type_Decl =>
Generate_Task_Body (Node);
when Ada_Incomplete_Type_Decl | Ada_Incomplete_Tagged_Type_Decl =>
Generate_Full_Type_Declaration (Node);
when others => null;
end case;
end Process_Node;
---------------------------
-- Generate_Package_Body --
---------------------------
procedure Generate_Package_Body
(Node : Element_Node; Cursor : Element_Node_Trees.Cursor)
is
Cur : constant Element_Node_Trees.Cursor := Cursor;
ID : Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
begin
if Is_Leaf (Cur) and then not Is_Root (Parent (Cur)) then
-- Nothing to worry about
return;
end if;
Trace (Me, "Generating package body for " & Node.Spec_Name.all);
-- Put local declaration section
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
S_Put
(Level * Indent_Level,
"package body " & Node.Spec_Name.all);
New_Line_Count;
Level := Level + 1;
S_Put
((Level) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level) * Indent_Level,
"-- This section can be used for local declarations.");
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put bodies
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put
((Level - 1) * Indent_Level, "is");
New_Line_Count;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
if not Is_Leaf (Cur) then
Process_Siblings (First_Child (Cur));
end if;
-- Put possible Elab sections
S_Put (0, GT_Marker_Begin);
New_Line_Count;
ID.Kind := Elaboration_MD;
S_Put
((Level) * Indent_Level,
Generate_MD_Id_String (ID));
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put
(Level * Indent_Level,
"-- This section can be used for elaboration statements.");
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
end if;
-- Put end package
Level := Level - 1;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put
(Level * Indent_Level,
"end " & Node.Spec_Name.all & ";");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
-- If we are in the root package, we have to print all the dangling
-- elements (if any).
if Is_Root (Parent (Cur)) then
if not Markered_Data.Is_Empty then
Report_Std
(" warning: (gnattest) "
& Node.Spec_Name.all
& " has dangling element(s)");
Put_Dangling_Elements;
end if;
end if;
end Generate_Package_Body;
--------------------
-- Generate_MD_Id --
--------------------
function Generate_MD_Id (Element : Ada_Node)
return Markered_Data_Id
is
Arg_Kind : constant Ada_Node_Kind_Type := Element.Kind;
Id : Markered_Data_Id;
begin
Id.Hash_Version := new String'(Hash_Version);
case Arg_Kind is
when Ada_Incomplete_Type_Decl |
Ada_Incomplete_Tagged_Type_Decl =>
Id.Kind := Type_MD;
Id.Self_Hash := new String'
(Substring_16
(GNAT.SHA1.Digest
(Node_Image (Element.As_Basic_Decl.P_Defining_Name))));
when Ada_Task_Type_Decl |
Ada_Single_Task_Decl =>
Id.Kind := Task_MD;
Id.Self_Hash := new String'
(Substring_16
(GNAT.SHA1.Digest
(Node_Image (Element.As_Basic_Decl.P_Defining_Name))));
when Ada_Package_Decl |
Ada_Generic_Package_Decl =>
Id.Kind := Package_MD;
Id.Self_Hash := new String'
(Substring_16
(GNAT.SHA1.Digest
(Node_Image (Element.As_Basic_Decl.P_Defining_Name))));
when Ada_Generic_Subp_Decl |
Ada_Subp_Decl =>
Id.Kind := Subprogram_MD;
if Arg_Kind = Ada_Generic_Subp_Decl then
Id.Self_Hash := new String'
(Substring_16
(GNAT.SHA1.Digest
(Node_Image (Element.As_Basic_Decl.P_Defining_Name))));
else
Id.Self_Hash := new String'
(Substring_16
(Mangle_Hash_16 (Element, For_Stubs => True)));
end if;
when Ada_Entry_Decl =>
Id.Kind := Entry_MD;
Id.Self_Hash := new String'
(Substring_16
(GNAT.SHA1.Digest
(Node_Image (Element.As_Basic_Decl.P_Defining_Name))));
when others =>
null;
end case;
Id.Nesting_Hash := new String'
(Substring_16 (GNAT.SHA1.Digest (Get_Nesting (Element))));
Id.Name := new String'
(Node_Image (Element.As_Basic_Decl.P_Defining_Name));
return Id;
end Generate_MD_Id;
---------------------------
-- Generate_MD_Id_String --
---------------------------
function Generate_MD_Id_String
(Id : Markered_Data_Id;
Commented_Out : Boolean := False) return String
is
Res : constant String :=
"-- id:"
& Hash_Version
& "/"
& MD_Kind_To_String (Id.Kind)
& "/"
& Id.Self_Hash.all
& "/"
& Id.Nesting_Hash.all
& "/"
& (if Commented_Out then "1" else "0")
& "/"
& Id.Name.all
& "/";
begin
return Res;
end Generate_MD_Id_String;
-----------------------------
-- Generate_Procedure_Body --
-----------------------------
procedure Generate_Procedure_Body (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
Arg_Kind : constant Ada_Node_Kind_Type := Node.Spec.Kind;
Spec : constant Base_Subp_Spec'Class :=
(if Arg_Kind = Ada_Generic_Subp_Decl then
Node.Spec.As_Generic_Subp_Decl.F_Subp_Decl.P_Subp_Decl_Spec
else
Node.Spec.As_Basic_Subp_Decl.P_Subp_Decl_Spec);
Parameters : constant Param_Spec_Array := Spec.P_Params;
Param_List : constant Stubbed_Parameter_Lists.List :=
Get_Args_List (Node);
Cur : Stubbed_Parameter_Lists.Cursor;
SP : Stubbed_Parameter;
Suffix : constant String := Hash_Suffix (ID);
Not_Empty_Stub : constant Boolean :=
Arg_Kind = Ada_Subp_Decl and then -- Not generic
not Node.Inside_Generic and then
not Node.Inside_Protected;
Has_Limited_Params : Boolean := False;
Has_Limited_View_Params : Boolean := False;
Has_Private_Params : Boolean := False;
begin
Trace (Me, "Generating procedure body for " & Node.Spec_Name.all);
Increase_Indent (Me);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
if Arg_Kind = Ada_Subp_Decl then
if Node.Spec.As_Classic_Subp_Decl.F_Overriding.Kind =
Ada_Overriding_Overriding
then
S_Put (Level * Indent_Level, "overriding");
New_Line_Count;
elsif Node.Spec.As_Classic_Subp_Decl.F_Overriding.Kind =
Ada_Overriding_Not_Overriding
then
S_Put (Level * Indent_Level, "not overriding");
New_Line_Count;
end if;
end if;
S_Put (Level * Indent_Level, "procedure " & Node.Spec_Name.all);
if Parameters'Length = 0 then
S_Put (0, " is");
New_Line_Count;
else
New_Line_Count;
S_Put
(Level * Indent_Level + 2, "(");
for I in Parameters'Range loop
if I = Parameters'First then
S_Put (0, Node_Image (Parameters (I)));
else
S_Put
((Level + 1) * Indent_Level, Node_Image (Parameters (I)));
end if;
if I = Parameters'Last then
S_Put (0, ") is");
else
S_Put (0, ";");
end if;
New_Line_Count;
end loop;
end if;
S_Put
((Level + 1) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"-- This section can be used to change the procedure body.");
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put body
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put ((Level) * Indent_Level, "begin");
New_Line_Count;
if Not_Empty_Stub then
New_Line_Count;
S_Put
(6,
Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& Stub_Counter_Var
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& Stub_Counter_Var
& " + 1;");
New_Line_Count;
if not Param_List.Is_Empty then
Cur := Param_List.First;
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if Is_Only_Limited_Withed (SP.Type_Elem.As_Type_Expr) then
Has_Limited_View_Params := True;
elsif Is_Limited (SP.Type_Elem.As_Type_Expr) then
Has_Limited_Params := True;
elsif Is_Fully_Private (SP.Type_Elem.As_Type_Expr) then
Has_Private_Params := True;
else
case SP.Kind is
when Constrained =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& " := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ";");
when Not_Constrained =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& " := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ".all;");
when Access_Kind =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& ".all := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ".all;");
end case;
New_Line_Count;
end if;
Next (Cur);
end loop;
end if;
else
S_Put
((Level + 1) * Indent_Level,
"pragma Compile_Time_Warning");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level + 2,
"(Standard.True,");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"""Stub for "
& Node.Spec_Name.all
& " is unimplemented,""");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"& "" this might affect some tests"");");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"null;");
New_Line_Count;
end if;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put ((Level) * Indent_Level, "end " & Node.Spec_Name.all & ";");
New_Line_Count;
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
if Has_Limited_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has limited type parameter, generated setter is incomplete");
end if;
if Has_Limited_View_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has parameter of a limited view type, "
& "generated setter is incomplete");
end if;
if Has_Private_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has private type parameter, generated setter is incomplete");
end if;
Decrease_Indent (Me);
end Generate_Procedure_Body;
----------------------------
-- Generate_Function_Body --
----------------------------
procedure Generate_Function_Body (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
Arg_Kind : constant Ada_Node_Kind_Type := Node.Spec.Kind;
Spec : constant Base_Subp_Spec'Class :=
(if Arg_Kind = Ada_Generic_Subp_Decl then
Node.Spec.As_Generic_Subp_Decl.F_Subp_Decl.P_Subp_Decl_Spec
else
Node.Spec.As_Basic_Subp_Decl.P_Subp_Decl_Spec);
Parameters : constant Param_Spec_Array := Spec.P_Params;
Res_Profile : constant Type_Expr := Spec.As_Subp_Spec.F_Subp_Returns;
Param_List : constant Stubbed_Parameter_Lists.List :=
Get_Args_List (Node);
Cur : Stubbed_Parameter_Lists.Cursor;
SP : Stubbed_Parameter;
Suffix : constant String := Hash_Suffix (ID);
Not_Empty_Stub : constant Boolean :=
Arg_Kind = Ada_Subp_Decl and then -- Not generic
not Node.Inside_Generic and then
not Node.Inside_Protected;
Has_Limited_Params : Boolean := False;
Has_Limited_View_Params : Boolean := False;
Has_Private_Params : Boolean := False;
procedure Output_Fake_Parameters;
-- Prints out the fake parameters of the fake recursive call of the
-- function to itself.
procedure Output_Fake_Parameters is
Idx : Positive;
begin
S_Put (0, " (");
for J in Parameters'Range loop
declare
Formal_Names : constant Defining_Name_List :=
F_Ids (Parameters (J));
begin
Idx := Formal_Names.Defining_Name_List_First;
loop
S_Put
(0,
Node_Image
(Formal_Names.Defining_Name_List_Element (Idx))
& " => "
& Node_Image
(Formal_Names.Defining_Name_List_Element (Idx)));
Idx := Formal_Names.Defining_Name_List_Next (Idx);
if
Formal_Names.Defining_Name_List_Has_Element (Idx)
or else J /= Parameters'Last
then
S_Put (0, ", ");
end if;
exit when
not Formal_Names.Defining_Name_List_Has_Element (Idx);
end loop;
end;
end loop;
S_Put (0, ");");
end Output_Fake_Parameters;
begin
Trace (Me, "Generating function body for " & Node.Spec_Name.all);
Increase_Indent (Me);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
if Arg_Kind = Ada_Subp_Decl then
if Node.Spec.As_Classic_Subp_Decl.F_Overriding.Kind =
Ada_Overriding_Overriding
then
S_Put (Level * Indent_Level, "overriding");
New_Line_Count;
elsif Node.Spec.As_Classic_Subp_Decl.F_Overriding.Kind =
Ada_Overriding_Not_Overriding
then
S_Put (Level * Indent_Level, "not overriding");
New_Line_Count;
end if;
end if;
S_Put
(Level * Indent_Level,
"function " & Node_Image (Node.Spec.As_Basic_Decl.P_Defining_Name));
if Parameters'Length = 0 then
S_Put
(0,
" return "
& Node_Image (Res_Profile)
& " is");
New_Line_Count;
else
New_Line_Count;
S_Put
(Level * Indent_Level + 2, "(");
for I in Parameters'Range loop
if I = Parameters'First then
S_Put (0, Node_Image (Parameters (I)));
else
S_Put
((Level + 1) * Indent_Level, Node_Image (Parameters (I)));
end if;
if I = Parameters'Last then
S_Put
(0,
") return "
& Node_Image (Res_Profile)
& " is");
else
S_Put (0, ";");
end if;
New_Line_Count;
end loop;
end if;
S_Put
((Level + 1) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"-- This section can be used to change the function body.");
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put body
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put ((Level) * Indent_Level, "begin");
New_Line_Count;
if Not_Empty_Stub then
New_Line_Count;
S_Put
(6,
Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& Stub_Counter_Var
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& Stub_Counter_Var
& " + 1;");
New_Line_Count;
if not Param_List.Is_Empty then
Cur := Param_List.First;
while Cur /= Param_List.Last loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if Is_Only_Limited_Withed (SP.Type_Elem.As_Type_Expr) then
Has_Limited_View_Params := True;
elsif Is_Limited (SP.Type_Elem.As_Type_Expr) then
Has_Limited_Params := True;
elsif Is_Fully_Private (SP.Type_Elem.As_Type_Expr) then
Has_Private_Params := True;
else
case SP.Kind is
when Constrained =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& " := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ";");
when Not_Constrained =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& " := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ".all;");
when Access_Kind =>
S_Put
((Level + 1) * Indent_Level,
SP.Name.all
& ".all := "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ".all;");
end case;
New_Line_Count;
end if;
Next (Cur);
end loop;
end if;
-- Processing result profile
SP := Param_List.Last_Element;
if
Is_Only_Limited_Withed (SP.Type_Elem.As_Type_Expr)
or else Is_Abstract (SP.Type_Elem.As_Type_Expr)
or else Is_Limited (SP.Type_Elem.As_Type_Expr)
or else Is_Fully_Private (SP.Type_Elem.As_Type_Expr)
then
S_Put
((Level + 1) * Indent_Level,
"pragma Compile_Time_Warning");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level + 2,
"(Standard.True,");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"""Stub for "
& Node.Spec_Name.all
& " is unimplemented,""");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"& "" this might affect some tests"");");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"raise Program_Error with ""Unimplemented stub for function "
& Node.Spec_Name.all
& """;");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"return "
& Node_Image (Node.Spec.As_Basic_Decl.P_Defining_Name));
if Parameters'Length = 0 then
S_Put (0, ";");
else
Output_Fake_Parameters;
end if;
else
case SP.Kind is
when Constrained | Access_Kind =>
S_Put
((Level + 1) * Indent_Level,
"return "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ";");
when Not_Constrained =>
S_Put
((Level + 1) * Indent_Level,
"return "
& Stub_Data_Unit_Name
& "."
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& ".all;");
end case;
end if;
New_Line_Count;
else
S_Put
((Level + 1) * Indent_Level,
"pragma Compile_Time_Warning");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level + 2,
"(Standard.True,");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"""Stub for "
& Node.Spec_Name.all
& " is unimplemented,""");
New_Line_Count;
S_Put
((Level + 2) * Indent_Level,
"& "" this might affect some tests"");");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"raise Program_Error with ""Unimplemented stub for function "
& Node.Spec_Name.all
& """;");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"return "
& Node_Image (Node.Spec.As_Basic_Decl.P_Defining_Name));
if Parameters'Length = 0 then
S_Put (0, ";");
else
Output_Fake_Parameters;
end if;
New_Line_Count;
end if;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put
((Level) * Indent_Level,
"end " & Node_Image (Node.Spec.As_Basic_Decl.P_Defining_Name) & ";");
New_Line_Count;
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
if Has_Limited_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has limited type parameter, generated setter is incomplete");
end if;
if Has_Limited_View_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has parameter of a limited view type, "
& "generated setter is incomplete");
end if;
if Has_Private_Params then
Report_Std
("warning: (gnattest) "
& Base_Name (Node.Spec.Unit.Get_Filename)
& ":"
& Trim (First_Line_Number (Node.Spec)'Img, Both)
& ":"
& Trim (First_Column_Number (Node.Spec)'Img, Both)
& ": "
& Node.Spec_Name.all
& " has private type parameter, generated setter is incomplete");
end if;
Decrease_Indent (Me);
end Generate_Function_Body;
-------------------
-- Get_Args_List --
-------------------
function Get_Args_List (Node : Element_Node)
return Stubbed_Parameter_Lists.List
is
Result : Stubbed_Parameter_Lists.List :=
Stubbed_Parameter_Lists.Empty_List;
Spec : constant Base_Subp_Spec'Class :=
(if Node.Spec.Kind = Ada_Generic_Subp_Decl then
Node.Spec.As_Generic_Subp_Decl.F_Subp_Decl.P_Subp_Decl_Spec
else
Node.Spec.As_Basic_Subp_Decl.P_Subp_Decl_Spec);
Parameters : constant Param_Spec_Array := Spec.P_Params;
SP : Stubbed_Parameter;
function Can_Declare_Variable (Param_Type : Type_Expr) return Boolean;
function Can_Declare_Variable (Param_Type : Type_Expr) return Boolean is
Param_Type_Name : Libadalang.Analysis.Name;
Attr_Name : Identifier;
begin
if Is_Only_Limited_Withed (Param_Type) then
return False;
end if;
if Param_Type.Kind = Ada_Subtype_Indication then
Param_Type_Name := Param_Type.As_Subtype_Indication.F_Name;
if Param_Type_Name.Kind = Ada_Attribute_Ref then
Attr_Name := Param_Type_Name.As_Attribute_Ref.F_Attribute;
if To_Lower (Node_Image (Attr_Name)) = "class" then
return False;
end if;
end if;
end if;
return
Get_Declaration
(Param_Type.As_Subtype_Indication).P_Is_Definite_Subtype
(Param_Type);
end Can_Declare_Variable;
begin
Trace (Me, "Getting argument list for " & Node.Spec_Name.all);
Increase_Indent (Me);
for J in Parameters'Range loop
declare
Param : constant Param_Spec := Parameters (J);
Name_List : constant Defining_Name_List := F_Ids (Param);
Param_Type : constant Type_Expr := Param.F_Type_Expr;
Type_Of_Interest : constant Boolean :=
Is_Only_Limited_Withed (Param_Type)
or else not Is_Abstract (Param_Type);
-- From limited view or else not abstract
begin
if Type_Of_Interest then
if Param_Type.Kind = Ada_Anonymous_Type
and then Param_Type.As_Anonymous_Type.F_Type_Decl.
As_Type_Decl.F_Type_Def.Kind = Ada_Type_Access_Def
and then not Param_Type.As_Anonymous_Type.F_Type_Decl.
As_Type_Decl.F_Type_Def.As_Type_Access_Def.F_Has_Constant
then
for N of Name_List loop
SP.Name := new String'(Node_Image (N));
SP.Type_Image := new String'(Node_Image (Param_Type));
SP.Type_Full_Name_Image := new String'
(Get_Type_Image (Param_Type));
SP.Kind := Access_Kind;
SP.Type_Elem := Param_Type.As_Ada_Node;
Result.Append (SP);
end loop;
elsif Param.F_Mode.Kind in Ada_Mode_In_Out | Ada_Mode_Out then
for N of Name_List loop
SP.Name := new String'(Node_Image (N));
SP.Type_Elem := Param_Type.As_Ada_Node;
if Can_Declare_Variable (Param_Type) then
SP.Type_Image := new String'(Node_Image (Param_Type));
SP.Type_Full_Name_Image := new String'
(Get_Type_Image (Param_Type));
SP.Kind := Constrained;
else
SP.Type_Image := new String'
(Get_Access_Type_Name
(Param_Type.As_Subtype_Indication));
SP.Type_Full_Name_Image := new String'
(Get_Access_Type_Name
(Param_Type.As_Subtype_Indication));
SP.Kind := Not_Constrained;
if not Is_Fully_Private (Param_Type) then
Add_Unconstrained_Type_To_Dictionary
(Param_Type.As_Subtype_Indication);
end if;
end if;
Result.Append (SP);
end loop;
end if;
end if;
end;
end loop;
if Spec.As_Subp_Spec.F_Subp_Kind.Kind = Ada_Subp_Kind_Function then
declare
Res_Profile : constant Type_Expr :=
Spec.As_Subp_Spec.F_Subp_Returns;
begin
SP.Name := new String'(Node.Spec_Name.all & Stub_Result_Suffix);
SP.Type_Elem := Res_Profile.As_Ada_Node;
if Res_Profile.Kind = Ada_Anonymous_Type then
SP.Type_Image := new String'(Node_Image (Res_Profile));
SP.Type_Full_Name_Image := new String'
(Get_Type_Image (Res_Profile));
SP.Kind := Access_Kind;
else
if Can_Declare_Variable (Res_Profile) then
SP.Type_Image := new String'(Node_Image (Res_Profile));
SP.Type_Full_Name_Image := new String'
(Get_Type_Image (Res_Profile));
SP.Kind := Constrained;
else
SP.Type_Image := new String'
(Get_Access_Type_Name (Res_Profile.As_Subtype_Indication));
SP.Type_Full_Name_Image := new String'
(Get_Access_Type_Name (Res_Profile.As_Subtype_Indication));
SP.Kind := Not_Constrained;
if not Is_Fully_Private (Res_Profile) then
Add_Unconstrained_Type_To_Dictionary
(Res_Profile.As_Subtype_Indication);
end if;
end if;
end if;
end;
Result.Append (SP);
end if;
Decrease_Indent (Me);
return Result;
end Get_Args_List;
-----------------
-- Is_Abstract --
-----------------
function Is_Abstract (Param_Type : Type_Expr) return Boolean is
Param_Type_Def : Type_Def;
Type_Decl, Decl : Base_Type_Decl;
Subtype_Ind : Subtype_Indication;
begin
if Param_Type.Kind = Ada_Anonymous_Type then
Param_Type_Def := Param_Type.As_Anonymous_Type.F_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Access_To_Subp_Def then
return False;
else
Subtype_Ind :=
Param_Type_Def.As_Type_Access_Def.F_Subtype_Indication;
end if;
else
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;
Type_Decl := Get_Declaration (Subtype_Ind);
if Type_Decl.Kind in Ada_Generic_Formal then
return False;
end if;
if Type_Decl.Kind in Ada_Interface_Kind then
return True;
end if;
Decl := Type_Decl;
while not Decl.Is_Null loop
if Abstract_Type (Decl) then
return True;
end if;
Decl := Decl.P_Next_Part;
end loop;
Decl := Type_Decl.P_Previous_Part;
while not Decl.Is_Null loop
if Abstract_Type (Decl) then
return True;
end if;
Decl := Decl.P_Previous_Part;
end loop;
return False;
end Is_Abstract;
-----------------
-- Hash_Suffix --
-----------------
function Hash_Suffix (ID : Markered_Data_Id) return String is
Self_First : constant Integer := ID.Self_Hash.all'First;
Self_Last : constant Integer := ID.Self_Hash.all'First + 5;
Nesting_First : constant Integer := ID.Nesting_Hash.all'First;
Nesting_Last : constant Integer := ID.Nesting_Hash.all'First + 5;
begin
return
"_"
& ID.Self_Hash.all (Self_First .. Self_Last)
& "_"
& ID.Nesting_Hash.all (Nesting_First .. Nesting_Last);
end Hash_Suffix;
--------------------------
-- Get_Access_Type_Name --
--------------------------
function Get_Access_Type_Name (Elem : Subtype_Indication) return String is
Decl : constant Base_Type_Decl := Get_Declaration (Elem);
Attr_Suff : constant String :=
(if Elem.F_Name.Kind = Ada_Attribute_Ref then
"_" & Node_Image (Elem.F_Name.As_Attribute_Ref.F_Attribute)
else "");
begin
if Get_Nesting (Decl) = "Standard" then
declare
S : String :=
Node_Image (Decl.P_Defining_Name) & Attr_Suff & "_Access";
begin
for I in S'Range loop
if S (I) = '.' then
S (I) := '_';
end if;
end loop;
return S;
end;
else
declare
S : String :=
Encode
(Decl.As_Basic_Decl.P_Fully_Qualified_Name,
Decl.Unit.Get_Charset)
& Attr_Suff & "_Access";
begin
for I in S'Range loop
if S (I) = '.' then
S (I) := '_';
end if;
end loop;
return S;
end;
end if;
end Get_Access_Type_Name;
--------------------
-- Get_Type_Image --
--------------------
function Get_Type_Image (Param_Type : Type_Expr) return String is
Param_Type_Def : Type_Def;
Subtype_Ind : Subtype_Indication;
Decl : Base_Type_Decl;
Enclosing_Unit_Name : constant String :=
To_Lower
(Node_Image
(Param_Type.Unit.Root.As_Compilation_Unit.F_Body.As_Library_Item.
F_Item.As_Basic_Decl.P_Defining_Name));
Overall_Image : constant String := Node_Image (Param_Type);
begin
if Param_Type.Kind = Ada_Anonymous_Type then
Param_Type_Def :=
Param_Type.As_Anonymous_Type.F_Type_Decl.As_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Access_To_Subp_Def then
return Overall_Image;
else
Subtype_Ind :=
Param_Type_Def.As_Type_Access_Def.F_Subtype_Indication;
end if;
else
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;
Decl := Get_Declaration (Subtype_Ind);
if To_Lower (Get_Nesting (Decl)) = "standard" then
return Overall_Image;
end if;
declare
Insts : constant Generic_Instantiation_Array :=
Decl.P_Generic_Instantiations;
begin
if Insts'Length = 0 and then Decl.Unit /= Param_Type.Unit then
-- Type declared in another unit, we can keep type name as is
return Overall_Image;
elsif Insts'Length > 0
and then Insts (Insts'First).Unit /= Param_Type.Unit
then
-- Type declared in an instantiation that is declared in another
-- unit, we can keep the type name as is.
return Overall_Image;
end if;
end;
-- At this point the type is daclared in an instantiation that itself if
-- declared in the same unit. It may be declared in the same nested
-- package, in that case we need to put a fully qualified name istead
-- of the original name.
declare
Type_Full : constant String :=
Encode
(Decl.As_Basic_Decl.P_Fully_Qualified_Name,
Decl.Unit.Get_Charset);
Type_Nesting : constant String :=
To_Lower
(Type_Full
(Type_Full'First .. Index (Type_Full, ".", Backward) - 1));
Span_Start : constant Token_Reference := Param_Type.Token_Start;
Span_End : constant Token_Reference := Param_Type.Token_End;
Type_Name : Libadalang.Analysis.Name;
begin
Type_Name := Subtype_Ind.F_Name;
if Type_Name.Kind = Ada_Attribute_Ref then
Type_Name := Type_Name.As_Attribute_Ref.F_Prefix;
end if;
if
Index (Type_Nesting, Enclosing_Unit_Name) /= Type_Nesting'First
or else Type_Nesting'Length <= Enclosing_Unit_Name'Length
then
-- Not a nested type declaration from the same package
return Overall_Image;
end if;
return
Encode
(Text (Span_Start, Previous (Type_Name.Token_Start)),
Subtype_Ind.Unit.Get_Charset)
& Type_Full
& Encode
(Text (Next (Type_Name.Token_End), Span_End),
Subtype_Ind.Unit.Get_Charset);
end;
end Get_Type_Image;
----------------------
-- Is_Fully_Private --
----------------------
function Is_Fully_Private (Param_Type : Type_Expr) return Boolean is
Param_Type_Def : Type_Def;
Type_Decl : Base_Type_Decl;
Subtype_Ind : Subtype_Indication;
begin
if Param_Type.Kind = Ada_Anonymous_Type then
Param_Type_Def := Param_Type.As_Anonymous_Type.F_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Access_To_Subp_Def then
-- Anonymous access to subprogram cannot be private anyway
return False;
else
Subtype_Ind :=
Param_Type_Def.As_Type_Access_Def.F_Subtype_Indication;
end if;
else
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;
Type_Decl := Get_Declaration (Subtype_Ind);
if Type_Decl.Kind in Ada_Generic_Formal then
return False;
end if;
while not Type_Decl.P_Previous_Part.Is_Null loop
Type_Decl := Type_Decl.P_Previous_Part;
end loop;
return Is_Private (Type_Decl);
end Is_Fully_Private;
----------------
-- Is_Limited --
----------------
function Is_Limited (Param_Type : Type_Expr) return Boolean is
Param_Type_Def : Type_Def;
Type_Decl, Decl : Base_Type_Decl;
Subtype_Ind : Subtype_Indication;
function Limited_Type (Decl : Base_Type_Decl) return Boolean;
function Limited_Type (Decl : Base_Type_Decl) return Boolean is
Type_Decl : constant Base_Type_Decl := Decl;
begin
if
Type_Decl.Kind = Ada_Incomplete_Tagged_Type_Decl and then
Type_Decl.As_Incomplete_Tagged_Type_Decl.F_Has_Abstract
then
return False;
end if;
if Type_Decl.Kind in Ada_Type_Decl then
Param_Type_Def := Type_Decl.As_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Derived_Type_Def
and then Param_Type_Def.As_Derived_Type_Def.F_Has_Limited
then
return True;
elsif Param_Type_Def.Kind = Ada_Private_Type_Def
and then Param_Type_Def.As_Private_Type_Def.F_Has_Limited
then
return True;
elsif Param_Type_Def.Kind = Ada_Record_Type_Def
and then Param_Type_Def.As_Record_Type_Def.F_Has_Limited
then
return True;
elsif Param_Type_Def.Kind = Ada_Interface_Type_Def
and then not Param_Type_Def.As_Interface_Type_Def.
F_Interface_Kind.Is_Null
and then Param_Type_Def.As_Interface_Type_Def.F_Interface_Kind =
Ada_Interface_Kind_Limited
then
return True;
end if;
end if;
return False;
end Limited_Type;
begin
if Param_Type.Kind = Ada_Anonymous_Type then
Param_Type_Def := Param_Type.As_Anonymous_Type.F_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Access_To_Subp_Def then
-- Anonymous access to subprogram cannot be private anyway
return False;
else
Subtype_Ind :=
Param_Type_Def.As_Type_Access_Def.F_Subtype_Indication;
end if;
else
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;
Type_Decl := Get_Declaration (Subtype_Ind).P_Canonical_Type;
if Type_Decl.Kind = Ada_Classwide_Type_Decl
and then Get_Declaration (Subtype_Ind).Kind = Ada_Subtype_Decl
then
Type_Decl :=
Get_Declaration
(Subtype_Ind).As_Subtype_Decl.F_Subtype.F_Name.P_Relative_Name.
P_Referenced_Decl.As_Base_Type_Decl;
end if;
while not Type_Decl.Is_Null loop
if Type_Decl.Kind in Ada_Generic_Formal then
return False;
end if;
Decl := Type_Decl;
while not Decl.Is_Null loop
if Limited_Type (Decl) then
return True;
end if;
Decl := Decl.P_Next_Part;
end loop;
Decl := Type_Decl.P_Previous_Part;
while not Decl.Is_Null loop
if Limited_Type (Decl) then
return True;
end if;
Decl := Decl.P_Previous_Part;
end loop;
Decl := Type_Decl;
while not Decl.P_Next_Part.Is_Null loop
Decl := Decl.P_Next_Part;
end loop;
Type_Decl := Parent_Type_Declaration (Decl);
end loop;
return False;
end Is_Limited;
----------------------------
-- Is_Only_Limited_Withed --
----------------------------
function Is_Only_Limited_Withed (Param_Type : Type_Expr) return Boolean is
Param_Type_Def : Type_Def;
Type_Decl : Base_Type_Decl;
Subtype_Ind : Subtype_Indication;
Origin_Unit : constant Analysis_Unit := Param_Type.Unit;
Type_Unit : Analysis_Unit;
Parent_Unit : Ada_Node;
begin
if Param_Type.Kind = Ada_Anonymous_Type then
Param_Type_Def := Param_Type.As_Anonymous_Type.F_Type_Decl.F_Type_Def;
if Param_Type_Def.Kind = Ada_Access_To_Subp_Def then
return False;
else
Subtype_Ind :=
Param_Type_Def.As_Type_Access_Def.F_Subtype_Indication;
end if;
else
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;
Type_Decl := Get_Declaration (Subtype_Ind);
declare
Insts : constant Generic_Instantiation_Array :=
Type_Decl.P_Generic_Instantiations;
begin
if Insts'Length > 0 then
Type_Unit := Insts (Insts'First).Unit;
else
Type_Unit := Type_Decl.Unit;
end if;
end;
if Type_Unit = Type_Decl.P_Standard_Unit then
return False;
end if;
if Origin_Unit = Type_Unit then
return False;
end if;
-- Units are different, we need to analyse with clauses of original unit
-- and check whether it is a parent unit.
Parent_Unit := Param_Type.P_Semantic_Parent;
while not Parent_Unit.Is_Null and then
Parent_Unit.Unit /= Parent_Unit.P_Standard_Unit
loop
if Parent_Unit.Unit = Type_Unit then
return False;
end if;
Parent_Unit := Parent_Unit.P_Semantic_Parent;
end loop;
declare
Clauses : constant Ada_Node_List :=
Origin_Unit.Root.As_Compilation_Unit.F_Prelude;
begin
for Cl of Clauses loop
if
Cl.Kind = Ada_With_Clause
and then not Cl.As_With_Clause.F_Has_Limited
then
declare
With_Names : constant Name_List :=
Cl.As_With_Clause.F_Packages;
Withed_Spec : Ada_Node;
Type_Unit_Spec : constant Ada_Node :=
Type_Unit.Root.As_Compilation_Unit.F_Body.
As_Library_Item.F_Item.As_Ada_Node;
begin
for WN of With_Names loop
Withed_Spec := WN.As_Name.P_Referenced_Decl.As_Ada_Node;
if Withed_Spec.Kind = Ada_Package_Renaming_Decl then
-- Package renamings should be unwinded
Withed_Spec := Withed_Spec.As_Package_Renaming_Decl.
F_Renames.F_Renamed_Object.
P_Referenced_Decl.As_Ada_Node;
end if;
while not Withed_Spec.Is_Null loop
if Withed_Spec = Type_Unit_Spec then
-- Parameter type declared in a unit from with
-- clause or one of its parent units.
return False;
end if;
Withed_Spec := Withed_Spec.P_Semantic_Parent;
end loop;
end loop;
end;
end if;
end loop;
end;
return True;
end Is_Only_Limited_Withed;
-------------------------
-- Generate_Entry_Body --
-------------------------
procedure Generate_Entry_Body (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
Parameters : constant Param_Spec_Array :=
Node.Spec.As_Basic_Subp_Decl.P_Subp_Decl_Spec.P_Params;
Family_Def : constant Ada_Node :=
Node.Spec.As_Entry_Decl.F_Spec.F_Family_Type;
begin
Trace (Me, "Generating entry body for " & Node.Spec_Name.all);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
S_Put
(Level * Indent_Level,
"entry " & Node.Spec_Name.all);
if not Family_Def.Is_Null then
S_Put
(0,
" (for I in "
& Node_Image (Family_Def)
& ")");
end if;
New_Line_Count;
if Parameters'Length > 0 then
S_Put
(Level * Indent_Level + 2, "(");
for I in Parameters'Range loop
if I = Parameters'First then
S_Put (0, Node_Image (Parameters (I)));
else
S_Put
((Level + 1) * Indent_Level,
Node_Image (Parameters (I)));
end if;
if I = Parameters'Last then
S_Put (0, ") when");
else
S_Put (0, ";");
end if;
New_Line_Count;
end loop;
else
S_Put
(Level * Indent_Level + 2, "when");
New_Line_Count;
end if;
S_Put
((Level + 1) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"-- This section can be used to change entry body.");
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put body
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put (Level * Indent_Level + 2, " Standard.True");
New_Line_Count;
S_Put (Level * Indent_Level, "is");
New_Line_Count;
S_Put ((Level) * Indent_Level, "begin");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"null;");
New_Line_Count;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put ((Level) * Indent_Level, "end " & Node.Spec_Name.all & ";");
New_Line_Count;
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Generate_Entry_Body;
-----------------------------
-- Generate_Protected_Body --
-----------------------------
procedure Generate_Protected_Body
(Node : Element_Node; Cursor : Element_Node_Trees.Cursor)
is
Cur : constant Element_Node_Trees.Cursor := Cursor;
begin
Trace (Me, "Generating protected body for " & Node.Spec_Name.all);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
S_Put
(Level * Indent_Level,
"protected body " & Node.Spec_Name.all & " is");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
Level := Level + 1;
if not Is_Leaf (Cur) then
Process_Siblings (First_Child (Cur));
end if;
Level := Level - 1;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put
(Level * Indent_Level,
"end " & Node.Spec_Name.all & ";");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Generate_Protected_Body;
------------------------
-- Generate_Task_Body --
------------------------
procedure Generate_Task_Body (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
begin
Trace (Me, "Generating task body for " & Node.Spec_Name.all);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
S_Put
(Level * Indent_Level,
"task body " & Node.Spec_Name.all & " is");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"-- This section can be used to change task body.");
New_Line_Count;
S_Put ((Level + 1) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put body
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put ((Level) * Indent_Level, "begin");
New_Line_Count;
S_Put
((Level + 1) * Indent_Level,
"delay until Ada.Real_Time.Time_Last;");
New_Line_Count;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put ((Level) * Indent_Level, "end " & Node.Spec_Name.all & ";");
New_Line_Count;
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Generate_Task_Body;
------------------------------------
-- Generate_Full_Type_Declaration --
------------------------------------
procedure Generate_Full_Type_Declaration (Node : Element_Node) is
Discr_Part : constant Discriminant_Part :=
Node.Spec.As_Incomplete_Type_Decl.F_Discriminants;
Is_Tagged : constant Boolean := Node.Spec.Kind =
Ada_Incomplete_Tagged_Type_Decl;
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
MD : Markered_Data_Type;
begin
Trace (Me, "Generating full type declaration for " & Node.Spec_Name.all);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Add_Entity_To_Local_List (Node, New_Line_Counter, Level * Indent_Level);
S_Put
(Level * Indent_Level,
"type " & Node.Spec_Name.all & " ");
if not Discr_Part.Is_Null
and then Discr_Part.Kind = Ada_Known_Discriminant_Part
then
S_Put (0, Node_Image (Discr_Part) & " ");
end if;
S_Put (0, "is");
if Is_Tagged then
S_Put (0, " tagged");
end if;
New_Line_Count;
S_Put
((Level) * Indent_Level,
Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put
((Level) * Indent_Level,
"-- This section can be used for changing type completion.");
New_Line_Count;
S_Put ((Level) * Indent_Level, "--");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
-- Put bodies
if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Data.Delete (ID);
else
New_Line_Count;
S_Put
((Level) * Indent_Level + 2,
"null record;");
New_Line_Count;
New_Line_Count;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
end Generate_Full_Type_Declaration;
------------------------------
-- Add_Entity_To_Local_List --
------------------------------
procedure Add_Entity_To_Local_List
(Node : Element_Node; New_First_Line, New_First_Column : Natural)
is
Local_Entity : Entity_Stub_Mapping;
begin
Trace (Me_Mapping, "adding entry for " & Node.Spec_Name.all);
Local_Entity.Name := new String'(Node.Spec_Name.all);
Local_Entity.Line := Integer (First_Line_Number (Node.Spec));
Local_Entity.Column := Integer (First_Column_Number (Node.Spec));
Local_Entity.Stub_Body.Line := New_First_Line;
Local_Entity.Stub_Body.Column := New_First_Column;
Local_Entity.Setter := Nil_Entity_Sloc;
Local_Stub_Unit_Mapping.Entities.Append (Local_Entity);
end Add_Entity_To_Local_List;
-------------------------------------
-- Update_Local_Entity_With_Setter --
-------------------------------------
procedure Update_Local_Entity_With_Setter
(Node : Element_Node; New_First_Line, New_First_Column : Natural)
is
Cur : Entity_Stub_Mapping_List.Cursor;
Local_Entity : Entity_Stub_Mapping;
begin
Trace (Me_Mapping, "adding setter info for " & Node.Spec_Name.all);
Increase_Indent (Me_Mapping);
Local_Entity.Name := new String'(Node.Spec_Name.all);
Local_Entity.Line := Integer (First_Line_Number (Node.Spec));
Local_Entity.Column := Integer (First_Column_Number (Node.Spec));
Cur := Local_Stub_Unit_Mapping.Entities.Find (Local_Entity);
if Cur = Entity_Stub_Mapping_List.No_Element then
Trace
(Me_Mapping,
"no entity found for setter ("
& Local_Entity.Name.all
& ":"
& Trim (Natural'Image (Local_Entity.Line), Both)
& ":"
& Trim (Natural'Image (Local_Entity.Column), Both));
return;
end if;
Local_Entity := Entity_Stub_Mapping_List.Element (Cur);
Local_Entity.Setter.Line := New_First_Line;
Local_Entity.Setter.Column := New_First_Column;
Local_Stub_Unit_Mapping.Entities.Replace_Element (Cur, Local_Entity);
Decrease_Indent (Me_Mapping);
end Update_Local_Entity_With_Setter;
------------------------------------------
-- Add_Unconstrained_Type_To_Dictionary --
------------------------------------------
procedure Add_Unconstrained_Type_To_Dictionary (Elem : Subtype_Indication)
is
Encl : Ada_Node := Get_Declaration (Elem).As_Ada_Node;
Dict_Elem : Access_Dictionary_Entry;
D_Cur : Access_Dictionaries.Cursor;
begin
-- Types formal or not, declared in nested generic packages should not
-- be added to the dictionary.
while not Encl.Is_Null loop
if Encl.Kind in Ada_Generic_Package_Decl | Ada_Generic_Subp_Decl then
return;
end if;
Encl := Encl.Parent;
end loop;
Dict_Elem.Type_Decl := Get_Declaration (Elem).As_Ada_Node;
D_Cur := Dictionary.First;
while D_Cur /= Access_Dictionaries.No_Element loop
if
Access_Dictionaries.Element (D_Cur).Type_Decl = Dict_Elem.Type_Decl
then
return;
end if;
Next (D_Cur);
end loop;
Dict_Elem.Entry_Str := new String'
("type "
& Get_Access_Type_Name (Elem)
& " is access all "
& Get_Type_Image (Elem.As_Type_Expr)
& ";");
Dictionary.Include (Dict_Elem);
end Add_Unconstrained_Type_To_Dictionary;
---------------------------
-- Put_Dangling_Elements --
---------------------------
procedure Put_Dangling_Elements is
MD_Cur : Markered_Data_Maps.Cursor := Markered_Data.First;
ID : Markered_Data_Id;
MD : Markered_Data_Type;
begin
S_Put (3, "-------------------");
New_Line_Count;
S_Put (3, "-- Unused Bodies --");
New_Line_Count;
S_Put (3, "-------------------");
New_Line_Count;
New_Line_Count;
while MD_Cur /= Markered_Data_Maps.No_Element loop
ID := Markered_Data_Maps.Key (MD_Cur);
MD := Markered_Data_Maps.Element (MD_Cur);
if not (ID.Kind in Subprogram_MD | Task_MD | Entry_MD) then
goto END_DANGLING;
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
case ID.Kind is
when Subprogram_MD =>
S_Put
(Indent_Level,
"-- procedure/function "
& ID.Name.all
& " is");
when Task_MD =>
S_Put
(3,
"-- task body "
& ID.Name.all
& " is");
when Entry_MD =>
S_Put
(3,
"-- entry "
& ID.Name.all
& " when");
when others =>
null;
end case;
New_Line_Count;
Local_Stub_Unit_Mapping.D_Bodies.Append ((New_Line_Counter, 0));
S_Put
(2 * Indent_Level,
Generate_MD_Id_String (ID, Commented_Out => True));
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
Put_Lines (MD, Comment_Out => True);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put
(Indent_Level,
"-- end "
& ID.Name.all
& ";");
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
<<END_DANGLING>>
Next (MD_Cur);
end loop;
end Put_Dangling_Elements;
----------------------------------
-- Generate_Default_Setter_Spec --
----------------------------------
procedure Generate_Default_Setter_Spec (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
Suffix : constant String := Hash_Suffix (ID);
Param_List : Stubbed_Parameter_Lists.List :=
Filter_Private_Parameters (Get_Args_List (Node));
Cur : Stubbed_Parameter_Lists.Cursor;
Empty_Case : Boolean := Param_List.Is_Empty;
Abstract_Res_Profile : constant Boolean :=
not Empty_Case
and then not Param_List.Last_Element.Type_Elem.Is_Null
and then not Is_Only_Limited_Withed
(Param_List.Last_Element.Type_Elem.As_Type_Expr)
and then Is_Abstract (Param_List.Last_Element.Type_Elem.As_Type_Expr);
SP : Stubbed_Parameter;
Count : Natural;
begin
Trace (Me, "Generating default setter spec for " & Node.Spec_Name.all);
if Abstract_Res_Profile and then not Empty_Case then
-- No need to keep it in the parameters list
Param_List.Delete_Last;
end if;
Empty_Case := Param_List.Is_Empty;
-- Stub type
S_Put
(3,
"type "
& Stub_Type_Prefix
& Node.Spec_Name.all
& Suffix
& " is record");
New_Line_Count;
Cur := Param_List.First;
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
S_Put
(6,
SP.Name.all
& " : "
& SP.Type_Full_Name_Image.all
& ";");
New_Line_Count;
Next (Cur);
end loop;
New_Line_Count;
S_Put (6, Stub_Counter_Var & " : Natural := 0;");
New_Line_Count;
S_Put (3, "end record;");
New_Line_Count;
-- stub object
S_Put
(3,
Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& " : "
& Stub_Type_Prefix
& Node.Spec_Name.all
& Suffix & ";");
New_Line_Count;
-- Setter
S_Put
(3,
"procedure "
& Setter_Prefix
& Node.Spec_Name.all
& Suffix);
if not Empty_Case then
New_Line_Count;
S_Put (5, "(");
Cur := Param_List.First;
Count := 1;
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if Count = 1 then
S_Put
(0,
SP.Name.all
& " : "
& SP.Type_Full_Name_Image.all
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all);
else
S_Put
(6,
SP.Name.all
& " : "
& SP.Type_Full_Name_Image.all
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all);
end if;
if Count = Natural (Param_List.Length) then
S_Put (0, ");");
else
S_Put (0, ";");
end if;
New_Line_Count;
Next (Cur);
Count := Count + 1;
end loop;
else
S_Put (0, ";");
New_Line_Count;
end if;
Param_List.Clear;
end Generate_Default_Setter_Spec;
----------------------------------
-- Generate_Default_Setter_Body --
----------------------------------
procedure Generate_Default_Setter_Body (Node : Element_Node) is
ID : constant Markered_Data_Id := Generate_MD_Id (Node.Spec);
Suffix : constant String := Hash_Suffix (ID);
Param_List : Stubbed_Parameter_Lists.List :=
Filter_Private_Parameters (Get_Args_List (Node));
Cur : Stubbed_Parameter_Lists.Cursor;
Empty_Case : Boolean := Param_List.Is_Empty;
Abstract_Res_Profile : constant Boolean :=
not Empty_Case
and then not Param_List.Last_Element.Type_Elem.Is_Null
and then not Is_Only_Limited_Withed
(Param_List.Last_Element.Type_Elem.As_Type_Expr)
and then Is_Abstract (Param_List.Last_Element.Type_Elem.As_Type_Expr);
SP : Stubbed_Parameter;
Count : Natural;
Non_Limited_Parameters : Boolean := False;
begin
Trace (Me, "Generating default setter body for " & Node.Spec_Name.all);
if Abstract_Res_Profile and then not Empty_Case then
-- No need to keep it in the parameters list
Param_List.Delete_Last;
end if;
Empty_Case := Param_List.Is_Empty;
S_Put
(3,
"procedure "
& Setter_Prefix
& Node.Spec_Name.all
& Suffix);
if not Empty_Case then
New_Line_Count;
S_Put (5, "(");
-- params declaration
Cur := Param_List.First;
Count := 1;
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if Count = 1 then
S_Put
(0,
SP.Name.all
& " : "
& SP.Type_Full_Name_Image.all
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all);
else
S_Put
(6,
SP.Name.all
& " : "
& SP.Type_Full_Name_Image.all
& " := "
& Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all);
end if;
if Count = Natural (Param_List.Length) then
S_Put (0, ") is");
else
S_Put (0, ";");
end if;
New_Line_Count;
Next (Cur);
Count := Count + 1;
end loop;
S_Put (3, "begin");
New_Line_Count;
-- Params setting
Cur := Param_List.First;
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if not Is_Limited (SP.Type_Elem.As_Type_Expr) then
S_Put
(6,
Stub_Object_Prefix
& Node.Spec_Name.all
& Suffix
& "."
& SP.Name.all
& " := "
& SP.Name.all
& ";");
New_Line_Count;
Non_Limited_Parameters := True;
end if;
Next (Cur);
end loop;
if not Non_Limited_Parameters then
S_Put (6, "null;");
end if;
else
S_Put (1, " is");
New_Line_Count;
S_Put (3, "begin");
New_Line_Count;
S_Put (6, "null;");
New_Line_Count;
end if;
New_Line_Count;
S_Put
(3,
"end "
& Setter_Prefix
& Node.Spec_Name.all
& Suffix
& ";");
New_Line_Count;
New_Line_Count;
Param_List.Clear;
end Generate_Default_Setter_Body;
-------------------------------
-- Filter_Private_Parameters --
-------------------------------
function Filter_Private_Parameters
(Param_List : Stubbed_Parameter_Lists.List)
return Stubbed_Parameter_Lists.List
is
SP : Stubbed_Parameter;
Cur : Stubbed_Parameter_Lists.Cursor := Param_List.First;
Res : Stubbed_Parameter_Lists.List := Stubbed_Parameter_Lists.Empty_List;
begin
while Cur /= Stubbed_Parameter_Lists.No_Element loop
SP := Stubbed_Parameter_Lists.Element (Cur);
if not Is_Fully_Private (SP.Type_Elem.As_Type_Expr) then
Res.Append (SP);
end if;
Next (Cur);
end loop;
return Res;
end Filter_Private_Parameters;
------------------------
-- Generate_Stub_Data --
------------------------
procedure Generate_Stub_Data
(Stub_Data_File_Spec : String;
Stub_Data_File_Body : String;
Data : Data_Holder)
is
Node : Element_Node;
Root_Node : constant Element_Node :=
Element_Node_Trees.Element (First_Child (Data.Elem_Tree.Root));
Tmp_File_Name : constant String :=
Ada.Directories.Compose
(Utils.Environment.Tool_Temp_Dir.all, "gnattest_tmp_stub_body");
Success : Boolean;
Cur : Element_Node_Lists.Cursor;
MD_Cur : Markered_Data_Maps.Cursor;
ID : Markered_Data_Id;
MD : Markered_Data_Type;
D_Cur : Access_Dictionaries.Cursor;
begin
if Data.Flat_List.Is_Empty then
Excluded_Test_Data_Files.Include (Base_Name (Stub_Data_File_Spec));
Excluded_Test_Data_Files.Include (Base_Name (Stub_Data_File_Body));
return;
end if;
-- Spec
Gather_Markered_Data (Stub_Data_File_Spec, Markered_Subp_Data);
Trace
(Me,
"generating stub data spec for "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name);
Increase_Indent (Me);
Create (Tmp_File_Name);
Reset_Line_Counter;
Put_Import_Section (Markered_Subp_Data, Add_Pragma_05 => True);
S_Put
(0,
"package "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& " is");
New_Line_Count;
D_Cur := Dictionary.First;
while D_Cur /= Access_Dictionaries.No_Element loop
S_Put (3, Access_Dictionaries.Element (D_Cur).Entry_Str.all);
New_Line_Count;
Next (D_Cur);
end loop;
New_Line_Count;
Cur := Data.Flat_List.First;
while Cur /= Element_Node_Lists.No_Element loop
Node := Element_Node_Lists.Element (Cur);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (3, Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
ID := Generate_MD_Id (Node.Spec);
if Markered_Subp_Data.Contains (ID) then
MD := Markered_Subp_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Subp_Data.Delete (ID);
else
Generate_Default_Setter_Spec (Node);
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
Next (Cur);
end loop;
if not Markered_Subp_Data.Is_Empty then
Report_Std
(" warning: (gnattest) "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& " has dangling setter spec(s)");
S_Put (3, "----------------------");
New_Line_Count;
S_Put (3, "-- Unused Setters --");
New_Line_Count;
S_Put (3, "----------------------");
New_Line_Count;
New_Line_Count;
MD_Cur := Markered_Subp_Data.First;
while MD_Cur /= Markered_Data_Maps.No_Element loop
ID := Markered_Data_Maps.Key (MD_Cur);
MD := Markered_Data_Maps.Element (MD_Cur);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (3, Generate_MD_Id_String (ID));
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
Put_Lines (MD, Comment_Out => False);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
Next (MD_Cur);
end loop;
end if;
S_Put
(0,
"end "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& ";");
New_Line_Count;
Close_File;
Markered_Subp_Data.Clear;
-- At this point temp package is coplete and it is safe
-- to replace the old one with it.
if Is_Regular_File (Stub_Data_File_Spec) then
Delete_File (Stub_Data_File_Spec, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete " & Stub_Data_File_Spec);
end if;
end if;
Copy_File (Tmp_File_Name, Stub_Data_File_Spec, Success);
if not Success then
Cmd_Error_No_Help
("cannot copy tmp test package to " & Stub_Data_File_Spec);
end if;
Delete_File (Tmp_File_Name, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete tmp test package");
end if;
Decrease_Indent (Me);
-- Body
Gather_Markered_Data (Stub_Data_File_Body, Markered_Subp_Data);
Trace
(Me,
"generating stub data body for "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name);
Increase_Indent (Me);
Create (Tmp_File_Name);
Reset_Line_Counter;
Put_Import_Section (Markered_Subp_Data);
S_Put
(0,
"package body "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& " is");
New_Line_Count;
Cur := Data.Flat_List.First;
while Cur /= Element_Node_Lists.No_Element loop
Node := Element_Node_Lists.Element (Cur);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (3, Generate_MD_Id_String (Node.Spec));
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
Update_Local_Entity_With_Setter (Node, New_Line_Counter, 4);
ID := Generate_MD_Id (Node.Spec);
if Markered_Subp_Data.Contains (ID) then
MD := Markered_Subp_Data.Element (ID);
Put_Lines (MD, Comment_Out => False);
Markered_Subp_Data.Delete (ID);
else
Generate_Default_Setter_Body (Node);
end if;
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
Next (Cur);
end loop;
if not Markered_Subp_Data.Is_Empty then
Report_Std
(" warning: (gnattest) "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& " has dangling setter body(ies)");
S_Put (3, "----------------------");
New_Line_Count;
S_Put (3, "-- Unused Setters --");
New_Line_Count;
S_Put (3, "----------------------");
New_Line_Count;
New_Line_Count;
MD_Cur := Markered_Subp_Data.First;
while MD_Cur /= Markered_Data_Maps.No_Element loop
ID := Markered_Data_Maps.Key (MD_Cur);
MD := Markered_Data_Maps.Element (MD_Cur);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
Local_Stub_Unit_Mapping.D_Setters.Append ((New_Line_Counter, 0));
S_Put (3, Generate_MD_Id_String (ID));
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
Put_Lines (MD, Comment_Out => False);
S_Put (0, GT_Marker_Begin);
New_Line_Count;
S_Put (0, GT_Marker_End);
New_Line_Count;
New_Line_Count;
Next (MD_Cur);
end loop;
end if;
S_Put
(0,
"end "
& Root_Node.Spec_Name.all
& "."
& Stub_Data_Unit_Name
& ";");
New_Line_Count;
Close_File;
Markered_Subp_Data.Clear;
-- At this point temp package is coplete and it is safe
-- to replace the old one with it.
if Is_Regular_File (Stub_Data_File_Body) then
Delete_File (Stub_Data_File_Body, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete " & Stub_Data_File_Body);
end if;
end if;
Copy_File (Tmp_File_Name, Stub_Data_File_Body, Success);
if not Success then
Cmd_Error_No_Help ("cannot copy tmp test package to "
& Stub_Data_File_Body);
end if;
Delete_File (Tmp_File_Name, Success);
if not Success then
Cmd_Error_No_Help ("cannot delete tmp test package");
end if;
Decrease_Indent (Me);
end Generate_Stub_Data;
end Test.Stub;
|