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 | ------------------------------------------------------------------------------
-- GNAT Documentation Generation Tool --
-- --
-- Copyright (C) 2022-2023, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Libadalang.Analysis; use Libadalang.Analysis;
with Libadalang.Common; use Libadalang.Common;
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
with Langkit_Support.Text; use Langkit_Support.Text;
with VSS.Characters; use VSS.Characters;
with VSS.Characters.Latin; use VSS.Characters.Latin;
with VSS.Regular_Expressions; use VSS.Regular_Expressions;
with VSS.String_Vectors; use VSS.String_Vectors;
with VSS.Strings; use VSS.Strings;
with VSS.Strings.Character_Iterators; use VSS.Strings.Character_Iterators;
with GNATdoc.Comments.Builders.Private_Types;
with GNATdoc.Comments.Builders.Enumerations;
with GNATdoc.Comments.Builders.Generics;
with GNATdoc.Comments.Builders.Protecteds;
with GNATdoc.Comments.Builders.Records;
with GNATdoc.Comments.Builders.Subprograms;
with GNATdoc.Comments.Utilities; use GNATdoc.Comments.Utilities;
package body GNATdoc.Comments.Extractor is
use all type GNATdoc.Comments.Options.Documentation_Style;
type Section_Tag is
(Param_Tag,
Return_Tag,
Exception_Tag,
Enum_Tag,
Member_Tag,
Formal_Tag,
Private_Tag);
type Section_Tag_Flags is array (Section_Tag) of Boolean with Pack;
Ada_New_Line_Function : constant Line_Terminator_Set :=
[CR | LF | CRLF => True, others => False];
Ada_Identifier_Expression : constant Virtual_String :=
"[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*";
Ada_Character_Literal_Expression : constant Virtual_String :=
"'[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Z}\p{Cn}]'";
Ada_Optional_Separator_Expression : constant Virtual_String :=
"[\p{Zs}\p{Cf}]*";
procedure Extract_Base_Package_Decl_Documentation
(Basic_Decl_Node : Libadalang.Analysis.Basic_Decl'Class;
Base_Package_Decl_Node : Libadalang.Analysis.Base_Package_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class);
-- Common code to extract documentation for ordinary and generic package
-- declarations.
procedure Extract_Generic_Decl_Documentation
(Node : Libadalang.Analysis.Generic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class);
procedure Extract_Subprogram_Documentation
(Decl_Node : Libadalang.Analysis.Basic_Decl'Class;
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
Expr_Node : Expr'Class;
Aspects_Node : Aspect_Spec'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
with Pre =>
Spec_Node.Kind in Ada_Subp_Spec | Ada_Entry_Spec;
-- Extracts subprogram's documentation.
--
-- @param Decl_Node Whole declaration
-- @param Subp_Spec_Node Subprogram specification
-- @param Expr_Node Expression of expression function
-- @param Aspects_Node List of aspects
-- @param Options Documentataion extraction options
-- @param Documentation Structured comment to fill
procedure Extract_Entry_Body_Documentation
(Decl_Node : Libadalang.Analysis.Entry_Body'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class);
-- Extracts entry body documentation.
--
-- @param Decl_Node Whole declaration
-- @param Options Documentataion extraction options
-- @param Documentation Structured comment to fill
procedure Extract_Enumeration_Type_Documentation
(Node : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
with Pre => Node.Kind in Ada_Type_Decl
and then Node.F_Type_Def.Kind = Ada_Enum_Type_Def;
-- Extract documentation for type declaration.
procedure Extract_Record_Type_Documentation
(Node : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
with Pre =>
(Node.Kind in Ada_Type_Decl
and then Node.F_Type_Def.Kind = Ada_Record_Type_Def)
or (Node.Kind in Ada_Type_Decl
and then Node.F_Type_Def.Kind = Ada_Derived_Type_Def
and then not Node.F_Type_Def.As_Derived_Type_Def
.F_Record_Extension.Is_Null);
-- Extract documentation for record type declaration.
procedure Extract_Private_Type_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Decl : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
with Pre =>
(Decl.Kind in Ada_Type_Decl
and then Decl.As_Type_Decl.F_Type_Def.Kind = Ada_Private_Type_Def)
or else (Decl.Kind in Ada_Formal_Type_Decl
and then Decl.As_Formal_Type_Decl.F_Type_Def.Kind
= Ada_Private_Type_Def);
-- Extract documentation for private type declaration.
procedure Extract_Simple_Declaration_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
with Pre => Node.Kind in Ada_Exception_Decl
| Ada_Generic_Formal_Package
| Ada_Generic_Package_Instantiation
| Ada_Generic_Subp_Instantiation
| Ada_Number_Decl
| Ada_Object_Decl
| Ada_Package_Renaming_Decl
| Ada_Subtype_Decl
or (Node.Kind in Ada_Type_Decl
and then Node.As_Type_Decl.F_Type_Def.Kind in Ada_Array_Type_Def
| Ada_Decimal_Fixed_Point_Def
| Ada_Floating_Point_Def
| Ada_Interface_Type_Def
| Ada_Mod_Int_Type_Def
| Ada_Ordinary_Fixed_Point_Def
| Ada_Signed_Int_Type_Def
| Ada_Type_Access_Def)
or (Node.Kind in Ada_Type_Decl
and then Node.As_Type_Decl.F_Type_Def.Kind = Ada_Derived_Type_Def
and then Node.As_Type_Decl.F_Type_Def.As_Derived_Type_Def
.F_Record_Extension.Is_Null)
or (Node.Kind in Ada_Generic_Formal_Type_Decl
and then Node.As_Generic_Formal_Type_Decl.F_Decl.Kind
= Ada_Incomplete_Formal_Type_Decl)
or (Node.Kind in Ada_Generic_Formal_Type_Decl
and then Node.As_Generic_Formal_Type_Decl.F_Decl.Kind
= Ada_Formal_Type_Decl
and then Node.As_Generic_Formal_Type_Decl.F_Decl.As_Formal_Type_Decl
.F_Type_Def.Kind in Ada_Type_Access_Def
| Ada_Array_Type_Def
| Ada_Decimal_Fixed_Point_Def
| Ada_Derived_Type_Def
| Ada_Floating_Point_Def
| Ada_Formal_Discrete_Type_Def
| Ada_Interface_Type_Def
| Ada_Ordinary_Fixed_Point_Def
| Ada_Mod_Int_Type_Def
| Ada_Signed_Int_Type_Def)
or Node.Kind = Ada_Generic_Formal_Obj_Decl;
-- Extract documentation for simple declaration (declarations that doesn't
-- contains components).
procedure Extract_Single_Task_Decl_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Decl : Libadalang.Analysis.Task_Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class);
-- Extract documentation for single task declaration.
procedure Extract_Protected_Decl_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Definition : Libadalang.Analysis.Protected_Def'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class);
-- Extract documentation for protected type declaration.
procedure Extract_Protected_Body_Documentation
(Node : Libadalang.Analysis.Protected_Body'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class);
-- Extract documentation for protected body.
procedure Extract_General_Trailing_Documentation
(Decl_Node : Basic_Decl'Class;
Pattern : VSS.Regular_Expressions.Regular_Expression;
Last_Section : Section_Access;
Minimum_Indent : Langkit_Support.Slocs.Column_Number;
Sections : in out Section_Vectors.Vector;
Trailing_Section : out not null Section_Access);
-- Creates leading documetation section of the structured comment
-- and extracts leading documentation follow general rules (there are
-- few exceptions from this rules, like ordinary and generic package
-- declarations).
--
-- @param Decl_Node Declaration node
-- @param Pattern
-- Regular expression to check whenther line should be included into
-- the documentation or not.
-- @param Last_Section
-- Last section inside the declaration. If there are some comments after
-- the declaration and its indentation is equal of deeper than the value
-- of the Minimum_Indent parameter, this section is filled by these
-- comments.
-- @param Minimum_Indent Minimum indentation to fill last section.
-- @param Sections List of sections to add new section
-- @param Trailing_Section Trailing raw text.
procedure Extract_General_Leading_Trailing_Documentation
(Decl_Node : Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Last_Section : Section_Access;
Minimum_Indent : Langkit_Support.Slocs.Column_Number;
Sections : in out Section_Vectors.Vector;
Leading_Section : out not null Section_Access;
Trailing_Section : out not null Section_Access);
-- Call both Extract_General_Leading_Documentation and
-- Extract_General_Trailing_Documentation subprograms.
procedure Extract_Leading_Section
(Token_Start : Token_Reference;
Options : GNATdoc.Comments.Options.Extractor_Options;
Separator_Allowed : Boolean;
Sections : in out Section_Vectors.Vector;
Section : out not null Section_Access);
-- Creates leading documetation section of the structured comment
-- and extracts leading documentation.
--
-- @param Token_Start Start token of the declaration node.
-- @param Options Extractor options
-- @param Separator_Allowed
-- Whether empty line is allowed between line that contains Token_Start
-- and comment. It is the case for packages, tasks and protected
-- objects.
-- @param Sections List of sections to add new section
-- @param Section Created section
procedure Extract_Upper_Intermediate_Section
(Token_Start : Token_Reference;
Token_End : Token_Reference;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class;
Section : out Section_Access)
with Pre => Kind (Data (Token_Start)) in Ada_Is | Ada_With;
-- Extract documentation from the upper intermediate section: after
-- Token_Start ('is' or 'with') and before any other declarations.
procedure Fill_Code_Snippet
(Node : Ada_Node'Class;
First_Token : Token_Reference;
Last_Token : Token_Reference;
Sections : in out Section_Vectors.Vector);
-- Extract code snippet between given tokens, remove all comments from it,
-- and create code snippet section of the structured comment.
--
-- @param Node Declaration or specification node
-- @param First_Token First token of the range to be processed
-- @param Last_Token Last token of the range to be processed
-- @param Sections List of sections to append new section.
procedure Remove_Comment_Start_And_Indentation
(Sections : in out Section_Vectors.Vector;
Pattern : VSS.Regular_Expressions.Regular_Expression);
-- Postprocess extracted text, for each group of lines, separated by empty
-- line, by remove of two minus signs and common leading whitespaces. For
-- code snippet remove common leading whitespaces only.
--
-- @param Sections List of sections of the documentation
-- @param Pattern Regular expression to remove "start of comment" text
procedure Parse_Raw_Section
(Raw_Section : Section_Access;
Allowed_Tags : Section_Tag_Flags;
Sections : in out Section_Vectors.Vector;
Is_Private : in out Boolean);
-- Process raw documentation, fill sections and create description section.
--
-- @param Raw_Section Raw section to process
-- @param Allowed_Tags Set of section tags to be processed
-- @param Sections Sections of the structured comment
-- @param Is_Private Set to True when private tag found
procedure Parse_Raw_Section
(Raw_Section : Section_Access;
Allowed_Tags : Section_Tag_Flags;
Sections : in out Section_Vectors.Vector)
with Pre => not Allowed_Tags (Private_Tag);
-- Wrapper around Parse_Raw_Section when private tag is not allowed
function Is_Ada_Separator (Item : Virtual_Character) return Boolean;
-- Return True when given character is Ada's separator.
--
-- @param Item Character to be classified
-- @return Whether given character is Ada's separator or not
procedure Prepend_Documentation_Line
(Text : in out VSS.String_Vectors.Virtual_String_Vector;
Line : Langkit_Support.Text.Text_Type;
Pattern : VSS.Regular_Expressions.Regular_Expression);
-- Prepend given Line to the Text when Pattern is valid and Line match to
-- Pattern. Always prepend Line when Pattern is invalid.
-------------
-- Extract --
-------------
procedure Extract
(Node : Libadalang.Analysis.Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class) is
begin
case Node.Kind is
when Ada_Package_Decl =>
Extract_Base_Package_Decl_Documentation
(Basic_Decl_Node => Node.As_Package_Decl,
Base_Package_Decl_Node => Node.As_Package_Decl,
Options => Options,
Documentation => Documentation);
when Ada_Abstract_Subp_Decl | Ada_Subp_Decl =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Classic_Subp_Decl.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => Node.F_Aspects,
Options => Options,
Sections => Documentation.Sections);
when Ada_Expr_Function =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Base_Subp_Body.F_Subp_Spec,
Expr_Node => Node.As_Expr_Function.F_Expr,
Aspects_Node => Node.F_Aspects,
Options => Options,
Sections => Documentation.Sections);
when Ada_Null_Subp_Decl =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Base_Subp_Body.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => Node.F_Aspects,
Options => Options,
Sections => Documentation.Sections);
when Ada_Subp_Body =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Base_Subp_Body.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => Node.As_Subp_Body.F_Aspects,
Options => Options,
Sections => Documentation.Sections);
when Ada_Generic_Package_Decl | Ada_Generic_Subp_Decl =>
Extract_Generic_Decl_Documentation
(Node.As_Generic_Decl, Options, Documentation);
-- when Ada_Generic_Subp_Decl =>
-- Extract_Generic_Decl_Documentation
-- (Node.As_Generic_Subp_Decl, Options, Documentation);
when Ada_Generic_Package_Instantiation =>
Extract_Simple_Declaration_Documentation
(Node.As_Generic_Package_Instantiation,
Options,
Documentation.Sections);
when Ada_Generic_Subp_Instantiation =>
Extract_Simple_Declaration_Documentation
(Node.As_Generic_Subp_Instantiation,
Options,
Documentation.Sections);
when Ada_Package_Renaming_Decl =>
Extract_Simple_Declaration_Documentation
(Node.As_Package_Renaming_Decl,
Options,
Documentation.Sections);
when Ada_Subp_Renaming_Decl =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Subp_Renaming_Decl.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => No_Aspect_Spec,
Options => Options,
Sections => Documentation.Sections);
when Ada_Type_Decl =>
-- Print (Node);
case Node.As_Type_Decl.F_Type_Def.Kind is
when Ada_Array_Type_Def =>
Extract_Simple_Declaration_Documentation
(Node.As_Type_Decl, Options, Documentation.Sections);
when Ada_Enum_Type_Def =>
Extract_Enumeration_Type_Documentation
(Node.As_Type_Decl, Options, Documentation);
when Ada_Derived_Type_Def =>
if Node.As_Type_Decl.F_Type_Def.As_Derived_Type_Def
.F_Record_Extension.Is_Null
then
Extract_Simple_Declaration_Documentation
(Node.As_Type_Decl, Options, Documentation.Sections);
else
Extract_Record_Type_Documentation
(Node.As_Type_Decl, Options, Documentation);
end if;
when Ada_Interface_Type_Def =>
Extract_Simple_Declaration_Documentation
(Node.As_Type_Decl, Options, Documentation.Sections);
when Ada_Decimal_Fixed_Point_Def
| Ada_Floating_Point_Def
| Ada_Mod_Int_Type_Def
| Ada_Ordinary_Fixed_Point_Def
| Ada_Signed_Int_Type_Def
=>
Extract_Simple_Declaration_Documentation
(Node.As_Type_Decl, Options, Documentation.Sections);
when Ada_Record_Type_Def =>
Extract_Record_Type_Documentation
(Node.As_Type_Decl, Options, Documentation);
when Ada_Private_Type_Def =>
Extract_Private_Type_Documentation
(Node, Node.As_Type_Decl, Options, Documentation.Sections);
when Ada_Type_Access_Def =>
Extract_Simple_Declaration_Documentation
(Node.As_Type_Decl, Options, Documentation.Sections);
when Ada_Access_To_Subp_Def =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node =>
Node.As_Type_Decl.F_Type_Def
.As_Access_To_Subp_Def.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => No_Aspect_Spec,
Options => Options,
Sections => Documentation.Sections);
when others =>
raise Program_Error;
end case;
when Ada_Subtype_Decl =>
Extract_Simple_Declaration_Documentation
(Node.As_Subtype_Decl, Options, Documentation.Sections);
when Ada_Object_Decl =>
Extract_Simple_Declaration_Documentation
(Node.As_Object_Decl, Options, Documentation.Sections);
when Ada_Number_Decl =>
Extract_Simple_Declaration_Documentation
(Node.As_Number_Decl, Options, Documentation.Sections);
when Ada_Exception_Decl =>
Extract_Simple_Declaration_Documentation
(Node.As_Exception_Decl, Options, Documentation.Sections);
when Ada_Single_Task_Decl =>
Extract_Single_Task_Decl_Documentation
(Node.As_Single_Task_Decl,
Node.As_Single_Task_Decl.F_Task_Type,
Options,
Documentation);
when Ada_Task_Type_Decl =>
Extract_Single_Task_Decl_Documentation
(Node.As_Task_Type_Decl,
Node.As_Task_Type_Decl,
Options,
Documentation);
when Ada_Single_Protected_Decl =>
Extract_Protected_Decl_Documentation
(Node.As_Single_Protected_Decl,
Node.As_Single_Protected_Decl.F_Definition,
Options,
Documentation);
when Ada_Protected_Type_Decl =>
Extract_Protected_Decl_Documentation
(Node.As_Protected_Type_Decl,
Node.As_Protected_Type_Decl.F_Definition,
Options,
Documentation);
when Ada_Protected_Body =>
Extract_Protected_Body_Documentation
(Node.As_Protected_Body, Options, Documentation);
when Ada_Entry_Decl =>
Extract_Subprogram_Documentation
(Decl_Node => Node,
Spec_Node => Node.As_Entry_Decl.F_Spec,
Expr_Node => No_Expr,
Aspects_Node => No_Aspect_Spec,
Options => Options,
Sections => Documentation.Sections);
when Ada_Entry_Body =>
Extract_Entry_Body_Documentation
(Decl_Node => Node.As_Entry_Body,
Options => Options,
Documentation => Documentation);
when others =>
raise Program_Error;
end case;
end Extract;
-------------
-- Extract --
-------------
function Extract
(Node : Libadalang.Analysis.Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options)
return not null Structured_Comment_Access is
begin
return Result : constant not null Structured_Comment_Access :=
new Structured_Comment
do
Extract (Node, Options, Result.all);
end return;
end Extract;
-------------
-- Extract --
-------------
function Extract
(Node : Libadalang.Analysis.Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options)
return Structured_Comment is
begin
return Result : Structured_Comment do
Extract (Node, Options, Result);
end return;
end Extract;
---------------------------------------------
-- Extract_Base_Package_Decl_Documentation --
---------------------------------------------
procedure Extract_Base_Package_Decl_Documentation
(Basic_Decl_Node : Libadalang.Analysis.Basic_Decl'Class;
Base_Package_Decl_Node : Libadalang.Analysis.Base_Package_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class)
is
Prelude : Ada_Node_List;
Header_Section : Section_Access;
Leading_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
Intermediate_Lower_Section : Section_Access;
Last_Pragma_Or_Use : Ada_Node;
begin
-- Header section: before context clauses of compilation unit
if Basic_Decl_Node.P_Is_Compilation_Unit_Root then
Prelude := Basic_Decl_Node.P_Enclosing_Compilation_Unit.F_Prelude;
if Prelude.Sloc_Range.Start_Line = Prelude.Sloc_Range.End_Line
and Prelude.Sloc_Range.Start_Column = Prelude.Sloc_Range.End_Column
then
Prelude := No_Ada_Node_List;
end if;
if not Prelude.Is_Null then
Header_Section :=
new Section'
(Kind => Raw,
Symbol => "<<HEADER>>",
Name => <>,
Text => <>,
others => <>);
Documentation.Sections.Append (Header_Section);
-- Going from the line before the first line of prelude to find
-- an empty line and append all text till the next empty line to
-- the header section.
declare
Token : Token_Reference := Prelude.Token_Start;
Found : Boolean := False;
begin
loop
Token := Previous (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
if Found then
Prepend_Documentation_Line
(Header_Section.Text,
Text (Token),
Options.Pattern);
end if;
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
exit when Found;
Found := True;
end if;
end;
when others =>
-- No tokens of other kinds are possible.
raise Program_Error;
end case;
end loop;
end;
end if;
end if;
-- Leading section: before the package declaration and after context
-- clauses of the compilation unit
if not Basic_Decl_Node.P_Is_Compilation_Unit_Root or Prelude.Is_Null then
Extract_Leading_Section
(Basic_Decl_Node.Token_Start,
Options,
True,
Documentation.Sections,
Leading_Section);
end if;
-- Upper intermediate section: after 'is' and before any declarations.
declare
Token : Token_Reference := Base_Package_Decl_Node.Token_Start;
begin
-- Lookup 'is' in the package declaration
loop
Token := Next (Token);
exit when
Token = No_Token or else Kind (Data (Token)) = Ada_Is;
end loop;
Extract_Upper_Intermediate_Section
(Token,
Base_Package_Decl_Node.Token_End,
Options,
Documentation,
Intermediate_Upper_Section);
end;
-- Lower intermediate section: after any 'pragma' and 'use' clauses.
-- Looukp last use clause or pragma declarations at the beginning of the
-- public part of the package.
for N of Base_Package_Decl_Node.F_Public_Part.F_Decls loop
case N.Kind is
when Ada_Pragma_Node | Ada_Use_Clause =>
Last_Pragma_Or_Use := N.As_Ada_Node;
when others =>
exit;
end case;
end loop;
if not Last_Pragma_Or_Use.Is_Null then
Intermediate_Lower_Section :=
new Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE UPPER>>",
Name => <>,
Text => <>,
others => <>);
Documentation.Sections.Append (Intermediate_Lower_Section);
declare
Token : Token_Reference := Last_Pragma_Or_Use.Token_End;
Found : Boolean := False;
begin
loop
Token := Next (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
Found := True;
Append_Documentation_Line
(Intermediate_Lower_Section.Text,
Text (Token),
Options.Pattern);
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
exit when Found;
Found := True;
end if;
end;
when others =>
exit;
end case;
end loop;
end;
end if;
Fill_Code_Snippet
(Basic_Decl_Node,
Basic_Decl_Node.Token_Start,
Base_Package_Decl_Node.F_Package_Name.Token_End,
Documentation.Sections);
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section.
if not Intermediate_Upper_Section.Text.Is_Empty then
Raw_Section := Intermediate_Upper_Section;
elsif Intermediate_Lower_Section /= null
and then not Intermediate_Lower_Section.Text.Is_Empty
then
Raw_Section := Intermediate_Lower_Section;
elsif Leading_Section /= null
and then not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
elsif Header_Section /= null
and then not Header_Section.Text.Is_Empty
then
Raw_Section := Header_Section;
end if;
Parse_Raw_Section
(Raw_Section,
[Private_Tag => True,
Formal_Tag => Basic_Decl_Node.Kind in Ada_Generic_Decl,
others => False],
Documentation.Sections,
Documentation.Is_Private);
end;
end Extract_Base_Package_Decl_Documentation;
--------------------------------------
-- Extract_Entry_Body_Documentation --
--------------------------------------
procedure Extract_Entry_Body_Documentation
(Decl_Node : Libadalang.Analysis.Entry_Body'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
is
-- entry Name
-- (for Index use Index_Type)
-- (Parameter : Parameter_Type)
-- -- UPPER INTERMEDIATE SECTION
-- with Aspect
-- when Barrier
-- is
-- -- LOWER INTERMEDIATE SECTION
--------------------------------
-- Intermediate_Section_Range --
--------------------------------
procedure Intermediate_Section_Range
(Decl_Node : Libadalang.Analysis.Entry_Body'Class;
Name_Node : Defining_Name'Class;
Family_Node : Entry_Index_Spec'Class;
Params_Node : Params'Class;
Aspects_Node : Aspect_Spec'Class;
Barrier_Node : Expr'Class;
Upper_Start_Line : out Line_Number;
Upper_End_Line : out Line_Number;
Lower_Start_Line : out Line_Number;
Lower_End_Line : out Line_Number);
-- Range of the "intermediate" section for subprogram.
--------------------------------
-- Intermediate_Section_Range --
--------------------------------
procedure Intermediate_Section_Range
(Decl_Node : Libadalang.Analysis.Entry_Body'Class;
Name_Node : Defining_Name'Class;
Family_Node : Entry_Index_Spec'Class;
Params_Node : Params'Class;
Aspects_Node : Aspect_Spec'Class;
Barrier_Node : Expr'Class;
Upper_Start_Line : out Line_Number;
Upper_End_Line : out Line_Number;
Lower_Start_Line : out Line_Number;
Lower_End_Line : out Line_Number)
is
begin
if Params_Node /= No_Params then
-- For entry body with parameters, upper intermediate section
-- starts after the parameters.
Upper_Start_Line := Params_Node.Sloc_Range.End_Line + 1;
elsif not Family_Node.Is_Null then
-- For entry family body without parameters, upper intermediate
-- section starts after the entry family index declaration.
Upper_Start_Line := Family_Node.Sloc_Range.End_Line + 1;
else
-- For entry without family index and parameters, upper
-- intermediate section starts after the entry defining name.
Upper_Start_Line := Name_Node.Sloc_Range.End_Line + 1;
end if;
if not Aspects_Node.Is_Null then
-- Aspects declaration ends upper intermediate section.
Upper_End_Line := Aspects_Node.Sloc_Range.Start_Line - 1;
else
-- Barrier condition is always present and ends upper
-- intermediate section.
Upper_End_Line := Barrier_Node.Sloc_Range.Start_Line - 1;
end if;
Lower_Start_Line := Barrier_Node.Sloc_Range.End_Line + 1;
Lower_End_Line := Decl_Node.Sloc_Range.End_Line;
end Intermediate_Section_Range;
Name_Node : constant Defining_Name := Decl_Node.F_Entry_Name;
Family_Node : constant Entry_Index_Spec'Class :=
Decl_Node.F_Index_Spec;
Params_Node : constant Params'Class := Decl_Node.F_Params.F_Params;
Aspects_Node : constant Aspect_Spec'Class := Decl_Node.F_Aspects;
Barrier_Node : constant Expr'Class := Decl_Node.F_Barrier;
Leading_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
Intermediate_Lower_Section : Section_Access;
Trailing_Section : Section_Access;
Last_Section : Section_Access;
Minimum_Indent : Column_Number;
Components_Builder :
GNATdoc.Comments.Builders.Subprograms.Subprogram_Components_Builder;
begin
-- Create intermediate "raw" sections to collect documentation of
-- the entry body, exact range is used to fill comments after the end
-- of the subprogram specification and before the name of the first
-- aspect association, thus, location of the "when" keyword is not
-- significant.
Intermediate_Upper_Section :=
new Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE UPPER>>",
Name => <>,
Text => <>,
others => <>);
Intermediate_Lower_Section :=
new Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE LOWER>>",
Name => <>,
Text => <>,
others => <>);
Intermediate_Section_Range
(Decl_Node,
Name_Node,
Family_Node,
Params_Node,
Aspects_Node,
Barrier_Node,
Intermediate_Upper_Section.Exact_Start_Line,
Intermediate_Upper_Section.Exact_End_Line,
Intermediate_Lower_Section.Exact_Start_Line,
Intermediate_Lower_Section.Exact_End_Line);
Documentation.Sections.Append (Intermediate_Upper_Section);
Documentation.Sections.Append (Intermediate_Lower_Section);
-- Create sections for family index and parameters.
Components_Builder.Build
(Sections => Documentation.Sections'Unchecked_Access,
Options => Options,
Node => Decl_Node,
Spec_Node => No_Base_Subp_Spec,
Name_Node => Name_Node,
Family_Node => Family_Node,
Params_Node => Params_Node,
Returns_Node => No_Type_Expr,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent);
Extract_General_Leading_Trailing_Documentation
(Decl_Node => Decl_Node,
Options => Options,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent,
Sections => Documentation.Sections,
Leading_Section => Leading_Section,
Trailing_Section => Trailing_Section);
-- Extract code snippet of declaration and remove all comments from
-- it.
declare
Last_Token : Token_Reference :=
(if Aspects_Node.Is_Null
then Barrier_Node.Token_Start
else Aspects_Node.Token_Start);
With_Or_When_Found : Boolean := not Aspects_Node.Is_Null;
-- First token of the aspects specification is 'with' keyword, while
-- first token of the barrier expression is expression itself.
begin
-- Move to the token before the 'with'/'when' keyword.
loop
Last_Token := Previous (Last_Token);
case Kind (Data (Last_Token)) is
when Ada_When =>
With_Or_When_Found := True;
when Ada_Whitespace | Ada_Comment =>
null;
when others =>
exit when With_Or_When_Found;
raise Program_Error;
end case;
end loop;
Fill_Code_Snippet
(Decl_Node,
Decl_Node.Token_Start,
Last_Token,
Documentation.Sections);
end;
-- Postprocess extracted text, for each group of lines, separated
-- by empty line by remove of two minus signs and common leading
-- whitespaces
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
-- Process raw documentation for subprogram, fill sections and create
-- description section.
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Intermediate_Upper_Section.Text.Is_Empty then
Raw_Section := Intermediate_Upper_Section;
elsif not Intermediate_Lower_Section.Text.Is_Empty then
Raw_Section := Intermediate_Lower_Section;
elsif not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback then
if Intermediate_Upper_Section.Text.Is_Empty then
Raw_Section := Intermediate_Upper_Section;
elsif not Intermediate_Lower_Section.Text.Is_Empty then
Raw_Section := Intermediate_Lower_Section;
elsif not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
end if;
end if;
end case;
Parse_Raw_Section
(Raw_Section,
[Param_Tag | Return_Tag | Exception_Tag => True,
others => False],
Documentation.Sections);
end;
end Extract_Entry_Body_Documentation;
--------------------------------------------
-- Extract_Enumeration_Type_Documentation --
--------------------------------------------
procedure Extract_Enumeration_Type_Documentation
(Node : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
is
Enum_Node : constant Enum_Type_Def'Class :=
Node.F_Type_Def.As_Enum_Type_Def;
Last_Section : Section_Access;
Minimum_Indent : Column_Number;
Leading_Section : Section_Access;
Trailing_Section : Section_Access;
Component_Builder :
GNATdoc.Comments.Builders.Enumerations.Enumeration_Components_Builder;
begin
Component_Builder.Build
(Documentation.Sections'Unchecked_Access,
Options,
Node,
Enum_Node,
Last_Section,
Minimum_Indent);
Extract_General_Leading_Trailing_Documentation
(Decl_Node => Node,
Options => Options,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent,
Sections => Documentation.Sections,
Leading_Section => Leading_Section,
Trailing_Section => Trailing_Section);
Fill_Code_Snippet
(Node, Node.Token_Start, Node.Token_End, Documentation.Sections);
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback
and not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
end if;
end case;
Parse_Raw_Section
(Raw_Section,
[Enum_Tag => True, others => False],
Documentation.Sections);
end;
end Extract_Enumeration_Type_Documentation;
----------------------------
-- Extract_Formal_Section --
----------------------------
function Extract_Formal_Section
(Documentation : Structured_Comment;
Name : Libadalang.Analysis.Defining_Name'Class)
return Structured_Comment
is
Symbol : constant VSS.Strings.Virtual_String := To_Symbol (Name);
begin
return Result : Structured_Comment do
for Section of Documentation.Sections loop
if Section.Kind = Formal and Section.Symbol = Symbol then
Result.Sections := Clone (Section.Sections);
exit;
end if;
end loop;
end return;
end Extract_Formal_Section;
----------------------------------------------------
-- Extract_General_Leading_Trailing_Documentation --
----------------------------------------------------
procedure Extract_General_Leading_Trailing_Documentation
(Decl_Node : Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Last_Section : Section_Access;
Minimum_Indent : Langkit_Support.Slocs.Column_Number;
Sections : in out Section_Vectors.Vector;
Leading_Section : out not null Section_Access;
Trailing_Section : out not null Section_Access) is
begin
Extract_Leading_Section
(Decl_Node.Token_Start, Options, False, Sections, Leading_Section);
Extract_General_Trailing_Documentation
(Decl_Node,
Options.Pattern,
Last_Section,
Minimum_Indent,
Sections,
Trailing_Section);
end Extract_General_Leading_Trailing_Documentation;
--------------------------------------------
-- Extract_General_Trailing_Documentation --
--------------------------------------------
procedure Extract_General_Trailing_Documentation
(Decl_Node : Basic_Decl'Class;
Pattern : VSS.Regular_Expressions.Regular_Expression;
Last_Section : Section_Access;
Minimum_Indent : Langkit_Support.Slocs.Column_Number;
Sections : in out Section_Vectors.Vector;
Trailing_Section : out not null Section_Access) is
begin
-- Create and add trailing section.
Trailing_Section :=
new Section'
(Kind => Raw,
Symbol => "<<TRAILING>>",
Name => <>,
Text => <>,
others => <>);
Sections.Append (Trailing_Section);
-- Process tokens after the declaration node.
declare
Current_Node : Ada_Node := Decl_Node.As_Ada_Node;
Next_Node : Ada_Node;
Token : Token_Reference;
In_Last : Boolean := Last_Section /= null;
begin
-- Skip till the last sibling not separated from the given
-- declaration node by the empty line. It is case of pragmas
-- and representation clauses after declaration but before
-- documentation comments.
loop
Next_Node := Current_Node.Next_Sibling;
exit when
Next_Node.Is_Null
or else Current_Node.Sloc_Range.End_Line
/= Next_Node.Sloc_Range.Start_Line - 1;
Current_Node := Next_Node;
end loop;
Token := Current_Node.Token_End;
loop
Token := Next (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
if In_Last then
if Sloc_Range (Data (Token)).Start_Column
>= Minimum_Indent
then
Append_Documentation_Line
(Last_Section.Text, Text (Token), Pattern);
goto Done;
else
In_Last := False;
end if;
end if;
Append_Documentation_Line
(Trailing_Section.Text, Text (Token), Pattern);
<<Done>>
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
exit when Location.End_Line - Location.Start_Line > 1;
end;
when others =>
exit;
end case;
end loop;
end;
end Extract_General_Trailing_Documentation;
----------------------------------------
-- Extract_Generic_Decl_Documentation --
----------------------------------------
procedure Extract_Generic_Decl_Documentation
(Node : Libadalang.Analysis.Generic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
is
function Lookup_Formal_Section
(Name : Defining_Name'Class) return not null Section_Access;
---------------------------
-- Lookup_Formal_Section --
---------------------------
function Lookup_Formal_Section
(Name : Defining_Name'Class) return not null Section_Access
is
Symbol : constant VSS.Strings.Virtual_String :=
GNATdoc.Comments.Utilities.To_Symbol (Name);
begin
for Section of Documentation.Sections loop
if Section.Kind = Formal and Section.Symbol = Symbol then
return Section;
end if;
end loop;
raise Program_Error;
end Lookup_Formal_Section;
Component_Builder :
GNATdoc.Comments.Builders.Generics.Generic_Components_Builder;
Decl : constant Basic_Decl'Class :=
(case Node.Kind is
when Ada_Generic_Package_Decl =>
Node.As_Generic_Package_Decl.F_Package_Decl,
when Ada_Generic_Subp_Decl =>
Node.As_Generic_Subp_Decl.F_Subp_Decl,
when others => raise Program_Error);
begin
Component_Builder.Build
(Documentation.Sections'Unchecked_Access,
Options,
Node,
Node.F_Formal_Part,
Decl);
case Node.Kind is
when Ada_Generic_Package_Decl =>
Extract_Base_Package_Decl_Documentation
(Node,
Node.As_Generic_Package_Decl.F_Package_Decl,
Options,
Documentation);
when Ada_Generic_Subp_Decl =>
Extract_Subprogram_Documentation
(Decl.As_Generic_Subp_Internal,
Decl.As_Generic_Subp_Internal.F_Subp_Spec,
No_Expr,
No_Aspect_Spec,
Options,
Documentation.Sections);
when others =>
raise Program_Error;
end case;
for Item of Node.F_Formal_Part.F_Decls loop
case Item.Kind is
when Ada_Generic_Formal_Type_Decl =>
case Item.As_Generic_Formal_Type_Decl.F_Decl.Kind is
when Ada_Incomplete_Formal_Type_Decl =>
declare
Formal_Name : constant Defining_Name :=
Item.As_Generic_Formal_Type_Decl.F_Decl
.As_Incomplete_Formal_Type_Decl.F_Name;
begin
Extract_Simple_Declaration_Documentation
(Item.As_Generic_Formal_Type_Decl,
Options,
Lookup_Formal_Section (Formal_Name).Sections);
end;
when Ada_Formal_Type_Decl =>
declare
Type_Decl : constant Formal_Type_Decl :=
Item.As_Generic_Formal_Type_Decl.F_Decl
.As_Formal_Type_Decl;
Formal_Type_Def : constant Type_Def :=
Type_Decl.F_Type_Def;
Formal_Name : constant Defining_Name :=
Type_Decl.F_Name;
begin
case Formal_Type_Def.Kind is
when Ada_Private_Type_Def =>
Extract_Private_Type_Documentation
(Item.As_Generic_Formal_Type_Decl,
Type_Decl,
Options,
Lookup_Formal_Section (Formal_Name).Sections);
when Ada_Type_Access_Def
| Ada_Array_Type_Def
| Ada_Decimal_Fixed_Point_Def
| Ada_Derived_Type_Def
| Ada_Floating_Point_Def
| Ada_Formal_Discrete_Type_Def
| Ada_Interface_Type_Def
| Ada_Mod_Int_Type_Def
| Ada_Ordinary_Fixed_Point_Def
| Ada_Signed_Int_Type_Def
=>
Extract_Simple_Declaration_Documentation
(Item.As_Generic_Formal_Type_Decl,
Options,
Lookup_Formal_Section (Formal_Name).Sections);
when Ada_Access_To_Subp_Def =>
Extract_Subprogram_Documentation
(Decl_Node =>
Item.As_Generic_Formal_Type_Decl,
Spec_Node =>
Formal_Type_Def.As_Access_To_Subp_Def
.F_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => No_Aspect_Spec,
Options => Options,
Sections =>
Lookup_Formal_Section
(Formal_Name).Sections);
when others =>
raise Program_Error;
end case;
end;
when others =>
raise Program_Error;
end case;
when Ada_Generic_Formal_Subp_Decl =>
declare
Subp_Decl : constant Concrete_Formal_Subp_Decl :=
Item.As_Generic_Formal_Subp_Decl.F_Decl
.As_Concrete_Formal_Subp_Decl;
Formal_Subp_Spec : constant Subp_Spec :=
Subp_Decl.F_Subp_Spec;
Formal_Name : constant Defining_Name :=
Formal_Subp_Spec.F_Subp_Name;
begin
Extract_Subprogram_Documentation
(Decl_Node => Item.As_Generic_Formal_Subp_Decl,
Spec_Node => Formal_Subp_Spec,
Expr_Node => No_Expr,
Aspects_Node => No_Aspect_Spec,
Options => Options,
Sections =>
Lookup_Formal_Section (Formal_Name).Sections);
end;
when Ada_Generic_Formal_Obj_Decl =>
declare
Ids : constant Defining_Name_List :=
Item.As_Generic_Formal_Obj_Decl.F_Decl
.As_Object_Decl.F_Ids;
begin
for Id of Ids loop
Extract_Simple_Declaration_Documentation
(Item.As_Generic_Formal_Obj_Decl,
Options,
Lookup_Formal_Section (Id).Sections);
end loop;
end;
when Ada_Generic_Formal_Package =>
Extract_Simple_Declaration_Documentation
(Item.As_Generic_Formal_Package,
Options,
Lookup_Formal_Section
(Item.As_Generic_Formal_Package.F_Decl
.As_Generic_Package_Instantiation.F_Name).Sections);
when Ada_Pragma_Node =>
-- Nothing to do for pragmas.
null;
when others =>
raise Program_Error;
end case;
end loop;
end Extract_Generic_Decl_Documentation;
-----------------------------
-- Extract_Leading_Section --
-----------------------------
procedure Extract_Leading_Section
(Token_Start : Token_Reference;
Options : GNATdoc.Comments.Options.Extractor_Options;
Separator_Allowed : Boolean;
Sections : in out Section_Vectors.Vector;
Section : out not null Section_Access) is
begin
-- Create and add leading section
Section :=
new GNATdoc.Comments.Section'
(Kind => Raw,
Symbol => "<<LEADING>>",
Name => <>,
Text => <>,
others => <>);
Sections.Append (Section);
-- Process tokens before the start token.
declare
Token : Token_Reference := Token_Start;
Found : Boolean := False;
-- Separated : Boolean := False;
begin
loop
Token := Previous (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
Found := True;
Prepend_Documentation_Line
(Section.Text, Text (Token), Options.Pattern);
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
if not Separator_Allowed then
exit;
else
exit when Found;
Found := True;
end if;
end if;
end;
when others =>
-- Leading section must be separated from the context
-- clauses by the empty line, thus any other tokens
-- cleanup accumulated text.
if Separator_Allowed then
Section.Text.Clear;
end if;
exit;
end case;
end loop;
end;
end Extract_Leading_Section;
----------------------------------------
-- Extract_Private_Type_Documentation --
----------------------------------------
procedure Extract_Private_Type_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Decl : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
is
Last_Section : Section_Access;
Leading_Section : Section_Access;
Trailing_Section : Section_Access;
Component_Builder :
GNATdoc.Comments.Builders.Private_Types.Private_Type_Builder;
Minimum_Indent : Column_Number := 0;
begin
Component_Builder.Build
(Sections'Unchecked_Access,
Options,
Decl,
Last_Section,
Minimum_Indent);
Extract_General_Leading_Trailing_Documentation
(Decl_Node => Node,
Options => Options,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent,
Sections => Sections,
Leading_Section => Leading_Section,
Trailing_Section => Trailing_Section);
Fill_Code_Snippet (Node, Node.Token_Start, Node.Token_End, Sections);
Remove_Comment_Start_And_Indentation (Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback
and not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
end if;
end case;
Parse_Raw_Section
(Raw_Section,
[Member_Tag => True, others => False],
Sections);
end;
end Extract_Private_Type_Documentation;
------------------------------------------
-- Extract_Protected_Body_Documentation --
------------------------------------------
procedure Extract_Protected_Body_Documentation
(Node : Libadalang.Analysis.Protected_Body'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class)
is
Is_Token : Token_Reference :=
(if Node.F_Aspects.Is_Null
then Node.F_Name.Token_End else Node.F_Aspects.Token_End);
Leading_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
begin
Extract_Leading_Section
(Node.Token_Start,
Options,
True,
Documentation.Sections,
Leading_Section);
-- Lookup for 'is' token that begins protected body.
loop
Is_Token := Next (Is_Token);
exit when Is_Token = No_Token;
case Kind (Data (Is_Token)) is
when Ada_Whitespace | Ada_Comment =>
null;
when Ada_Is =>
exit;
when others =>
raise Program_Error;
end case;
end loop;
Extract_Upper_Intermediate_Section
(Is_Token,
Node.Token_End,
Options,
Documentation,
Intermediate_Upper_Section);
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section.
if Intermediate_Upper_Section /= null
and then not Intermediate_Upper_Section.Text.Is_Empty
then
Raw_Section := Intermediate_Upper_Section;
elsif not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
end if;
Parse_Raw_Section
(Raw_Section,
[Private_Tag => True,
Member_Tag => True,
others => False],
Documentation.Sections,
Documentation.Is_Private);
end;
end Extract_Protected_Body_Documentation;
------------------------------------------
-- Extract_Protected_Decl_Documentation --
------------------------------------------
procedure Extract_Protected_Decl_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Definition : Libadalang.Analysis.Protected_Def'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class)
is
Is_Or_With_Token : Token_Reference;
Leading_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
Component_Builder :
GNATdoc.Comments.Builders.Protecteds.Protected_Components_Builder;
begin
Component_Builder.Build
(Documentation.Sections'Unchecked_Access, Options, Node);
Extract_Leading_Section
(Node.Token_Start,
Options,
True,
Documentation.Sections,
Leading_Section);
-- Lookup for 'is' token that begins protected definition, or 'with'
-- token that ends interface part.
Is_Or_With_Token := Definition.Token_Start;
loop
Is_Or_With_Token := Previous (Is_Or_With_Token);
exit when Is_Or_With_Token = No_Token;
case Kind (Data (Is_Or_With_Token)) is
when Ada_Whitespace | Ada_Comment =>
null;
when Ada_Is | Ada_With =>
exit;
when others =>
raise Program_Error;
end case;
end loop;
Extract_Upper_Intermediate_Section
(Is_Or_With_Token,
Definition.Token_End,
Options,
Documentation,
Intermediate_Upper_Section);
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section.
if Intermediate_Upper_Section /= null
and then not Intermediate_Upper_Section.Text.Is_Empty
then
Raw_Section := Intermediate_Upper_Section;
elsif not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
end if;
Parse_Raw_Section
(Raw_Section,
[Private_Tag => True,
Member_Tag => True,
others => False],
Documentation.Sections,
Documentation.Is_Private);
end;
end Extract_Protected_Decl_Documentation;
---------------------------------------
-- Extract_Record_Type_Documentation --
---------------------------------------
procedure Extract_Record_Type_Documentation
(Node : Libadalang.Analysis.Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : out Structured_Comment'Class)
is
Last_Section : Section_Access;
Minimum_Indent : Column_Number;
Leading_Section : Section_Access;
Trailing_Section : Section_Access;
Component_Builder :
GNATdoc.Comments.Builders.Records.Record_Components_Builder;
begin
Component_Builder.Build
(Documentation.Sections'Unchecked_Access,
Options,
Node,
Last_Section,
Minimum_Indent);
Extract_General_Leading_Trailing_Documentation
(Decl_Node => Node,
Options => Options,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent,
Sections => Documentation.Sections,
Leading_Section => Leading_Section,
Trailing_Section => Trailing_Section);
Fill_Code_Snippet
(Node,
Node.Token_Start,
Node.F_Type_Def.Token_End,
Documentation.Sections);
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback
and not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
end if;
end case;
Parse_Raw_Section
(Raw_Section,
[Member_Tag => True, others => False],
Documentation.Sections);
end;
end Extract_Record_Type_Documentation;
----------------------------------------------
-- Extract_Simple_Declaration_Documentation --
----------------------------------------------
procedure Extract_Simple_Declaration_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
is
Leading_Section : Section_Access;
Trailing_Section : Section_Access;
begin
Extract_General_Leading_Trailing_Documentation
(Decl_Node => Node,
Options => Options,
Last_Section => null,
Minimum_Indent => 0,
Sections => Sections,
Leading_Section => Leading_Section,
Trailing_Section => Trailing_Section);
Fill_Code_Snippet (Node, Node.Token_Start, Node.Token_End, Sections);
Remove_Comment_Start_And_Indentation (Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Trailing_Section.Text.Is_Empty then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback
and not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
end if;
end case;
Parse_Raw_Section (Raw_Section, [others => False], Sections);
end;
end Extract_Simple_Declaration_Documentation;
--------------------------------------------
-- Extract_Single_Task_Decl_Documentation --
--------------------------------------------
procedure Extract_Single_Task_Decl_Documentation
(Node : Libadalang.Analysis.Basic_Decl'Class;
Decl : Libadalang.Analysis.Task_Type_Decl'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class)
is
Definition : constant
Libadalang.Analysis.Task_Def'Class := Decl.F_Definition;
Is_Or_With_Token : Token_Reference;
Leading_Section : Section_Access;
Trailing_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
begin
Extract_Leading_Section
(Node.Token_Start,
Options,
True,
Documentation.Sections,
Leading_Section);
if Definition.Is_Null then
-- It is the case of the entry-less and definition-less task
-- declaration. Documentation may be provided by the comment
-- immidiately below task declaration. Retreive it into the
-- tailing section.
Extract_General_Trailing_Documentation
(Node,
Options.Pattern,
null,
0,
Documentation.Sections,
Trailing_Section);
else
-- Overwise, documentation may be provided inside task definition
-- before the first entry.
-- Lookup for 'is' token that begins task definition, or 'with'
-- token that ends interface part.
Is_Or_With_Token := Definition.Token_Start;
if Definition.F_Interfaces.Children_Count /= 0 then
Is_Or_With_Token := Definition.F_Interfaces.Token_End;
loop
Is_Or_With_Token := Next (Is_Or_With_Token);
exit when Is_Or_With_Token = No_Token;
case Kind (Data (Is_Or_With_Token)) is
when Ada_Whitespace =>
null;
when Ada_With =>
exit;
when others =>
raise Program_Error;
end case;
end loop;
end if;
Extract_Upper_Intermediate_Section
(Is_Or_With_Token,
Definition.Token_End,
Options,
Documentation,
Intermediate_Upper_Section);
end if;
Remove_Comment_Start_And_Indentation
(Documentation.Sections, Options.Pattern);
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section.
if Trailing_Section /= null
and then not Trailing_Section.Text.Is_Empty
then
-- Trailing section is present in the corner case only, and
-- preferable section in this case.
Raw_Section := Trailing_Section;
elsif Intermediate_Upper_Section /= null
and then not Intermediate_Upper_Section.Text.Is_Empty
then
Raw_Section := Intermediate_Upper_Section;
elsif not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
end if;
Parse_Raw_Section
(Raw_Section,
[Private_Tag => True,
Member_Tag => True,
others => False],
Documentation.Sections,
Documentation.Is_Private);
end;
end Extract_Single_Task_Decl_Documentation;
--------------------------------------
-- Extract_Subprogram_Documentation --
--------------------------------------
procedure Extract_Subprogram_Documentation
(Decl_Node : Libadalang.Analysis.Basic_Decl'Class;
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
Expr_Node : Expr'Class;
Aspects_Node : Aspect_Spec'Class;
Options : GNATdoc.Comments.Options.Extractor_Options;
Sections : in out Section_Vectors.Vector)
is
--------------------------------
-- Intermediate_Section_Range --
--------------------------------
procedure Intermediate_Section_Range
(Spec_Node : Base_Subp_Spec'Class;
Name_Node : Defining_Name'Class;
Params_Node : Params'Class;
Returns_Node : Type_Expr'Class;
Expr_Node : Expr'Class;
Aspects_Node : Aspect_Spec'Class;
Upper_Start_Line : out Line_Number;
Upper_End_Line : out Line_Number;
Lower_Start_Line : out Line_Number;
Lower_End_Line : out Line_Number);
-- Range of the "intermediate" section for subprogram.
--------------------------------
-- Intermediate_Section_Range --
--------------------------------
procedure Intermediate_Section_Range
(Spec_Node : Base_Subp_Spec'Class;
Name_Node : Defining_Name'Class;
Params_Node : Params'Class;
Returns_Node : Type_Expr'Class;
Expr_Node : Expr'Class;
Aspects_Node : Aspect_Spec'Class;
Upper_Start_Line : out Line_Number;
Upper_End_Line : out Line_Number;
Lower_Start_Line : out Line_Number;
Lower_End_Line : out Line_Number) is
begin
if Returns_Node /= No_Type_Expr then
-- For any functions, intermediate section starts after the
-- return type of the function.
Upper_Start_Line := Returns_Node.Sloc_Range.End_Line + 1;
elsif Params_Node /= No_Params then
-- For procedures with parameters, intermediate section starts
-- after the parameters.
Upper_Start_Line := Params_Node.Sloc_Range.End_Line + 1;
elsif not Name_Node.Is_Null then
-- For parameterless procedures, intermadiate section starts
-- after the procedure's name identifier.
Upper_Start_Line := Name_Node.Sloc_Range.Start_Line;
else
-- For access to subprogram, intermediate section starts after
-- the beginning of declaration.
Upper_Start_Line := Spec_Node.Sloc_Range.Start_Line + 1;
end if;
if Aspects_Node /= No_Aspect_Spec then
-- When subprogram has aspects, intermediate section ends before
-- the first aspect.
Upper_End_Line :=
Aspects_Node.F_Aspect_Assocs.First_Child.Sloc_Range.Start_Line
- 1;
else
Upper_End_Line := 0;
end if;
if Expr_Node /= No_Expr then
-- When function has expression, initialize lower intermediate
-- section to be text between expression function and aspects.
Lower_Start_Line := Expr_Node.Sloc_Range.End_Line + 1;
Lower_End_Line := Upper_End_Line;
-- ... and limit upper section till expression.
Upper_End_Line := Expr_Node.Sloc_Range.Start_Line - 1;
else
Lower_Start_Line := 0;
Lower_End_Line := 0;
end if;
end Intermediate_Section_Range;
Name_Node : constant Defining_Name :=
(case Spec_Node.Kind is
when Ada_Subp_Spec => Spec_Node.As_Subp_Spec.F_Subp_Name,
when Ada_Entry_Spec => Spec_Node.As_Entry_Spec.F_Entry_Name,
when others => raise Program_Error);
Params_Node : constant Params'Class :=
(case Spec_Node.Kind is
when Ada_Subp_Spec => Spec_Node.As_Subp_Spec.F_Subp_Params,
when Ada_Entry_Spec => Spec_Node.As_Entry_Spec.F_Entry_Params,
when others => raise Program_Error);
Returns_Node : constant Type_Expr'Class :=
(case Spec_Node.Kind is
when Ada_Subp_Spec => Spec_Node.As_Subp_Spec.F_Subp_Returns,
when Ada_Entry_Spec => No_Type_Expr,
when others => raise Program_Error);
Leading_Section : Section_Access;
Intermediate_Upper_Section : Section_Access;
Intermediate_Lower_Section : Section_Access;
Declarative_Section : Section_Access;
Trailing_Section : Section_Access;
Last_Section : Section_Access;
Minimum_Indent : Column_Number;
Components_Builder :
GNATdoc.Comments.Builders.Subprograms.Subprogram_Components_Builder;
begin
-- Create "raw" section to collect all documentation for subprogram,
-- exact range is used to fill comments after the end of the
-- subprogram specification and before the name of the first aspect
-- association, thus, location of the "when" keyword is not
-- significant.
Intermediate_Upper_Section :=
new Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE UPPER>>",
Name => <>,
Text => <>,
others => <>);
Intermediate_Lower_Section :=
new Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE LOWER>>",
Name => <>,
Text => <>,
others => <>);
Intermediate_Section_Range
(Spec_Node,
Name_Node,
Params_Node,
Returns_Node,
Expr_Node,
Aspects_Node,
Intermediate_Upper_Section.Exact_Start_Line,
Intermediate_Upper_Section.Exact_End_Line,
Intermediate_Lower_Section.Exact_Start_Line,
Intermediate_Lower_Section.Exact_End_Line);
Sections.Append (Intermediate_Upper_Section);
Sections.Append (Intermediate_Lower_Section);
-- Create sections for parameters and return value.
Components_Builder.Build
(Sections => Sections'Unchecked_Access,
Options => Options,
Node => Decl_Node,
Spec_Node => Spec_Node,
Name_Node => Name_Node,
Family_Node => Libadalang.Analysis.No_Entry_Index_Spec,
Params_Node => Params_Node,
Returns_Node => Returns_Node,
Last_Section => Last_Section,
Minimum_Indent => Minimum_Indent);
Extract_Leading_Section
(Decl_Node.Token_Start, Options, False, Sections, Leading_Section);
if Decl_Node.Kind = Ada_Subp_Body then
-- Extract comments before and after 'is' keyword.
Declarative_Section :=
new Section'
(Kind => Raw,
Symbol => "<<DECLARATIVE>>",
Name => <>,
Text => <>,
others => <>);
Sections.Append (Declarative_Section);
declare
Token : Token_Reference :=
Decl_Node.As_Subp_Body.F_Decls.Token_Start;
Reset : Boolean := False;
begin
-- Process comments on top of declarative section.
loop
Token := Previous (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
if Reset then
Reset := False;
Declarative_Section.Text.Clear;
end if;
Prepend_Documentation_Line
(Declarative_Section.Text,
Text (Token),
Options.Pattern);
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
Reset := True;
end if;
end;
when others =>
exit;
end case;
end loop;
-- Process lower intermediate section.
Reset := False;
loop
Token := Previous (Token);
exit when Token = No_Token;
case Kind (Data (Token)) is
when Ada_Comment =>
if Reset then
Reset := False;
Intermediate_Lower_Section.Text.Clear;
end if;
Prepend_Documentation_Line
(Intermediate_Lower_Section.Text,
Text (Token),
Options.Pattern);
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
-- exit;
Reset := True;
end if;
end;
when others =>
exit;
end case;
end loop;
end;
else
-- Extract comments after the subprogram declaration.
Extract_General_Trailing_Documentation
(Decl_Node,
Options.Pattern,
Last_Section,
Minimum_Indent,
Sections,
Trailing_Section);
end if;
-- Extract code snippet of declaration and remove all comments from
-- it.
if Decl_Node.Kind in Ada_Type_Decl then
-- Access to subprogram type
Fill_Code_Snippet
(Decl_Node, Decl_Node.Token_Start, Decl_Node.Token_End, Sections);
elsif Decl_Node.Kind in Ada_Generic_Subp_Internal then
-- Generic subprogram declaration includes generic formals
-- declarations.
Fill_Code_Snippet
(Spec_Node,
Decl_Node.Parent.Token_Start,
Spec_Node.Token_End,
Sections);
else
Fill_Code_Snippet
(Spec_Node, Spec_Node.Token_Start, Spec_Node.Token_End, Sections);
end if;
-- Postprocess extracted text, for each group of lines, separated
-- by empty line by remove of two minus signs and common leading
-- whitespaces
Remove_Comment_Start_And_Indentation (Sections, Options.Pattern);
-- Process raw documentation for subprogram, fill sections and create
-- description section.
declare
Raw_Section : Section_Access;
begin
-- Select most appropriate section depending from the style and
-- fallback.
case Options.Style is
when GNAT =>
if not Intermediate_Upper_Section.Text.Is_Empty then
Raw_Section := Intermediate_Upper_Section;
elsif not Intermediate_Lower_Section.Text.Is_Empty then
Raw_Section := Intermediate_Lower_Section;
elsif Declarative_Section /= null
and then not Declarative_Section.Text.Is_Empty
then
Raw_Section := Declarative_Section;
elsif Trailing_Section /= null
and then not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
elsif Options.Fallback
and not Leading_Section.Text.Is_Empty
then
Raw_Section := Leading_Section;
end if;
when Leading =>
if not Leading_Section.Text.Is_Empty then
Raw_Section := Leading_Section;
elsif Options.Fallback then
if Intermediate_Upper_Section.Text.Is_Empty then
Raw_Section := Intermediate_Upper_Section;
elsif not Intermediate_Lower_Section.Text.Is_Empty then
Raw_Section := Intermediate_Lower_Section;
elsif Declarative_Section /= null
and then not Declarative_Section.Text.Is_Empty
then
Raw_Section := Declarative_Section;
elsif Trailing_Section /= null
and then not Trailing_Section.Text.Is_Empty
then
Raw_Section := Trailing_Section;
end if;
end if;
end case;
Parse_Raw_Section
(Raw_Section,
[Param_Tag | Return_Tag | Exception_Tag => True,
others => False],
Sections);
end;
end Extract_Subprogram_Documentation;
----------------------------------------
-- Extract_Upper_Intermediate_Section --
----------------------------------------
procedure Extract_Upper_Intermediate_Section
(Token_Start : Token_Reference;
Token_End : Token_Reference;
Options : GNATdoc.Comments.Options.Extractor_Options;
Documentation : in out Structured_Comment'Class;
Section : out Section_Access)
is
Token : Token_Reference := Token_Start;
Found : Boolean := False;
Separated : Boolean := False;
-- Whether comment block is separated from the list with 'is' keyword
-- by empty line. In this case comment block can belong to the entity
-- declaration below.
begin
Section :=
new GNATdoc.Comments.Section'
(Kind => Raw,
Symbol => "<<INTERMEDIATE UPPER>>",
Name => <>,
Text => <>,
others => <>);
Documentation.Sections.Append (Section);
loop
Token := Next (Token);
exit when Token = No_Token or else Token = Token_End;
case Kind (Data (Token)) is
when Ada_Comment =>
Found := True;
Append_Documentation_Line
(Section.Text, Text (Token), Options.Pattern);
when Ada_Whitespace =>
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
begin
if Location.End_Line - Location.Start_Line > 1 then
exit when Found;
Found := True;
Separated := True;
end if;
end;
when others =>
if Separated then
-- Comment block is separated from the line with 'is'
-- keyword by an empty line, but not separated from the
-- entity declaration below, thus don't include it into
-- package documentation.
Section.Text.Clear;
end if;
exit;
end case;
end loop;
end Extract_Upper_Intermediate_Section;
-----------------------
-- Fill_Code_Snippet --
-----------------------
procedure Fill_Code_Snippet
(Node : Ada_Node'Class;
First_Token : Token_Reference;
Last_Token : Token_Reference;
Sections : in out Section_Vectors.Vector)
is
procedure Remove_Leading_Spaces
(Text : in out VSS.String_Vectors.Virtual_String_Vector;
Line_Index : Positive;
Amount : VSS.Strings.Character_Count);
-- Remove given amount of space characters from the line of the given
-- index.
---------------------------
-- Remove_Leading_Spaces --
---------------------------
procedure Remove_Leading_Spaces
(Text : in out VSS.String_Vectors.Virtual_String_Vector;
Line_Index : Positive;
Amount : VSS.Strings.Character_Count)
is
Line : constant Virtual_String := Text (Line_Index);
Iterator : Character_Iterator := Line.At_First_Character;
Count : Character_Count := Amount;
begin
while Iterator.Forward loop
exit when Iterator.Element /= Space;
Count := Count - 1;
if Count = 0 then
Text.Replace (Line_Index, Line.Tail_From (Iterator));
exit;
end if;
end loop;
end Remove_Leading_Spaces;
First_Token_Location : constant Source_Location_Range :=
Sloc_Range (Data (First_Token));
Snippet_Section : Section_Access;
Text : Virtual_String_Vector;
begin
Text :=
To_Virtual_String
(Libadalang.Common.Text (First_Token, Last_Token)).Split_Lines
(Ada_New_Line_Function);
-- Indent first line correctly.
declare
Line : Virtual_String := Text (1);
begin
for J in 2 .. First_Token_Location.Start_Column loop
Line.Prepend (' ');
end loop;
Text.Replace (1, Line);
end;
-- Remove comments
if First_Token /= Last_Token then
declare
Line_Offset : constant Line_Number :=
First_Token_Location.Start_Line - 1;
Token : Token_Reference := Last_Token;
begin
loop
Token := Previous (Token);
exit when Token = First_Token or Token = No_Token;
if Kind (Data (Token)) = Ada_Comment then
declare
Location : constant Source_Location_Range :=
Sloc_Range (Data (Token));
Index : constant Positive :=
Positive (Location.Start_Line - Line_Offset);
Line : Virtual_String := Text (Index);
Iterator : Character_Iterator :=
Line.After_Last_Character;
begin
-- Move iterator till first character before the
-- comment's start column.
while Iterator.Backward loop
exit when
Iterator.Character_Index
< Character_Index (Location.Start_Column);
end loop;
-- Rewind all whitespaces before the comment
while Iterator.Backward loop
exit when not Is_Ada_Separator (Iterator.Element);
end loop;
-- Remove comment and spaces before it from the line.
Line := Line.Slice (Line.At_First_Character, Iterator);
Text.Replace (Index, Line);
end;
end if;
end loop;
end;
end if;
-- For enumeration types with large number of defined enumeration
-- literals, limit text for few first literals and last literal.
if Node.Kind = Ada_Concrete_Type_Decl
and then Node.As_Concrete_Type_Decl.F_Type_Def.Kind
= Ada_Enum_Type_Def
then
declare
procedure Move_At
(Iterator : in out Character_Iterator;
Position : Character_Index);
-------------
-- Move_At --
-------------
procedure Move_At
(Iterator : in out Character_Iterator;
Position : Character_Index) is
begin
if Iterator.Character_Index = Position then
return;
elsif Iterator.Character_Index < Position then
while Iterator.Forward loop
exit when Iterator.Character_Index = Position;
end loop;
else
while Iterator.Backward loop
exit when Iterator.Character_Index = Position;
end loop;
end if;
end Move_At;
Max_Enum_Literals : constant := 10;
-- Maximum number of the enumeration literals presented in the
-- code snippet.
Line_Offset : constant Line_Number :=
First_Token_Location.Start_Line - 1;
Literals : constant Enum_Literal_Decl_List :=
Node.As_Concrete_Type_Decl.F_Type_Def.As_Enum_Type_Def
.F_Enum_Literals;
begin
if Literals.Children_Count > Max_Enum_Literals then
-- Replace enumeration literal before the last enumeration
-- literal of the type by the horizontal ellipsis.
declare
Location : constant Source_Location_Range :=
Literals.Child (Literals.Last_Child_Index - 1).Sloc_Range;
Index : constant Positive :=
Positive (Location.Start_Line - Line_Offset);
Line : Virtual_String := Text (Index);
E_Iterator : Character_Iterator :=
Line.After_Last_Character;
S_Iterator : Character_Iterator :=
Line.After_Last_Character;
begin
Move_At
(S_Iterator, Character_Index (Location.Start_Column));
Move_At
(E_Iterator, Character_Index (Location.End_Column) - 1);
Line.Replace (S_Iterator, E_Iterator, "…");
Text.Replace (Index, Line);
end;
-- Remove all other intermediate enumeration literals.
for J in reverse
Literals.First_Child_Index + Max_Enum_Literals - 2
.. Literals.Last_Child_Index - 2
loop
declare
Location : constant Source_Location_Range :=
Literals.Child (J).Sloc_Range;
Index : constant Positive :=
Positive (Location.Start_Line - Line_Offset);
Line : Virtual_String := Text (Index);
E_Iterator : Character_Iterator :=
Line.After_Last_Character;
S_Iterator : Character_Iterator :=
Line.After_Last_Character;
begin
Move_At
(S_Iterator, Character_Index (Location.Start_Column));
Move_At
(E_Iterator, Character_Index (Location.End_Column) - 1);
while S_Iterator.Backward loop
exit when not Is_Ada_Separator (S_Iterator.Element);
end loop;
if S_Iterator.Has_Element then
Line.Delete (S_Iterator, E_Iterator);
Text.Replace (Index, Line);
else
Line.Delete (Line.At_First_Character, E_Iterator);
declare
Previous : Virtual_String := Text (Index - 1);
begin
E_Iterator.Set_At_Last (Previous);
Previous.Delete
(E_Iterator, Previous.At_Last_Character);
Previous.Append (Line);
Text.Replace (Index - 1, Previous);
Text.Delete (Index);
end;
end if;
end;
end loop;
end if;
end;
end if;
-- For record type add ';' at the end
if Node.Kind = Ada_Concrete_Type_Decl
and then Node.As_Concrete_Type_Decl.F_Type_Def.Kind
in Ada_Record_Type_Def | Ada_Derived_Type_Def
then
Text.Replace (Text.Length, Text.Last_Element & ";");
end if;
-- Remove all empty lines
for Index in reverse 1 .. Text.Length loop
if Text (Index).Is_Empty then
Text.Delete (Index);
end if;
end loop;
-- For the subprogram specification check whether "overriding"/"not
-- overriding" indicator is used at the same line with subprogram
-- specification and reformat code snippet: first line of the
-- subprogram specification is moved left to position of the indicator;
-- if subprogram parameter is present on this line too, all lines
-- below is moved too, unless any non-space characters are found in
-- the removed slice of the line.
if Node.Kind = Ada_Subp_Spec
and then Node.Parent.Kind
in Ada_Classic_Subp_Decl | Ada_Base_Subp_Body
then
declare
Indicator_Node : constant Overriding_Node :=
(if Node.Parent.Kind in Ada_Classic_Subp_Decl
then Node.Parent.As_Classic_Subp_Decl.F_Overriding
else Node.Parent.As_Base_Subp_Body.F_Overriding);
Indicator_Location : constant Source_Location_Range :=
Indicator_Node.Sloc_Range;
Offset : VSS.Strings.Character_Count := 0;
begin
if Indicator_Node.Kind /= Ada_Overriding_Unspecified
and then First_Token_Location.Start_Line
= Indicator_Location.Start_Line
then
Offset :=
VSS.Strings.Character_Count
(First_Token_Location.Start_Column
- Indicator_Location.Start_Column);
end if;
if Offset /= 0 then
Remove_Leading_Spaces (Text, 1, Offset);
declare
Params_Node : constant Params :=
Node.As_Subp_Spec.F_Subp_Params;
P1_Node : Ada_Node;
Success : Boolean;
begin
if Params_Node /= No_Params then
Params_Node.F_Params.Get_Child (1, Success, P1_Node);
if Success
and then P1_Node.Sloc_Range.Start_Line
= First_Token_Location.Start_Line
then
for J in 2 .. Text.Length loop
Remove_Leading_Spaces (Text, J, Offset);
end loop;
end if;
end if;
end;
end if;
end;
end if;
Snippet_Section :=
new Section'
(Kind => Snippet, Symbol => "ada", Text => Text, others => <>);
Sections.Append (Snippet_Section);
end Fill_Code_Snippet;
----------------------
-- Is_Ada_Separator --
----------------------
function Is_Ada_Separator (Item : Virtual_Character) return Boolean is
begin
return Get_General_Category (Item) in Space_Separator | Format;
end Is_Ada_Separator;
-----------------------
-- Parse_Raw_Section --
-----------------------
procedure Parse_Raw_Section
(Raw_Section : Section_Access;
Allowed_Tags : Section_Tag_Flags;
Sections : in out Section_Vectors.Vector)
is
Aux : Boolean := False;
begin
Parse_Raw_Section (Raw_Section, Allowed_Tags, Sections, Aux);
end Parse_Raw_Section;
-----------------------
-- Parse_Raw_Section --
-----------------------
procedure Parse_Raw_Section
(Raw_Section : Section_Access;
Allowed_Tags : Section_Tag_Flags;
Sections : in out Section_Vectors.Vector;
Is_Private : in out Boolean)
is
Tag_Matcher : constant Regular_Expression :=
To_Regular_Expression
(Ada_Optional_Separator_Expression
& "@(param|return|exception|enum|field|formal|private)"
& Ada_Optional_Separator_Expression);
Parameter_Matcher : constant Regular_Expression :=
To_Regular_Expression
("((?:" & Ada_Identifier_Expression
& "|" & Ada_Character_Literal_Expression & "))"
& Ada_Optional_Separator_Expression);
Match : Regular_Expression_Match;
Current_Section : Section_Access;
Kind : Section_Kind;
Tag : Section_Tag;
Name : Virtual_String;
Symbol : Virtual_String;
Line_Tail : Virtual_String;
Skip_Line : Boolean;
begin
pragma Assert (Tag_Matcher.Is_Valid);
pragma Assert (Parameter_Matcher.Is_Valid);
-- Create "Description" section
Current_Section :=
new Section'(Kind => Description, others => <>);
Sections.Append (Current_Section);
-- Return when there is no raw section to parse
if Raw_Section = null then
return;
end if;
-- Process raw text
for Line of Raw_Section.Text loop
Skip_Line := False;
Match := Tag_Matcher.Match (Line);
if Match.Has_Match then
if Match.Captured (1) = "param" then
Tag := Param_Tag;
Kind := Parameter;
elsif Match.Captured (1) = "return" then
Tag := Return_Tag;
Kind := Returns;
elsif Match.Captured (1) = "exception" then
Tag := Exception_Tag;
Kind := Raised_Exception;
elsif Match.Captured (1) = "enum" then
Tag := Enum_Tag;
Kind := Enumeration_Literal;
elsif Match.Captured (1) = "field" then
Tag := Member_Tag;
Kind := Field;
elsif Match.Captured (1) = "formal" then
Tag := Formal_Tag;
Kind := Formal;
elsif Match.Captured (1) = "private" then
Tag := Private_Tag;
else
raise Program_Error;
end if;
if not Allowed_Tags (Tag) then
goto Default;
end if;
Line_Tail := Line.Tail_After (Match.Last_Marker);
if Tag = Private_Tag then
Is_Private := True;
goto Skip;
elsif Kind
in Parameter | Raised_Exception | Enumeration_Literal | Field
| Formal
then
-- Lookup for name of the parameter/exception. Convert
-- found name to canonical form.
-- Match := Parameter_Matcher.Match (Line, Tail_First);
-- ??? Not implemented
Match := Parameter_Matcher.Match (Line_Tail);
if not Match.Has_Match then
goto Default;
end if;
Name := Match.Captured (1);
Symbol := GNATdoc.Comments.Utilities.To_Symbol (Name);
Line_Tail := Line_Tail.Tail_After (Match.Last_Marker);
else
Name.Clear;
Symbol.Clear;
end if;
declare
Found : Boolean := False;
begin
for Section of Sections loop
if Section.Kind = Kind and Section.Symbol = Symbol then
Current_Section := Section;
Found := True;
exit;
end if;
end loop;
if not Found then
if Kind = Raised_Exception then
Current_Section :=
new Section'
(Kind => Raised_Exception,
Name => Name,
Symbol => Symbol,
others => <>);
Sections.Append (Current_Section);
else
goto Default;
end if;
else
if not Current_Section.Text.Is_Empty then
Current_Section.Text.Append (Empty_Virtual_String);
end if;
end if;
end;
<<Skip>>
Skip_Line := True;
if not Line_Tail.Is_Empty then
Current_Section.Text.Append (Line_Tail);
end if;
end if;
<<Default>>
if not Skip_Line then
Current_Section.Text.Append (Line);
end if;
end loop;
-- Remove empty lines at the end of text of all sections
for Section of Sections loop
while not Section.Text.Is_Empty
and then Section.Text.Last_Element.Is_Empty
loop
Section.Text.Delete_Last;
end loop;
end loop;
end Parse_Raw_Section;
--------------------------------
-- Prepend_Documentation_Line --
--------------------------------
procedure Prepend_Documentation_Line
(Text : in out VSS.String_Vectors.Virtual_String_Vector;
Line : Langkit_Support.Text.Text_Type;
Pattern : VSS.Regular_Expressions.Regular_Expression)
is
L : constant Virtual_String := To_Virtual_String (Line);
M : Regular_Expression_Match;
begin
if Pattern.Is_Valid then
M := Pattern.Match (L);
if M.Has_Match then
Text.Prepend (L);
end if;
else
Text.Prepend (L);
end if;
end Prepend_Documentation_Line;
------------------------------------------
-- Remove_Comment_Start_And_Indentation --
------------------------------------------
procedure Remove_Comment_Start_And_Indentation
(Sections : in out Section_Vectors.Vector;
Pattern : VSS.Regular_Expressions.Regular_Expression) is
begin
for Section of Sections loop
declare
First_Line : Positive := 1;
Last_Line : Natural := 0;
Indent : Character_Count;
begin
loop
for J in First_Line .. Section.Text.Length loop
exit when Section.Text (J).Is_Empty;
Last_Line := J;
end loop;
-- Compute common indentation level
Indent := Character_Count'Last;
for J in First_Line .. Last_Line loop
declare
Line : constant Virtual_String :=
Section.Text (J);
Iterator : Character_Iterator :=
Line.Before_First_Character;
Success : Boolean;
begin
if Section.Kind /= Snippet then
-- Skip '--' or documentation pattern from all
-- sections, but snippet.
if not Pattern.Is_Valid then
Success := Iterator.Forward;
pragma Assert
(Success and then Iterator.Element = '-');
Success := Iterator.Forward;
pragma Assert
(Success and then Iterator.Element = '-');
else
declare
Match : constant Regular_Expression_Match :=
Pattern.Match (Line);
begin
Iterator.Set_At (Match.Last_Marker);
end;
end if;
end if;
-- Lookup for first non-whitespace character
while Iterator.Forward loop
exit when not Is_Ada_Separator (Iterator.Element);
end loop;
if Iterator.Has_Element then
Indent :=
Character_Index'Min
(Indent, Iterator.Character_Index - 1);
end if;
end;
end loop;
-- Remove common indentation segment
for J in First_Line .. Last_Line loop
declare
Line : constant Virtual_String :=
Section.Text (J);
Iterator : Character_Iterator :=
Line.At_First_Character;
Success : Boolean with Unreferenced;
begin
if Line.Character_Length > Indent then
for J in 1 .. Indent loop
Success := Iterator.Forward;
end loop;
Section.Text.Replace (J, Line.Tail_From (Iterator));
else
Section.Text.Replace (J, Empty_Virtual_String);
end if;
end;
end loop;
First_Line := Last_Line + 2;
exit when Last_Line = Section.Text.Length;
end loop;
end;
end loop;
end Remove_Comment_Start_And_Indentation;
end GNATdoc.Comments.Extractor;
|