package diffast-langs-cpp-parsing

  1. Overview
  2. Docs

Source file parser_aux.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
(*
   Copyright 2012-2020 Codinuum Software Lab <https://codinuum.com>
   Copyright 2020-2025 Chiba Institute of Technology

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)

(* Author: Masatomo Hashimoto <m.hashimoto@stair.center> *)

[%%prepare_logger]

module Xset = Diffast_misc.Xset
module Xhash = Diffast_misc.Xhash
module Binding = Diffast_misc.Binding
module Loc = Diffast_misc.Loc
module Env_base = Langs_common.Env_base
module Astloc = Langs_common.Astloc

module UID = Diffast_misc.UID
module L = Label
module B = Binding
module BID = Binding.ID
module I = Pinfo
module N = Pinfo.Name
module Type = Pinfo.Type
module C = Context
module Loc_ = Loc

open Common

let is_asm_kw =
  let l = [
    "pop";
    "push";
    "add";
    "sub";

    "subs"; (* ARM *)

    "movn"; (* MIPS *)
    "movz";
    "sll";
    "srl";
  ] in
  let names = Xset.create 0 in
  List.iter (Xset.add names) l;
  fun s -> Xset.mem names s

let conv_loc
    { Ast.Loc.filename     = fn;
      Ast.Loc.start_offset = so;
      Ast.Loc.end_offset   = eo;
      Ast.Loc.start_line   = sl;
      Ast.Loc.start_char   = sc;
      Ast.Loc.end_line     = el;
      Ast.Loc.end_char     = ec;
    } =
  Loc_.make ~fname:fn so eo sl sc el ec

let mes fmt = _mes "Parser_aux" fmt

type paren_kind_sub =
  | PKS_NONE
  | PKS_SIZEOF
  | PKS_IF
  | PKS_NUMERIC

type paren_kind =
  | PK_NORMAL of paren_kind_sub
  | PK_ARG
  | PK_TYPE of paren_kind_sub
  | PK_MACRO
  | PK_PP (* preprocessor *)
  | PK_SS (* statements *)
  | PK_PS (* old-style function parameters *)
  | PK_FOLD
  | PK_BRACKET (* objective-C *)

let paren_kind_sub_to_string = function
  | PKS_NONE   -> "PKS_NONE"
  | PKS_SIZEOF -> "PKS_SIZEOF"
  | PKS_IF     -> "PKS_IF"
  | PKS_NUMERIC -> "PKS_NUMERIC"

let paren_kind_to_string = function
  | PK_NORMAL s -> "PK_NORMAL:"^(paren_kind_sub_to_string s)
  | PK_ARG    -> "PK_ARG"
  | PK_TYPE s -> "PK_TYPE:"^(paren_kind_sub_to_string s)
  | PK_MACRO  -> "PK_MACRO"
  | PK_PP     -> "PK_PP"
  | PK_SS     -> "PK_SS"
  | PK_PS     -> "PK_PS"
  | PK_FOLD   -> "PK_FOLD"
  | PK_BRACKET -> "PK_BRACKET"

type templ_param_arg_context = {
    mutable tpac_expr_flag : bool;
  }

let make_templ_param_arg_context () = { tpac_expr_flag=false }

let templ_param_arg_context_to_string {
  tpac_expr_flag=e;
} =
  let sl = ref [] in
  if e then
    sl := "expr" :: !sl;
  if !sl = [] then
    ""
  else
    ":" ^ String.concat ";" !sl

type bracket_kind =
  | BK_PAREN of paren_kind
  | BK_TEMPL_PARAM of templ_param_arg_context
  | BK_TEMPL_ARG of templ_param_arg_context
  | BK_SUBSCR
  | BK_LAM_INTR
  | BK_ATTR
  | BK_OBJC_MSG
  | BK_BRACE of int (* indent *) option
  | BK_CLASS_BRACE
  | BK_INI_BRACE
  | BK_REQ_BRACE

let make_templ_param () = BK_TEMPL_PARAM (make_templ_param_arg_context())
let make_templ_arg () = BK_TEMPL_ARG (make_templ_param_arg_context())

let bracket_kind_to_string = function
  | BK_PAREN pk    -> "BK_PAREN:"^(paren_kind_to_string pk)
  | BK_TEMPL_PARAM c -> "BK_TEMPL_PARAM"^(templ_param_arg_context_to_string c)
  | BK_TEMPL_ARG c   -> "BK_TEMPL_ARG"^(templ_param_arg_context_to_string c)
  | BK_SUBSCR      -> "BK_SUBSCR"
  | BK_LAM_INTR    -> "BK_LAM_INTR"
  | BK_ATTR        -> "BK_ATTR"
  | BK_OBJC_MSG    -> "BK_OBJC_MSG"
  | BK_BRACE i_opt -> "BK_BRACE:"^(match i_opt with Some i -> string_of_int i | _ -> "")
  | BK_CLASS_BRACE -> "BK_CLASS_BRACE"
  | BK_INI_BRACE   -> "BK_INI_BRACE"
  | BK_REQ_BRACE   -> "BK_REQ_BRACE"

type parsing_mode =
  | M_NORMAL
  | M_STMTS
  | M_DECLS_SUB of string
  | M_MEM_DECLS_SUB of string
  | M_STMTS_SUB of string
  | M_EXPR_SUB of string
  | M_INIT_SUB of string
  | M_TYPE_SUB of string
  | M_SPECS_SUB of string
  | M_DTORS_SUB of string
  | M_ETORS_SUB of string
  | M_OBJC_DECLS_SUB of string

let parsing_mode_to_string = function
  | M_NORMAL -> "M_NORMAL"
  | M_STMTS -> "M_STMTS"
  | M_DECLS_SUB s -> "M_DECLS_SUB:"^s
  | M_MEM_DECLS_SUB s -> "M_MEM_DECLS_SUB:"^s
  | M_STMTS_SUB s -> "M_STMTS_SUB:"^s
  | M_EXPR_SUB s -> "M_EXPR_SUB:"^s
  | M_INIT_SUB s -> "M_INIT_SUB:"^s
  | M_TYPE_SUB s -> "M_TYPE_SUB:"^s
  | M_SPECS_SUB s -> "M_SPECS_SUB:"^s
  | M_DTORS_SUB s -> "M_DTORS_SUB:"^s
  | M_ETORS_SUB s -> "M_ETORS_SUB:"^s
  | M_OBJC_DECLS_SUB s -> "M_OBJC_DECLS_SUB:"^s

type odd_brace_lv_t = { o_lv : int; mutable o_ini_lv : int }
let odd_brace_lv_to_string { o_lv=lv; o_ini_lv=ilv } = sprintf "%d(%d)" lv ilv

let stack_2nd stack =
  let count = ref 0 in
  let y = ref (Stack.top stack) in
  begin
    try
      Stack.iter
        (fun x ->
          incr count;
          if !count = 2 then begin
            y := x;
            raise Exit
          end
        ) stack;
      raise Not_found
    with
      Exit -> ()
  end;
  !y

[%%capture_path
class pstat = object (self)
  val mutable for_flag = false
  val mutable templ_flag = false
  val mutable sizeof_ty_flag = false
  val mutable str_flag = false
  val mutable macro_arg_level = 0
  val mutable end_of_if_head_flag = false
  val mutable pp_line_flag = false
  val mutable pp_if_flag = false
  val mutable pp_ifdef_flag = false
  val mutable pp_ifx_d_level = 0
  val mutable asm_flag = false
  val mutable asm_block_flag = false
  val mutable asm_paren_level = 0
  val mutable braced_asm_flag = false
  val mutable enum_head_flag = false
  val mutable ty_param_flag = false
  val mutable ty_param_rhs_flag = false
  val mutable exec_config_flag = false
  val mutable decltype_flag = false
  val mutable alignas_flag = false
  val mutable alignof_flag = false
  val mutable noexcept_flag = false
  val mutable end_of_id_macro_call_flag = false
  val mutable end_of_literal_macro_call_flag = false
  val mutable end_of_decltype_flag = false
  val mutable trailing_retty_flag = false
  val mutable base_clause_flag = false
  val mutable start_of_func_body_flag = false
  val mutable end_of_old_param_decl_flag = false
  val mutable end_of_class_spec_flag = false
  val mutable end_of_enum_spec_flag = false
  val mutable end_of_cast_type_flag = false
  val mutable stmts_flag = false
  val mutable end_of_templ_head_flag = false
  val mutable end_of_params_flag = false
  val mutable end_of_req_params_flag = false
  val mutable decl_stmt_block_flag = false
  val mutable lambda_dtor_flag = false
  val mutable lambda_intro_flag = false
  val mutable end_of_lambda_templ_flag = false
  val mutable ctor_init_flag = false
  val mutable asm_shader_flag = false
  val mutable dsl_flag = false
  val mutable objc_class_interface_flag = false
  val mutable objc_protocol_decl_flag = false
  val mutable objc_class_flag = false
  val mutable objc_block_flag = false
  val mutable objc_sel_flag = false
  val mutable objc_meth_sel_flag = false
  val mutable objc_meth_decl_flag = false
  val mutable objc_superclass_flag = false
  val mutable objc_cat_flag = false
  val mutable objc_protocol_ref_flag = false
  val mutable end_of_objc_meth_sel_flag = false
  val mutable end_of_objc_meth_type_flag = false
  val mutable end_of_objc_property_attrs_decl_flag = false
  val mutable end_of_objc_protocol_ref_list_flag = false
  val mutable end_of_decl_spec_macro_call_flag = false
  val mutable end_of_attr_macro_call_flag = false
  val mutable end_of_type_macro_call_flag = false
  val mutable dtor_flag = false
  val mutable pp_func_body_odd_flag = false
  val mutable class_name_flag = false
  val mutable broken_flag = false
  val mutable end_of_noptr_dtor_paren_flag = false
  val mutable ns_alias_flag = false
  val mutable old_param_decl_flag = false
  val mutable end_of_sizeof_flag = false
  val mutable end_of_handler_head_flag = false
  val mutable cast_head_flag = false
  val mutable end_of_broken_decl_section_flag = false
  val mutable end_of_label_flag = false
  val mutable end_of_mem_initializer_flag = false
  val mutable attr_flag = false
  val mutable linkage_spec_flag = false
  val mutable condition_flag = false
  val mutable mem_acc_flag = false
  val mutable alias_flag = false
  val mutable using_flag = false
  val mutable mock_qualifier_flag = false
  val mutable end_of_str_section_flag = false
  val mutable new_flag = false
  val mutable concept_flag = false
  val mutable requires_clause_flag = false
  val mutable rhs_flag = false
  val mutable eq_init_flag = false

  val bracket_stack_stack = Stack.create()

  val paren_stack = Stack.create()
  val brace_stack = Stack.create()

  val templ_param_arg_stack = (Stack.create() : int Stack.t)
  val pp_if_section_stack = (Stack.create() : I.pp_if_section_info Stack.t)
  val pp_group_rel_brace_level_stack = (Stack.create() : int ref Stack.t)
  val top_stmts_stack = (Stack.create() : int Stack.t)
  val templ_arg_stack = (Stack.create() : bool Stack.t)
  val odd_brace_lv_stack = (Stack.create() : odd_brace_lv_t Stack.t)

  val mutable last_templ_arg_stack_top = false

  val mutable typename_level = 0
  val mutable braced_init_level = 0
  val mutable bracket_level = 0
  val mutable _pp_if_section_level = 0
  val mutable pp_paren_level = 0
  val mutable objc_message_expr_level = 0

  val mutable brace_level_marker = 0
  val mutable brace_level_marker_flag = false
  val mutable brace_level_marker_unbalanced_flag = false
  val mutable canceled_brace_level_marker = 0
  val mutable pp_line_rel_brace_level = 0

  val mutable last_pp_if_section_info = I.dummy_info

  initializer
    Stack.push (Stack.create() : bracket_kind Stack.t) bracket_stack_stack;
    Stack.push (ref 0) pp_group_rel_brace_level_stack

  method reset () =
    for_flag <- false;
    templ_flag <- false;
    sizeof_ty_flag <- false;
    str_flag <- false;
    macro_arg_level <- 0;
    end_of_if_head_flag <- false;
    pp_line_flag <- false;
    pp_if_flag <- false;
    pp_ifdef_flag <- false;
    pp_ifx_d_level <- 0;
    asm_flag <- false;
    asm_block_flag <- false;
    asm_paren_level <- 0;
    braced_asm_flag <- false;
    enum_head_flag <- false;
    ty_param_flag <- false;
    ty_param_rhs_flag <- false;
    exec_config_flag <- false;
    decltype_flag <- false;
    alignas_flag <- false;
    alignof_flag <- false;
    noexcept_flag <- false;
    start_of_func_body_flag <- false;
    end_of_id_macro_call_flag <- false;
    end_of_literal_macro_call_flag <- false;
    end_of_decltype_flag <- false;
    trailing_retty_flag <- false;
    base_clause_flag <- false;
    end_of_old_param_decl_flag <- false;
    end_of_class_spec_flag <- false;
    end_of_enum_spec_flag <- false;
    end_of_cast_type_flag <- false;
    stmts_flag <- false;
    end_of_templ_head_flag <- false;
    end_of_params_flag <- false;
    end_of_req_params_flag <- false;
    decl_stmt_block_flag <- false;
    lambda_dtor_flag <- false;
    lambda_intro_flag <- false;
    end_of_lambda_templ_flag <- false;
    ctor_init_flag <- false;
    asm_shader_flag <- false;
    dsl_flag <- false;
    objc_class_interface_flag <- false;
    objc_protocol_decl_flag <- false;
    objc_class_flag <- false;
    objc_block_flag <- false;
    objc_sel_flag <- false;
    objc_meth_sel_flag <- false;
    objc_meth_decl_flag <- false;
    objc_superclass_flag <- false;
    objc_cat_flag <- false;
    objc_protocol_ref_flag <- false;
    end_of_objc_meth_sel_flag <- false;
    end_of_objc_meth_type_flag <- false;
    end_of_objc_property_attrs_decl_flag <- false;
    end_of_objc_protocol_ref_list_flag <- false;
    end_of_decl_spec_macro_call_flag <- false;
    end_of_attr_macro_call_flag <- false;
    end_of_type_macro_call_flag <- false;
    dtor_flag <- false;
    pp_func_body_odd_flag <- false;
    class_name_flag <- false;
    broken_flag <- false;
    end_of_noptr_dtor_paren_flag <- false;
    ns_alias_flag <- false;
    old_param_decl_flag <- false;
    end_of_sizeof_flag <- false;
    end_of_handler_head_flag <- false;
    cast_head_flag <- false;
    end_of_broken_decl_section_flag <- false;
    end_of_label_flag <- false;
    end_of_mem_initializer_flag <- false;
    attr_flag <- false;
    linkage_spec_flag <- false;
    condition_flag <- false;
    mem_acc_flag <- false;
    alias_flag <- false;
    using_flag <- false;
    mock_qualifier_flag <- false;
    end_of_str_section_flag <- false;
    new_flag <- false;
    concept_flag <- false;
    requires_clause_flag <- false;
    rhs_flag <- false;
    eq_init_flag <- false;
    Stack.clear bracket_stack_stack;
    Stack.push (Stack.create() : bracket_kind Stack.t) bracket_stack_stack;
    Stack.clear paren_stack;
    Stack.clear brace_stack;
    Stack.clear templ_param_arg_stack;
    Stack.clear pp_if_section_stack;
    Stack.clear pp_group_rel_brace_level_stack;
    Stack.push (ref 0) pp_group_rel_brace_level_stack;
    Stack.clear top_stmts_stack;
    Stack.clear templ_arg_stack;
    Stack.clear odd_brace_lv_stack;
    last_templ_arg_stack_top <- false;
    typename_level <- 0;
    braced_init_level <- 0;
    bracket_level <- 0;
    pp_paren_level <- 0;
    _pp_if_section_level <- 0;
    objc_message_expr_level <- 0;
    brace_level_marker <- 0;
    brace_level_marker_flag <- false;
    brace_level_marker_unbalanced_flag <- false;
    canceled_brace_level_marker <- 0;
    pp_line_rel_brace_level <- 0

  method to_string =
    let l = [
      "paren_lv", self#paren_level;
      "brace_lv", self#brace_level;
      "templ_param_arg_lv", self#templ_param_arg_level;
      "typename_lv", typename_level;
      "braced_init_lv", braced_init_level;
      "bracket_lv", bracket_level;
      "macro_arg_lv", macro_arg_level;
      "odd_brace_lv", self#odd_brace_level;
      "pp_paren_lv", self#pp_paren_level;
      "_pp_if_section_lv", self#_pp_if_section_level;
      "objc_message_expr_lv", objc_message_expr_level;
      "pp_group_rel_brace_lv", self#pp_group_rel_brace_level;
    ]
    in
    sprintf "{%s}"
      (String.concat ";"
         (List.map
            (fun (k, v) ->
              sprintf "%s:%d" k v
            ) (List.filter (fun (_, v) -> v <> 0) l)))

  method copy =
    let bracket_stack_stack_copy =
      let stack_list = ref [] in
      Stack.iter
        (fun bracket_stack ->
          let bracket_stack_copy = Stack.copy bracket_stack in
          stack_list := bracket_stack_copy :: !stack_list
        ) bracket_stack_stack;
      let stack_copy = Stack.create() in
      List.iter (fun x -> Stack.push x stack_copy) !stack_list;
      stack_copy
    in
    {<bracket_stack_stack = bracket_stack_stack_copy;
      paren_stack = Stack.copy paren_stack;
      brace_stack = Stack.copy brace_stack;
      templ_param_arg_stack = Stack.copy templ_param_arg_stack;
      pp_if_section_stack = Stack.copy pp_if_section_stack;
      pp_group_rel_brace_level_stack = Stack.copy pp_group_rel_brace_level_stack;
      top_stmts_stack = Stack.copy top_stmts_stack;
      templ_arg_stack = Stack.copy templ_arg_stack;
      odd_brace_lv_stack = Stack.copy odd_brace_lv_stack;
      >}

  method set_brace_level_marker_flag () =
    [%debug_log "set"];
    brace_level_marker_flag <- true

  method clear_brace_level_marker_flag () =
    [%debug_log "cleared"];
    brace_level_marker_flag <- false;
    brace_level_marker_unbalanced_flag <- false

  method brace_level_marker_flag = brace_level_marker_flag

  method set_brace_level_marker_unbalanced_flag () =
    [%debug_log "set"];
    brace_level_marker_unbalanced_flag <- true

  method clear_brace_level_marker_unbalanced_flag () =
    [%debug_log "cleared"];
    brace_level_marker_unbalanced_flag <- false

  method brace_level_marker_unbalanced_flag = brace_level_marker_unbalanced_flag

  method brace_level_marker = brace_level_marker

  method incr_brace_level_marker () =
    let lv = brace_level_marker in
    let lv1 = lv + 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    brace_level_marker <- lv1

  method decr_brace_level_marker () =
    let lv = brace_level_marker in
    let lv1 = lv - 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    brace_level_marker <- lv1

  method canceled_brace_level_marker = canceled_brace_level_marker

  method set_canceled_brace_level_marker lv =
    [%debug_log "lv=%d" lv];
    canceled_brace_level_marker <- lv

  method reset_canceled_brace_level_marker () =
    [%debug_log "@"];
    canceled_brace_level_marker <- 0

  method pp_line_rel_brace_level = pp_line_rel_brace_level

  method incr_pp_line_rel_brace_level () =
    let lv = pp_line_rel_brace_level in
    let lv1 = lv + 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    pp_line_rel_brace_level <- lv1

  method decr_pp_line_rel_brace_level () =
    let lv = pp_line_rel_brace_level in
    let lv1 = lv - 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    pp_line_rel_brace_level <- lv1

  method pp_group_rel_brace_level_stack = pp_group_rel_brace_level_stack

  method pp_group_rel_brace_level =
    try
      !(Stack.top pp_group_rel_brace_level_stack)
    with _ -> 0

  method reset_pp_group_rel_brace_level () =
    (Stack.top pp_group_rel_brace_level_stack) := 0

  method incr_pp_group_rel_brace_level () =
    let lv = self#pp_group_rel_brace_level in
    let lv1 = lv + 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    (Stack.top pp_group_rel_brace_level_stack) := lv1

  method decr_pp_group_rel_brace_level () =
    let lv = self#pp_group_rel_brace_level in
    let lv1 = lv - 1 in
    [%debug_log "lv=%d -> %d" lv lv1];
    (Stack.top pp_group_rel_brace_level_stack) := lv1

  method enter_templ_arg is_type =
    [%debug_log "entering templ_arg (is_type=%B)" is_type];
    Stack.push is_type templ_arg_stack

  method exit_templ_arg () =
    [%debug_log "exiting templ_arg"];
    let is_ty = Stack.pop templ_arg_stack in
    last_templ_arg_stack_top <- is_ty;
    [%debug_log "templ_arg exited (is_type=%B)" is_ty]

  method templ_arg_flag = (Stack.length templ_arg_stack) > 0
  method ty_templ_id_flag =
    try
      Stack.top templ_arg_stack
    with
      _ -> false
  method last_ty_templ_id_flag = last_templ_arg_stack_top

  method set_for_flag () =
    [%debug_log "for_flag set"];
    for_flag <- true

  method clear_for_flag () =
    if for_flag then begin
      [%debug_log "for_flag cleared"];
      for_flag <- false
    end

  method for_flag = for_flag

  method set_templ_flag () =
    [%debug_log "templ_flag set"];
    templ_flag <- true

  method clear_templ_flag () =
    if templ_flag then begin
      [%debug_log "templ_flag cleared"];
      templ_flag <- false
    end

  method templ_flag = templ_flag

  method set_start_of_func_body_flag () =
    [%debug_log "start_of_func_body_flag set"];
    start_of_func_body_flag <- true

  method clear_start_of_func_body_flag () =
    if start_of_func_body_flag then begin
      [%debug_log "start_of_func_body_flag cleared"];
      start_of_func_body_flag <- false
    end

  method start_of_func_body_flag = start_of_func_body_flag

  method set_end_of_old_param_decl_flag () =
    [%debug_log "end_of_old_param_decl_flag set"];
    end_of_old_param_decl_flag <- true

  method clear_end_of_old_param_decl_flag () =
    if end_of_old_param_decl_flag then begin
      [%debug_log "end_of_old_param_decl_flag cleared"];
      end_of_old_param_decl_flag <- false
    end

  method end_of_old_param_decl_flag = end_of_old_param_decl_flag

  method set_end_of_lambda_templ_flag () =
    [%debug_log "end_of_lambda_templ_flag set"];
    end_of_lambda_templ_flag <- true

  method clear_end_of_lambda_templ_flag () =
    if end_of_lambda_templ_flag then begin
      [%debug_log "end_of_lambda_templ_flag cleared"];
      end_of_lambda_templ_flag <- false
    end

  method end_of_lambda_templ_flag = end_of_lambda_templ_flag

  method set_old_param_decl_flag () =
    [%debug_log "old_param_decl_flag set"];
    old_param_decl_flag <- true

  method clear_old_param_decl_flag () =
    if old_param_decl_flag then begin
      [%debug_log "old_param_decl_flag cleared"];
      old_param_decl_flag <- false
    end

  method old_param_decl_flag = old_param_decl_flag

  method set_end_of_class_spec_flag () =
    [%debug_log "end_of_class_spec_flag set"];
    end_of_class_spec_flag <- true

  method clear_end_of_class_spec_flag () =
    if end_of_class_spec_flag then begin
      [%debug_log "end_of_class_spec_flag cleared"];
      end_of_class_spec_flag <- false
    end

  method end_of_class_spec_flag = end_of_class_spec_flag

  method set_end_of_enum_spec_flag () =
    [%debug_log "end_of_enum_spec_flag set"];
    end_of_enum_spec_flag <- true

  method clear_end_of_enum_spec_flag () =
    if end_of_enum_spec_flag then begin
      [%debug_log "end_of_enum_spec_flag cleared"];
      end_of_enum_spec_flag <- false
    end

  method end_of_enum_spec_flag = end_of_enum_spec_flag

  method set_end_of_cast_type_flag () =
    [%debug_log "end_of_cast_type_flag set"];
    end_of_cast_type_flag <- true

  method clear_end_of_cast_type_flag () =
    if end_of_cast_type_flag then begin
      [%debug_log "end_of_cast_type_flag cleared"];
      end_of_cast_type_flag <- false
    end

  method end_of_cast_type_flag = end_of_cast_type_flag

  method set_end_of_templ_head_flag () =
    [%debug_log "end_of_templ_head_flag set"];
    end_of_templ_head_flag <- true

  method clear_end_of_templ_head_flag () =
    if end_of_templ_head_flag then begin
      [%debug_log "end_of_templ_head_flag cleared"];
      end_of_templ_head_flag <- false
    end

  method end_of_templ_head_flag = end_of_templ_head_flag

  method set_end_of_params_flag () =
    [%debug_log "end_of_params_flag set"];
    end_of_params_flag <- true

  method clear_end_of_params_flag () =
    if end_of_params_flag then begin
      [%debug_log "end_of_params_flag cleared"];
      end_of_params_flag <- false
    end

  method end_of_params_flag = end_of_params_flag

  method set_end_of_req_params_flag () =
    [%debug_log "end_of_req_params_flag set"];
    end_of_req_params_flag <- true

  method clear_end_of_req_params_flag () =
    if end_of_req_params_flag then begin
      [%debug_log "end_of_req_params_flag cleared"];
      end_of_req_params_flag <- false
    end

  method end_of_req_params_flag = end_of_req_params_flag

  method set_decl_stmt_block_flag () =
    [%debug_log "decl_stmt_block_flag set"];
    decl_stmt_block_flag <- true

  method clear_decl_stmt_block_flag () =
    if decl_stmt_block_flag then begin
      [%debug_log "decl_stmt_block_flag cleared"];
      decl_stmt_block_flag <- false
    end

  method decl_stmt_block_flag = decl_stmt_block_flag

  method set_lambda_dtor_flag () =
    [%debug_log "lambda_dtor_flag set"];
    lambda_dtor_flag <- true

  method clear_lambda_dtor_flag () =
    if lambda_dtor_flag then begin
      [%debug_log "lambda_dtor_flag cleared"];
      lambda_dtor_flag <- false
    end

  method lambda_dtor_flag = lambda_dtor_flag

  method set_asm_shader_flag () =
    [%debug_log "asm_shader_flag set"];
    asm_shader_flag <- true

  method clear_asm_shader_flag () =
    if asm_shader_flag then begin
      [%debug_log "asm_shader_flag cleared"];
      asm_shader_flag <- false
    end

  method asm_shader_flag = asm_shader_flag

  method set_dsl_flag () =
    [%debug_log "dsl_flag set"];
    dsl_flag <- true

  method clear_dsl_flag () =
    if dsl_flag then begin
      [%debug_log "dsl_flag cleared"];
      dsl_flag <- false
    end

  method dsl_flag = dsl_flag

  method enter_pp_ifx_d () =
    [%debug_log "entering pp_ifx_d"];
    pp_ifx_d_level <- pp_ifx_d_level + 1

  method exit_pp_ifx_d () =
    if pp_ifx_d_level > 0 then begin
      [%debug_log "exiting pp_ifx_d"];
      pp_ifx_d_level <- pp_ifx_d_level - 1
    end

  method pp_ifx_d_level = pp_ifx_d_level
  method pp_ifx_d_flag = pp_ifx_d_level > 0

  method set_objc_class_interface_flag () =
    [%debug_log "objc_class_interface_flag set"];
    objc_class_interface_flag <- true

  method clear_objc_class_interface_flag () =
    if objc_class_interface_flag then begin
      [%debug_log "objc_class_interface_flag cleared"];
      objc_class_interface_flag <- false
    end

  method objc_class_interface_flag = objc_class_interface_flag

  method set_objc_protocol_decl_flag () =
    [%debug_log "objc_protocol_decl_flag set"];
    objc_protocol_decl_flag <- true

  method clear_objc_protocol_decl_flag () =
    if objc_protocol_decl_flag then begin
      [%debug_log "objc_protocol_decl_flag cleared"];
      objc_protocol_decl_flag <- false
    end

  method objc_protocol_decl_flag = objc_protocol_decl_flag

  method set_objc_class_flag () =
    [%debug_log "objc_class_flag set"];
    objc_class_flag <- true

  method clear_objc_class_flag () =
    if objc_class_flag then begin
      [%debug_log "objc_class_flag cleared"];
      objc_class_flag <- false
    end

  method objc_class_flag = objc_class_flag

  method enter_objc_message_expr () =
    [%debug_log "entering objc_message_expr"];
    objc_message_expr_level <- objc_message_expr_level + 1

  method exit_objc_message_expr () =
    if objc_message_expr_level > 0 then begin
      [%debug_log "exiting objc_message_expr"];
      objc_message_expr_level <- objc_message_expr_level - 1
    end

  method objc_message_expr_level = objc_message_expr_level
  method in_objc_message_expr = objc_message_expr_level > 0

  method set_objc_block_flag () =
    [%debug_log "objc_block_flag set"];
    objc_block_flag <- true

  method clear_objc_block_flag () =
    if objc_block_flag then begin
      [%debug_log "objc_block_flag cleared"];
      objc_block_flag <- false
    end

  method objc_block_flag = objc_block_flag

  method set_objc_sel_flag () =
    [%debug_log "objc_sel_flag set"];
    objc_sel_flag <- true

  method clear_objc_sel_flag () =
    if objc_sel_flag then begin
      [%debug_log "objc_sel_flag cleared"];
      objc_sel_flag <- false
    end

  method objc_sel_flag = objc_sel_flag

  method set_objc_meth_sel_flag () =
    [%debug_log "objc_meth_sel_flag set"];
    objc_meth_sel_flag <- true

  method clear_objc_meth_sel_flag () =
    if objc_meth_sel_flag then begin
      [%debug_log "objc_meth_sel_flag cleared"];
      objc_meth_sel_flag <- false
    end

  method objc_meth_sel_flag = objc_meth_sel_flag

  method set_objc_meth_decl_flag () =
    [%debug_log "objc_meth_decl_flag set"];
    objc_meth_decl_flag <- true

  method clear_objc_meth_decl_flag () =
    if objc_meth_decl_flag then begin
      [%debug_log "objc_meth_decl_flag cleared"];
      objc_meth_decl_flag <- false
    end

  method objc_meth_decl_flag = objc_meth_decl_flag

  method set_objc_superclass_flag () =
    [%debug_log "objc_superclass_flag set"];
    objc_superclass_flag <- true

  method clear_objc_superclass_flag () =
    if objc_superclass_flag then begin
      [%debug_log "objc_superclass_flag cleared"];
      objc_superclass_flag <- false
    end

  method objc_superclass_flag = objc_superclass_flag

  method set_objc_cat_flag () =
    [%debug_log "objc_cat_flag set"];
    objc_cat_flag <- true

  method clear_objc_cat_flag () =
    if objc_cat_flag then begin
      [%debug_log "objc_cat_flag cleared"];
      objc_cat_flag <- false
    end

  method objc_cat_flag = objc_cat_flag

  method set_objc_protocol_ref_flag () =
    [%debug_log "objc_protocol_ref_flag set"];
    objc_protocol_ref_flag <- true

  method clear_objc_protocol_ref_flag () =
    if objc_protocol_ref_flag then begin
      [%debug_log "objc_protocol_ref_flag cleared"];
      objc_protocol_ref_flag <- false
    end

  method objc_protocol_ref_flag = objc_protocol_ref_flag

  method set_dtor_flag () =
    [%debug_log "dtor_flag set"];
    dtor_flag <- true

  method clear_dtor_flag () =
    if dtor_flag then begin
      [%debug_log "dtor_flag cleared"];
      dtor_flag <- false
    end

  method dtor_flag = dtor_flag

  method set_pp_func_body_odd_flag () =
    [%debug_log "pp_func_body_odd_flag set"];
    pp_func_body_odd_flag <- true

  method clear_pp_func_body_odd_flag () =
    if pp_func_body_odd_flag then begin
      [%debug_log "pp_func_body_odd_flag cleared"];
      pp_func_body_odd_flag <- false
    end

  method pp_func_body_odd_flag = pp_func_body_odd_flag

  method set_class_name_flag () =
    [%debug_log "class_name_flag set"];
    class_name_flag <- true

  method clear_class_name_flag () =
    if class_name_flag then begin
      [%debug_log "class_name_flag cleared"];
      class_name_flag <- false
    end

  method class_name_flag = class_name_flag

  method set_cast_head_flag () =
    [%debug_log "cast_head_flag set"];
    cast_head_flag <- true

  method clear_cast_head_flag () =
    if cast_head_flag then begin
      [%debug_log "cast_head_flag cleared"];
      cast_head_flag <- false
    end

  method cast_head_flag = cast_head_flag

  method set_broken_flag () =
    [%debug_log "broken_flag set"];
    broken_flag <- true

  method clear_broken_flag () =
    if broken_flag then begin
      [%debug_log "broken_flag cleared"];
      broken_flag <- false
    end

  method broken_flag = broken_flag

  method set_ns_alias_flag () =
    [%debug_log "ns_alias_flag set"];
    ns_alias_flag <- true

  method clear_ns_alias_flag () =
    if ns_alias_flag then begin
      [%debug_log "ns_alias_flag cleared"];
      ns_alias_flag <- false
    end

  method ns_alias_flag = ns_alias_flag

  method set_end_of_objc_meth_sel_flag () =
    [%debug_log "end_of_objc_meth_sel_flag set"];
    end_of_objc_meth_sel_flag <- true

  method clear_end_of_objc_meth_sel_flag () =
    if end_of_objc_meth_sel_flag then begin
      [%debug_log "end_of_objc_meth_sel_flag cleared"];
      end_of_objc_meth_sel_flag <- false
    end

  method end_of_objc_meth_sel_flag = end_of_objc_meth_sel_flag

  method set_end_of_objc_meth_type_flag () =
    [%debug_log "end_of_objc_meth_type_flag set"];
    end_of_objc_meth_type_flag <- true

  method clear_end_of_objc_meth_type_flag () =
    if end_of_objc_meth_type_flag then begin
      [%debug_log "end_of_objc_meth_type_flag cleared"];
      end_of_objc_meth_type_flag <- false
    end

  method end_of_objc_meth_type_flag = end_of_objc_meth_type_flag

  method set_end_of_objc_property_attrs_decl_flag () =
    [%debug_log "end_of_objc_property_attrs_decl_flag set"];
    end_of_objc_property_attrs_decl_flag <- true

  method clear_end_of_objc_property_attrs_decl_flag () =
    if end_of_objc_property_attrs_decl_flag then begin
      [%debug_log "end_of_objc_property_attrs_decl_flag cleared"];
      end_of_objc_property_attrs_decl_flag <- false
    end

  method end_of_objc_property_attrs_decl_flag = end_of_objc_property_attrs_decl_flag

  method set_end_of_objc_protocol_ref_list_flag () =
    [%debug_log "end_of_objc_protocol_ref_list_flag set"];
    end_of_objc_protocol_ref_list_flag <- true

  method clear_end_of_objc_protocol_ref_list_flag () =
    if end_of_objc_protocol_ref_list_flag then begin
      [%debug_log "end_of_objc_protocol_ref_list_flag cleared"];
      end_of_objc_protocol_ref_list_flag <- false
    end

  method end_of_objc_protocol_ref_list_flag = end_of_objc_protocol_ref_list_flag

  method set_end_of_decl_spec_macro_call_flag () =
    [%debug_log "end_of_decl_spec_macro_call_flag set"];
    end_of_decl_spec_macro_call_flag <- true

  method clear_end_of_decl_spec_macro_call_flag () =
    if end_of_decl_spec_macro_call_flag then begin
      [%debug_log "end_of_decl_spec_macro_call_flag cleared"];
      end_of_decl_spec_macro_call_flag <- false
    end

  method end_of_decl_spec_macro_call_flag = end_of_decl_spec_macro_call_flag

  method set_end_of_attr_macro_call_flag () =
    [%debug_log "end_of_attr_macro_call_flag set"];
    end_of_attr_macro_call_flag <- true

  method clear_end_of_attr_macro_call_flag () =
    if end_of_attr_macro_call_flag then begin
      [%debug_log "end_of_attr_macro_call_flag cleared"];
      end_of_attr_macro_call_flag <- false
    end

  method end_of_attr_macro_call_flag = end_of_attr_macro_call_flag

  method set_end_of_type_macro_call_flag () =
    [%debug_log "end_of_type_macro_call_flag set"];
    end_of_type_macro_call_flag <- true

  method clear_end_of_type_macro_call_flag () =
    if end_of_type_macro_call_flag then begin
      [%debug_log "end_of_type_macro_call_flag cleared"];
      end_of_type_macro_call_flag <- false
    end

  method end_of_type_macro_call_flag = end_of_type_macro_call_flag

  method set_str_flag () =
    [%debug_log "str_flag set"];
    str_flag <- true

  method clear_str_flag () =
    if str_flag then begin
      [%debug_log "str_flag cleared"];
      str_flag <- false
    end

  method str_flag = str_flag

  method set_ty_param_rhs_flag () =
    [%debug_log "ty_param_rhs_flag set"];
    ty_param_rhs_flag <- true

  method clear_ty_param_rhs_flag () =
    if ty_param_rhs_flag then begin
      [%debug_log "ty_param_rhs_flag cleared"];
      ty_param_rhs_flag <- false
    end

  method ty_param_rhs_flag = ty_param_rhs_flag

  method set_end_of_if_head_flag () =
    [%debug_log "end_of_if_head_flag set"];
    end_of_if_head_flag <- true

  method clear_end_of_if_head_flag () =
    if end_of_if_head_flag then begin
      [%debug_log "end_of_if_head_flag cleared"];
      end_of_if_head_flag <- false
    end

  method end_of_if_head_flag = end_of_if_head_flag

  method set_trailing_retty_flag () =
    [%debug_log "trailing_retty_flag set"];
    trailing_retty_flag <- true

  method clear_trailing_retty_flag () =
    if trailing_retty_flag then begin
      [%debug_log "trailing_retty_flag cleared"];
      trailing_retty_flag <- false
    end

  method trailing_retty_flag = trailing_retty_flag

  method set_end_of_id_macro_call_flag () =
    [%debug_log "end_of_id_macro_call_flag set"];
    end_of_id_macro_call_flag <- true

  method clear_end_of_id_macro_call_flag () =
    if end_of_id_macro_call_flag then begin
      [%debug_log "end_of_id_macro_call_flag cleared"];
      end_of_id_macro_call_flag <- false
    end

  method end_of_id_macro_call_flag = end_of_id_macro_call_flag

  method set_end_of_literal_macro_call_flag () =
    [%debug_log "end_of_literal_macro_call_flag set"];
    end_of_literal_macro_call_flag <- true

  method clear_end_of_literal_macro_call_flag () =
    if end_of_literal_macro_call_flag then begin
      [%debug_log "end_of_literal_macro_call_flag cleared"];
      end_of_literal_macro_call_flag <- false
    end

  method end_of_literal_macro_call_flag = end_of_literal_macro_call_flag

  method set_end_of_decltype_flag () =
    [%debug_log "end_of_decltype_flag set"];
    end_of_decltype_flag <- true

  method clear_end_of_decltype_flag () =
    if end_of_decltype_flag then begin
      [%debug_log "end_of_decltype_flag cleared"];
      end_of_decltype_flag <- false
    end

  method end_of_decltype_flag = end_of_decltype_flag

  method set_end_of_noptr_dtor_paren_flag () =
    [%debug_log "end_of_noptr_dtor_paren_flag set"];
    end_of_noptr_dtor_paren_flag <- true

  method clear_end_of_noptr_dtor_paren_flag () =
    if end_of_noptr_dtor_paren_flag then begin
      [%debug_log "end_of_noptr_dtor_paren_flag cleared"];
      end_of_noptr_dtor_paren_flag <- false
    end

  method end_of_noptr_dtor_paren_flag = end_of_noptr_dtor_paren_flag

  method set_end_of_sizeof_flag () =
    [%debug_log "end_of_sizeof_flag set"];
    end_of_sizeof_flag <- true

  method clear_end_of_sizeof_flag () =
    if end_of_sizeof_flag then begin
      [%debug_log "end_of_sizeof_flag cleared"];
      end_of_sizeof_flag <- false
    end

  method end_of_sizeof_flag = end_of_sizeof_flag

  method set_end_of_handler_head_flag () =
    [%debug_log "end_of_handler_head_flag set"];
    end_of_handler_head_flag <- true

  method clear_end_of_handler_head_flag () =
    if end_of_handler_head_flag then begin
      [%debug_log "end_of_handler_head_flag cleared"];
      end_of_handler_head_flag <- false
    end

  method end_of_handler_head_flag = end_of_handler_head_flag

  method set_end_of_broken_decl_section_flag () =
    [%debug_log "end_of_broken_decl_section_flag set"];
    end_of_broken_decl_section_flag <- true

  method clear_end_of_broken_decl_section_flag () =
    if end_of_broken_decl_section_flag then begin
      [%debug_log "end_of_broken_decl_section_flag cleared"];
      end_of_broken_decl_section_flag <- false
    end

  method end_of_broken_decl_section_flag = end_of_broken_decl_section_flag

  method set_end_of_label_flag () =
    [%debug_log "end_of_label_flag set"];
    end_of_label_flag <- true

  method clear_end_of_label_flag () =
    if end_of_label_flag then begin
      [%debug_log "end_of_label_flag cleared"];
      end_of_label_flag <- false
    end

  method end_of_label_flag = end_of_label_flag

  method set_end_of_mem_initializer_flag () =
    [%debug_log "end_of_mem_initializer_flag set"];
    end_of_mem_initializer_flag <- true

  method clear_end_of_mem_initializer_flag () =
    if end_of_mem_initializer_flag then begin
      [%debug_log "end_of_mem_initializer_flag cleared"];
      end_of_mem_initializer_flag <- false
    end

  method end_of_mem_initializer_flag = end_of_mem_initializer_flag

  method set_attr_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "attr_flag set"];
      attr_flag <- true
    end

  method clear_attr_flag () =
    if attr_flag then begin
      [%debug_log "attr_flag cleared"];
      attr_flag <- false
    end

  method attr_flag = attr_flag

  method set_linkage_spec_flag () =
    [%debug_log "linkage_spec_flag set"];
    linkage_spec_flag <- true

  method clear_linkage_spec_flag () =
    if linkage_spec_flag then begin
      [%debug_log "linkage_spec_flag cleared"];
      linkage_spec_flag <- false
    end

  method linkage_spec_flag = linkage_spec_flag

  method set_condition_flag () =
    [%debug_log "condition_flag set"];
    condition_flag <- true

  method clear_condition_flag () =
    if condition_flag then begin
      [%debug_log "condition_flag cleared"];
      condition_flag <- false
    end

  method condition_flag = condition_flag

  method set_mem_acc_flag () =
    [%debug_log "mem_acc_flag set"];
    mem_acc_flag <- true

  method clear_mem_acc_flag () =
    if mem_acc_flag then begin
      [%debug_log "mem_acc_flag cleared"];
      mem_acc_flag <- false
    end

  method mem_acc_flag = mem_acc_flag

  method set_alias_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "alias_flag set"];
      alias_flag <- true
    end

  method clear_alias_flag () =
    if alias_flag then begin
      [%debug_log "alias_flag cleared"];
      alias_flag <- false
    end

  method alias_flag = alias_flag

  method set_using_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "using_flag set"];
      using_flag <- true
    end

  method clear_using_flag () =
    if using_flag then begin
      [%debug_log "using_flag cleared"];
      using_flag <- false
    end

  method using_flag = using_flag

  method set_mock_qualifier_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "mock_qualifier_flag set"];
      mock_qualifier_flag <- true
    end

  method clear_mock_qualifier_flag () =
    if mock_qualifier_flag then begin
      [%debug_log "mock_qualifier_flag cleared"];
      mock_qualifier_flag <- false
    end

  method mock_qualifier_flag = mock_qualifier_flag

  method set_end_of_str_section_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "end_of_str_section_flag set"];
      end_of_str_section_flag <- true
    end

  method clear_end_of_str_section_flag () =
    if end_of_str_section_flag then begin
      [%debug_log "end_of_str_section_flag cleared"];
      end_of_str_section_flag <- false
    end

  method end_of_str_section_flag = end_of_str_section_flag

  method set_new_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "new_flag set"];
      new_flag <- true
    end

  method clear_new_flag () =
    if new_flag then begin
      [%debug_log "new_flag cleared"];
      new_flag <- false
    end

  method new_flag = new_flag

  method set_concept_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "concept_flag set"];
      concept_flag <- true
    end

  method clear_concept_flag () =
    if concept_flag then begin
      [%debug_log "concept_flag cleared"];
      concept_flag <- false
    end

  method concept_flag = concept_flag

  method set_requires_clause_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "requires_clause_flag set"];
      requires_clause_flag <- true
    end

  method clear_requires_clause_flag () =
    if requires_clause_flag then begin
      [%debug_log "requires_clause_flag cleared"];
      requires_clause_flag <- false
    end

  method requires_clause_flag = requires_clause_flag

  method set_rhs_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "rhs_flag set"];
      rhs_flag <- true
    end

  method clear_rhs_flag () =
    if rhs_flag then begin
      [%debug_log "rhs_flag cleared"];
      rhs_flag <- false
    end

  method rhs_flag = rhs_flag

  method set_eq_init_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "eq_init_flag set"];
      eq_init_flag <- true
    end

  method clear_eq_init_flag () =
    if eq_init_flag then begin
      [%debug_log "eq_init_flag cleared"];
      eq_init_flag <- false
    end

  method eq_init_flag = eq_init_flag

  method enter_sizeof_ty () =
    [%debug_log "entering sizeof_ty"];
    sizeof_ty_flag <- true

  method exit_sizeof_ty () =
    if sizeof_ty_flag then begin
      [%debug_log "exiting sizeof_ty"];
      sizeof_ty_flag <- false
    end

  method sizeof_ty_flag = sizeof_ty_flag

  method enter_lambda_intro () =
    [%debug_log "entering lambda_intro"];
    lambda_intro_flag <- true

  method exit_lambda_intro () =
    if lambda_intro_flag then begin
      [%debug_log "exiting lambda_intro"];
      lambda_intro_flag <- false
    end

  method lambda_intro_flag = lambda_intro_flag

  method enter_ctor_init () =
    [%debug_log "entering ctor_init"];
    ctor_init_flag <- true

  method exit_ctor_init () =
    if ctor_init_flag then begin
      [%debug_log "exiting ctor_init"];
      ctor_init_flag <- false
    end

  method ctor_init_flag = ctor_init_flag

  method enter_stmts () =
    [%debug_log "entering stmts"];
    stmts_flag <- true

  method exit_stmts () =
    if stmts_flag then begin
      [%debug_log "exiting stmts"];
      stmts_flag <- false
    end

  method stmts_flag = stmts_flag

  method enter_base_clause () =
    [%debug_log "entering base_clause"];
    base_clause_flag <- true

  method exit_base_clause () =
    if base_clause_flag then begin
      [%debug_log "exiting base_clause"];
      base_clause_flag <- false
    end

  method base_clause_flag = base_clause_flag

  method enter_asm plv =
    [%debug_log "entering asm"];
    asm_paren_level <- plv;
    asm_flag <- true

  method exit_asm () =
    if asm_flag then begin
      [%debug_log "exiting asm"];
      asm_paren_level <- 0;
      asm_flag <- false
    end

  method asm_flag = asm_flag
  method asm_paren_level = asm_paren_level

  method enter_braced_asm () =
    [%debug_log "entering braced_asm"];
    braced_asm_flag <- true

  method exit_braced_asm () =
    if braced_asm_flag then begin
      [%debug_log "exiting braced_asm"];
      braced_asm_flag <- false
    end

  method braced_asm_flag = braced_asm_flag

  method enter_asm_block () =
    [%debug_log "entering asm_block"];
    asm_block_flag <- true

  method exit_asm_block () =
    if asm_block_flag then begin
      [%debug_log "exiting asm_block"];
      asm_block_flag <- false
    end

  method asm_block_flag = asm_block_flag

  method enter_enum_head () =
    [%debug_log "entering enum_head"];
    enum_head_flag <- true

  method exit_enum_head () =
    if enum_head_flag then begin
      [%debug_log "exiting enum_head"];
      enum_head_flag <- false
    end

  method enum_head_flag = enum_head_flag

  method enter_ty_param () =
    [%debug_log "entering ty_param"];
    ty_param_flag <- true

  method exit_ty_param () =
    if ty_param_flag then begin
      [%debug_log "exiting ty_param"];
      ty_param_flag <- false
    end

  method ty_param_flag = ty_param_flag

  method enter_exec_config () =
    [%debug_log "entering exec_config"];
    exec_config_flag <- true

  method exit_exec_config () =
    if exec_config_flag then begin
      [%debug_log "exiting exec_config"];
      exec_config_flag <- false
    end

  method exec_config_flag = exec_config_flag

  method enter_decltype () =
    [%debug_log "entering decltype"];
    decltype_flag <- true

  method exit_decltype () =
    if decltype_flag then begin
      [%debug_log "exiting decltype"];
      decltype_flag <- false
    end

  method decltype_flag = decltype_flag

  method enter_alignas () =
    [%debug_log "entering alignas"];
    alignas_flag <- true

  method exit_alignas () =
    if alignas_flag then begin
      [%debug_log "exiting alignas"];
      alignas_flag <- false
    end

  method alignas_flag = alignas_flag

  method enter_alignof () =
    [%debug_log "entering alignof"];
    alignof_flag <- true

  method exit_alignof () =
    if alignof_flag then begin
      [%debug_log "exiting alignof"];
      alignof_flag <- false
    end

  method alignof_flag = alignof_flag

  method enter_noexcept () =
    [%debug_log "entering noexcept"];
    noexcept_flag <- true

  method exit_noexcept () =
    if noexcept_flag then begin
      [%debug_log "exiting noexcept"];
      noexcept_flag <- false
    end

  method noexcept_flag = noexcept_flag

  method enter_macro_arg () =
    [%debug_log "entering macro_arg"];
    macro_arg_level <- macro_arg_level + 1

  method exit_macro_arg () =
    [%debug_log "exiting macro_arg"];
    macro_arg_level <- macro_arg_level - 1

  method macro_arg_level = macro_arg_level
  method macro_arg_flag = macro_arg_level > 0

  method enter_pp_line () =
    [%debug_log "entering pp_line"];
    pp_line_flag <- true;
    pp_line_rel_brace_level <- 0

  method exit_pp_line () =
    if pp_line_flag then begin
      [%debug_log "exiting pp_line"];
      pp_line_flag <- false;
      pp_line_rel_brace_level <- 0
    end

  method pp_line_flag = pp_line_flag

  method enter_pp_if () =
    [%debug_log "entering pp_if"];
    pp_if_flag <- true

  method exit_pp_if () =
    [%debug_log "exiting pp_if"];
    pp_if_flag <- false

  method pp_if_flag = pp_if_flag

  method enter_pp_ifdef () =
    [%debug_log "entering pp_ifdef"];
    pp_ifdef_flag <- true

  method exit_pp_ifdef () =
    [%debug_log "exiting pp_ifdef"];
    pp_ifdef_flag <- false

  method pp_ifdef_flag = pp_ifdef_flag

  method enter_pp_group () =
    [%debug_log "entering:\n%s" self#bracket_stack_to_string];
    Stack.push (Stack.copy self#bracket_stack) bracket_stack_stack

  method exit_pp_group ?(last=false) () =
    [%debug_log "exiting (last=%B):\n%s" last self#bracket_stack_to_string];
    let len = Stack.length bracket_stack_stack in
    if last && len = 1 then
      ()
    else if len > 1 then begin
      let s = Stack.pop bracket_stack_stack in
      if last then begin
        let _ = Stack.pop bracket_stack_stack in
        Stack.push s bracket_stack_stack
      end
    end;
    [%debug_log "after:\n%s" self#bracket_stack_to_string];
    ()

  method enter_pp_if_section ln c sc cond =
    let brace_lv = self#brace_level in
    let paren_lv = self#paren_level in
    let templ_param_arg_lv = self#templ_param_arg_level in
    let info = I.make_pp_if_section_info ln c sc brace_lv paren_lv templ_param_arg_lv cond in
    [%debug_log "entering pp_if_section %s" (I.pp_if_section_info_to_string info)];
    Stack.push info pp_if_section_stack;
    Stack.push (ref 0) pp_group_rel_brace_level_stack;
    self#enter_pp_group()

  method exit_pp_if_section ?(odd=false) () =
    [%debug_log "exiting pp_if_section (odd=%B)..." odd];
    let info = Stack.pop pp_if_section_stack in
    last_pp_if_section_info <- info;
    let _ =
      try
        Stack.pop pp_group_rel_brace_level_stack
      with _ -> ref 0
    in
    if odd && self#pp_odd_if_section_level > 0 then
      (Stack.top odd_brace_lv_stack).o_ini_lv <- info.i_brace_level;
    [%debug_log "pp_if_section exited %s" (I.pp_if_section_info_to_string info)];
    self#exit_pp_group ~last:true ()

  method pp_if_section_stack = pp_if_section_stack

  method pp_if_section_level = Stack.length pp_if_section_stack
  method pp_if_section_top_info = Stack.top pp_if_section_stack

  method last_pp_if_section_info = last_pp_if_section_info

  method pp_if_section_nth_info nth =
    match nth with
    | 1 -> self#pp_if_section_top_info
    | n when n < 0 -> invalid_arg "Cpp.Parser_aux.pstat#pp_if_section_nth_info"
    | _ ->
        let count = ref 0 in
        let res = ref None in
        begin
          try
            Stack.iter
              (fun x ->
                if !count = nth - 1 then begin
                  res := Some x;
                  raise Exit
                end;
                incr count
              ) pp_if_section_stack
          with
            Exit -> ()
        end;
        match !res with
        | Some x -> x
        | _ -> raise Stack.Empty

  method pp_if_section_rel_brace_level =
    let lv =
      try
        self#brace_level - (Stack.top pp_if_section_stack).i_brace_level
      with
        _ -> 0
    in
    [%debug_log "%d" lv];
    lv

  method pp_odd_if_section_rel_brace_level =
    let lv =
      try
        self#brace_level - (Stack.top odd_brace_lv_stack).o_ini_lv
      with
        _ -> 0
    in
    [%debug_log "%d" lv];
    lv

  method pp_if_section_rel_paren_level =
    let lv = self#paren_level - (Stack.top pp_if_section_stack).i_paren_level in
    [%debug_log "%d" lv];
    lv

  method pp_top_label = (Stack.top pp_if_section_stack).i_label

  method set_pp_top_label lab =
    try
      (Stack.top pp_if_section_stack).i_label <- lab
    with
      Stack.Empty -> ()

  method pp_if_section_flag = not (Stack.is_empty pp_if_section_stack)

  method add_pp_elif () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let top = Stack.top pp_if_section_stack in
      top.i_pp_elif <- self#brace_level::top.i_pp_elif
    end

  method pp_elif_flag =
    try
      (Stack.top pp_if_section_stack).i_pp_elif != []
    with
      Stack.Empty -> false

  method add_pp_else () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      (Stack.top pp_if_section_stack).i_pp_else <- Some self#brace_level
    end

  method clear_lbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_lbraces <- 0
    end

  method set_lbrace_info x =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_lbraces <- x
    end

  method get_lbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_lbraces
    end
    else
      0

  method incr_lbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_lbraces <- info.i_lbraces + 1
    end

  method decr_lbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_lbraces <- info.i_lbraces - 1
    end

  method clear_rbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_rbraces <- 0
    end

  method set_rbrace_info x =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_rbraces <- x
    end

  method get_rbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_rbraces
    end
    else
      0

  method incr_rbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_rbraces <- info.i_rbraces + 1
    end

  method decr_rbrace_info () =
    let lv = self#pp_if_section_level in
    [%debug_log "pp_if_section_level=%d" lv];
    if lv > 0 then begin
      let info = Stack.top pp_if_section_stack in
      info.i_rbraces <- info.i_rbraces - 1
    end

  method set_odd_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_odd <- true

  method set_odd_canceled_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_odd_canceled <- true

  method get_odd_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_odd
    with
      _ -> false

  method set_broken_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_broken <- true

  method get_broken_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_broken
    with
      _ -> false

  method set_paren_closing_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_paren_closing <- true

  method get_paren_closing_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_paren_closing
    with
      _ -> false

  method set_brace_paren_closing_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_brace_paren_closing <- true

  method get_brace_paren_closing_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_brace_paren_closing
    with
      _ -> false

  method set_brace_closing_info n =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_brace_closing <- n

  method incr_brace_closing_info() =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_brace_closing <- info.i_brace_closing + 1

  method get_brace_closing_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_brace_closing
    with
      _ -> 0

  method set_brace_opening_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_brace_opening <- true

  method clear_brace_opening_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_brace_opening <- false

  method get_brace_opening_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_brace_opening
    with
      _ -> false

  method set_func_head_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_func_head <- true

  method get_func_head_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_func_head
    with
      _ -> false

  method set_broken_func_head_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_broken_func_head <- true

  method get_broken_func_head_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_broken_func_head
    with
      _ -> false

  method set_templ_closing_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_templ_closing <- true

  method get_templ_closing_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_templ_closing
    with
      _ -> false

  method set_func_body_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_func_body <- true

  method get_func_body_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_func_body
    with
      _ -> false

  method set_semicolon_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_semicolon <- true

  method clear_semicolon_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_semicolon <- false

  method get_semicolon_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_semicolon
    with
      _ -> false

  method set_comma_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_comma <- true

  method get_comma_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_comma
    with
      _ -> false

  method set_cond_expr_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_cond_expr <- true

  method get_cond_expr_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_cond_expr
    with
      _ -> false

  method set_cond_expr__info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_cond_expr_ <- true

  method get_cond_expr__info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_cond_expr_
    with
      _ -> false

  method set_asm_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_asm <- true

  method get_asm_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_asm
    with
      _ -> false

  method set_begin_asm_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_begin_asm <- true

  method get_begin_asm_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_begin_asm
    with
      _ -> false

  method set_lack_of_dtor_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_lack_of_dtor <- true

  method get_lack_of_dtor_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_lack_of_dtor
    with
      _ -> false

  method set_class_brace_opening_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_class_brace_opening <- true

  method get_class_brace_opening_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_class_brace_opening
    with
      _ -> false

  method set_follows_comma_info () =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_follows_comma <- true

  method get_follows_comma_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_follows_comma
    with
      _ -> false

  method get_pp_if_compl_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_pp_if_compl
    with
      _ -> {c_brace=0;c_paren=0}

  method get_pp_if_compl_brace_info () =
    (self#get_pp_if_compl_info()).c_brace

  method get_pp_if_compl_paren_info () =
    (self#get_pp_if_compl_info()).c_paren

  method reset_pp_if_compl_info () =
    try
      let info = Stack.top pp_if_section_stack in
      let c = info.i_pp_if_compl in
      c.c_brace <- 0;
      c.c_paren <- 0
    with
      _ -> ()

  method set_cond_sub_info x =
    let info = Stack.top pp_if_section_stack in
    [%debug_log "%s" (I.pp_if_section_info_to_string info)];
    info.i_cond_sub <- x

  method get_cond_sub_info () =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_cond_sub
    with
      _ -> PP_NONE

  method pp_else_flag =
    try
      (Stack.top pp_if_section_stack).i_pp_else != None
    with
      Stack.Empty -> false

  method alt_pp_branch_flag =
    try
      let info = Stack.top pp_if_section_stack in
      info.i_pp_elif != [] || info.i_pp_else != None
    with
      Stack.Empty -> false

  method check_pp_branch_cond f =
    try
      let info = Stack.top pp_if_section_stack in
      f info.i_cond
    with
      Stack.Empty -> false

  method bracket_stack = Stack.top bracket_stack_stack

  method bracket_stack_top = Stack.top self#bracket_stack

  method bracket_stack_2nd = stack_2nd self#bracket_stack

  method bracket_stack_to_string =
    let buf = Buffer.create 0 in
    Stack.iter
      (fun bk ->
        Buffer.add_string buf (bracket_kind_to_string bk);
        Buffer.add_string buf "\n"
      ) self#bracket_stack;
    Buffer.contents buf

  method _open_bracket bk =
    [%debug_log "opening %s" (bracket_kind_to_string bk)];
    Stack.push bk self#bracket_stack

  method __close_bracket () =
    try
      let bk = Stack.pop self#bracket_stack in
      [%debug_log "closed %s" (bracket_kind_to_string bk)];
      begin
        try
          [%debug_log "top changed to %s" (bracket_kind_to_string (self#bracket_stack_top))]
        with _ -> ()
      end;
      match bk with
      | BK_BRACE i_opt -> i_opt
      | _ -> None
    with
      Stack.Empty -> begin
        [%debug_log "stack empty"];
        None
      end

  method _close_bracket () =
    let _ = self#__close_bracket() in
    ()

  method open_paren k =
    [%debug_log "opening paren (%s)" (paren_kind_to_string k)];
    Stack.push k paren_stack;
    self#_open_bracket (BK_PAREN k)

  method open_paren_normal ?(kind=PKS_NONE) () =
    self#open_paren (PK_NORMAL kind);

  method open_paren_arg () =
    self#open_paren PK_ARG

  method close_paren ?(pseudo=false) () =
    [%debug_log "closing paren (pseudo=%B)..." pseudo];
    let k = Stack.pop paren_stack in
    let _ = k in
    [%debug_log "paren closed (%s)" (paren_kind_to_string k)];
    begin
      try
        [%debug_log "top became %s" (paren_kind_to_string (self#paren_stack_top))]
      with _ -> ()
    end;
    if not pseudo then
      self#_close_bracket()

  method paren_stack_to_string =
    let buf = Buffer.create 0 in
    Stack.iter
      (fun pk ->
        Buffer.add_string buf (paren_kind_to_string pk);
        Buffer.add_string buf "\n"
      ) paren_stack;
    Buffer.contents buf

  method paren_level = Stack.length paren_stack
  method paren_stack_top = Stack.top paren_stack

  method at_ini_brace =
    try
      match self#bracket_stack_top with
      | BK_INI_BRACE -> true
      | _ -> false
    with
      _ -> false

  method at_ini_brace_2 =
    try
      match self#bracket_stack_2nd with
      | BK_INI_BRACE -> true
      | _ -> false
    with
      _ -> false

  method at_class_brace =
    try
      match self#bracket_stack_top with
      | BK_CLASS_BRACE -> true
      | _ -> false
    with
      _ -> false

  method at_brace =
    try
      match self#bracket_stack_top with
      | BK_BRACE _ -> true
      | _ -> false
    with
      _ -> false

  method at_brace_2 =
    try
      match self#bracket_stack_2nd with
      | BK_BRACE _ -> true
      | _ -> false
    with
      _ -> false

  method at_req_brace =
    try
      match self#bracket_stack_top with
      | BK_REQ_BRACE -> true
      | _ -> false
    with
      _ -> false

  method at_objc_msg =
    try
      match self#bracket_stack_top with
      | BK_OBJC_MSG -> true
      | _ -> false
    with
      _ -> false

  method at_attr =
    try
      match self#bracket_stack_top with
      | BK_ATTR -> true
      | _ -> false
    with
      _ -> false

  method at_lam_intr =
    try
      match self#bracket_stack_top with
      | BK_LAM_INTR -> true
      | _ -> false
    with
      _ -> false

  method at_subscr =
    try
      match self#bracket_stack_top with
      | BK_SUBSCR -> true
      | _ -> false
    with
      _ -> false

  method at_templ_arg =
    try
      match self#bracket_stack_top with
      | BK_TEMPL_ARG _ -> true
      | _ -> false
    with
      _ -> false

  method at_templ_arg_2 =
    try
      match self#bracket_stack_2nd with
      | BK_TEMPL_ARG _ -> true
      | _ -> false
    with
      _ -> false

  method at_templ_param =
    try
      match self#bracket_stack_top with
      | BK_TEMPL_PARAM _ -> true
      | _ -> false
    with
      _ -> false

  method at_templ_param_2 =
    try
      match self#bracket_stack_2nd with
      | BK_TEMPL_PARAM _ -> true
      | _ -> false
    with
      _ -> false

  method at_templ_param_arg_expr_2 =
    try
      match self#bracket_stack_2nd with
      | BK_TEMPL_PARAM c | BK_TEMPL_ARG c when c.tpac_expr_flag -> true
      | _ -> false
    with
      _ -> false

  method private _at_paren =
    try
      match self#bracket_stack_top with
      | BK_PAREN _ -> true
      | _ -> false
    with
      _ -> true

  method at_arg_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_ARG -> true
      | _ -> false
    with
      _ -> false

  method at_arg_paren_2 =
    try
      match self#bracket_stack_2nd with
      | BK_PAREN PK_ARG -> true
      | _ -> false
    with
      _ -> false

  method at_macro_arg_paren_2 =
    try
      match self#bracket_stack_2nd with
      | BK_PAREN PK_MACRO -> true
      | _ -> false
    with
      _ -> false

  method _arg_paren_flag =
    try
      Stack.iter
        (function
          | PK_ARG -> raise Exit
          | _ -> ()
        ) paren_stack;
      false
    with
      Exit -> true

  method at_ps_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_PS -> true
      | _ -> false
    with
      _ -> false

  method at_type_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_TYPE _ -> true
      | _ -> false
    with
      _ -> false

  method at_type_paren_2 =
    try
      match self#bracket_stack_2nd with
      | BK_PAREN (PK_TYPE _) -> true
      | _ -> false
    with
      _ -> false

  method was_at_type_paren =
    try
      match stack_2nd paren_stack with
      | PK_TYPE _ -> true
      | _ -> false
    with
      _ -> false

  method at_fold_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_FOLD -> true
      | _ -> false
    with
      _ -> false

  method at_fold_paren_2 =
    try
      match self#bracket_stack_2nd with
      | BK_PAREN PK_FOLD -> true
      | _ -> false
    with
      _ -> false

  method at_macro_arg_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_MACRO | PK_SS -> true
      | _ -> false
    with
      _ -> false

  method at_ss_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_SS -> true
      | _ -> false
    with
      _ -> false

  method at_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_NORMAL _ -> true
      | _ -> false
    with
      _ -> false

  method at_paren_2 =
    try
      match self#bracket_stack_2nd with
      | BK_PAREN PK_NORMAL _ -> true
      | _ -> false
    with
      _ -> false

  method at_if_paren =
    self#_at_paren &&
    try
      match Stack.top paren_stack with
      | PK_NORMAL PKS_IF -> true
      | _ -> false
    with
      _ -> false

  method at_bracket =
    try
      match Stack.top paren_stack with
      | PK_BRACKET -> true
      | _ -> false
    with
      _ -> false

  method change_paren_kind pk =
    try
      let k = Stack.pop paren_stack in
      [%debug_log "%s -> %s" (paren_kind_to_string k) (paren_kind_to_string pk)];
      ignore k;
      Stack.push pk paren_stack
    with _ -> ()

  method get_paren_stack () = Stack.copy paren_stack

  method enter_top_stmts lv =
    [%debug_log "entering top_stmts (%d)" lv];
    Stack.push lv top_stmts_stack

  method exit_top_stmts () =
    [%debug_log "exitsing top_stmts..."];
    let lv = Stack.pop top_stmts_stack in
    let _ = lv in
    [%debug_log "top_stmts exited (%d)" lv]

  method top_stmts_flag =
    Stack.length top_stmts_stack > 0

  method top_stmts_top =
    let lv = Stack.top top_stmts_stack in
    [%debug_log "%d" lv];
    lv

  method enter_templ_param_arg () =
    if not self#dsl_flag then begin
      [%debug_log "entering templ_param_arg"];
      Stack.push self#paren_level templ_param_arg_stack
    end

  method exit_templ_param_arg () =
    if not self#dsl_flag then begin
      [%debug_log "exiting templ_param_arg"];
      let lv = Stack.pop templ_param_arg_stack in
      let _ = lv in
      [%debug_log "templ_param_arg exited (%d)" lv]
    end

  method templ_param_arg_level = Stack.length templ_param_arg_stack
  method templ_param_arg_stack_top = Stack.top templ_param_arg_stack
  method get_templ_param_arg_stack() = Stack.copy templ_param_arg_stack

  method enter_typename () =
    [%debug_log "entering typename"];
    typename_level <- typename_level + 1

  method exit_typename () =
    [%debug_log "exiting typename"];
    typename_level <- typename_level - 1

  method set_typename_level lv = typename_level <- lv
  method reset_typename_level () = typename_level <- 0

  method typename_level = typename_level
  method typename_flag = typename_level > 0

  method enter_braced_init () =
    [%debug_log "entering braced_init"];
    braced_init_level <- braced_init_level + 1

  method exit_braced_init () =
    [%debug_log "exiting braced_init"];
    braced_init_level <- braced_init_level - 1

  method set_braced_init_level lv = braced_init_level <- lv
  method reset_braced_init_level () = braced_init_level <- 0

  method braced_init_level = braced_init_level
  method braced_init_flag = braced_init_level > 0

  method enter__pp_if_section () =
    [%debug_log "entering _pp_if_section"];
    _pp_if_section_level <- _pp_if_section_level + 1

  method exit__pp_if_section () =
    [%debug_log "exiting _pp_if_section"];
    _pp_if_section_level <- _pp_if_section_level - 1

  method set__pp_if_section_level lv = _pp_if_section_level <- lv
  method reset__pp_if_section_level () = _pp_if_section_level <- 0

  method _pp_if_section_level = _pp_if_section_level
  method _pp_if_section_flag = _pp_if_section_level > 0

  method open_brace () =
    [%debug_log "opening brace"];
    Stack.push self#paren_level brace_stack

  method close_brace () =
    [%debug_log "closing brace"];
    let plv = Stack.pop brace_stack in
    let _ = plv in
    [%debug_log "brace closed (%d)" plv]

  method brace_level = Stack.length brace_stack

  method rel_paren_level =
    let lv =
      try
        self#paren_level - (Stack.top brace_stack)
      with
        _ -> 0
    in
    [%debug_log "%d" lv];
    lv

  method open_bracket () =
    [%debug_log "opening bracket"];
    bracket_level <- bracket_level + 1

  method close_bracket () =
    [%debug_log "closing bracket"];
    bracket_level <- bracket_level - 1

  method bracket_level = bracket_level
  method set_bracket_level lv = bracket_level <- lv

  method open_pp_paren () =
    [%debug_log "opening pp_paren"];
    pp_paren_level <- pp_paren_level + 1

  method close_pp_paren () =
    [%debug_log "closing pp_paren"];
    pp_paren_level <- pp_paren_level - 1

  method pp_paren_level = pp_paren_level
  method set_pp_paren_level lv = pp_paren_level <- lv

  method odd_brace_lv_stack_to_string =
    let buf = Buffer.create 0 in
    Stack.iter
      (fun oblv -> Buffer.add_string buf (odd_brace_lv_to_string oblv))
      odd_brace_lv_stack;
    Buffer.contents buf

  method open_odd_brace () =
    [%debug_log "odd_brace_lv_stack=%s" self#odd_brace_lv_stack_to_string];
    [%debug_log "brace_level=%d" self#brace_level];
    Stack.push {o_lv=self#brace_level;o_ini_lv=0} odd_brace_lv_stack

  method close_odd_brace () =
    [%debug_log "odd_brace_lv_stack=%s" self#odd_brace_lv_stack_to_string];
    let oblv = Stack.pop odd_brace_lv_stack in
    [%debug_log "brace_level=%s" (odd_brace_lv_to_string oblv)];
    ignore oblv

  method pp_odd_if_section_level = Stack.length odd_brace_lv_stack

  method odd_brace_level =
    try
      (Stack.top odd_brace_lv_stack).o_lv
    with
      _ -> 0

end (* class pstat *)
]

class dummy_pstat = object
  inherit pstat
  method! reset () = ()
  method! to_string = "<dummy_pstat>"
  method! copy = {<>}
  method! set_brace_level_marker_flag () = ()
  method! clear_brace_level_marker_flag () = ()
  method! brace_level_marker_flag = false
  method! set_brace_level_marker_unbalanced_flag () = ()
  method! clear_brace_level_marker_unbalanced_flag () = ()
  method! brace_level_marker_unbalanced_flag = false
  method! brace_level_marker = 0
  method! incr_brace_level_marker () = ()
  method! decr_brace_level_marker () = ()
  method! canceled_brace_level_marker = 0
  method! set_canceled_brace_level_marker _ = ()
  method! reset_canceled_brace_level_marker () = ()
  method! pp_line_rel_brace_level = 0
  method! incr_pp_line_rel_brace_level () = ()
  method! decr_pp_line_rel_brace_level () = ()
  method! reset_pp_group_rel_brace_level () = ()
  method! incr_pp_group_rel_brace_level () = ()
  method! decr_pp_group_rel_brace_level () = ()
  method! enter_templ_arg _ = ()
  method! exit_templ_arg () = ()
  method! templ_arg_flag = false
  method! ty_templ_id_flag = false
  method! last_ty_templ_id_flag = false
  method! set_for_flag () = ()
  method! clear_for_flag () = ()
  method! set_templ_flag () = ()
  method! clear_templ_flag () = ()
  method! for_flag = false
  method! templ_flag = false
  method! set_start_of_func_body_flag () = ()
  method! clear_start_of_func_body_flag () = ()
  method! start_of_func_body_flag = false
  method! set_end_of_old_param_decl_flag () = ()
  method! clear_end_of_old_param_decl_flag () = ()
  method! end_of_old_param_decl_flag = false
  method! set_old_param_decl_flag () = ()
  method! clear_old_param_decl_flag () = ()
  method! old_param_decl_flag = false
  method! set_end_of_class_spec_flag () = ()
  method! clear_end_of_class_spec_flag () = ()
  method! end_of_class_spec_flag = false
  method! set_end_of_enum_spec_flag () = ()
  method! clear_end_of_enum_spec_flag () = ()
  method! end_of_enum_spec_flag = false
  method! set_end_of_cast_type_flag () = ()
  method! clear_end_of_cast_type_flag () = ()
  method! end_of_cast_type_flag = false
  method! set_end_of_templ_head_flag () = ()
  method! clear_end_of_templ_head_flag () = ()
  method! end_of_templ_head_flag = false
  method! set_end_of_params_flag () = ()
  method! clear_end_of_params_flag () = ()
  method! end_of_params_flag = false
  method! set_end_of_req_params_flag () = ()
  method! clear_end_of_req_params_flag () = ()
  method! end_of_req_params_flag = false
  method! set_decl_stmt_block_flag () = ()
  method! clear_decl_stmt_block_flag () = ()
  method! decl_stmt_block_flag = false
  method! set_lambda_dtor_flag () = ()
  method! clear_lambda_dtor_flag () = ()
  method! lambda_dtor_flag = false
  method! set_asm_shader_flag () = ()
  method! clear_asm_shader_flag () = ()
  method! asm_shader_flag = false
  method! set_dsl_flag () = ()
  method! clear_dsl_flag () = ()
  method! dsl_flag = false
  method! enter_pp_ifx_d () = ()
  method! exit_pp_ifx_d () = ()
  method! pp_ifx_d_level = 0
  method! pp_ifx_d_flag = false
  method! set_objc_class_interface_flag () = ()
  method! clear_objc_class_interface_flag () = ()
  method! objc_class_interface_flag = false
  method! set_objc_protocol_decl_flag () = ()
  method! clear_objc_protocol_decl_flag () = ()
  method! objc_protocol_decl_flag = false
  method! set_objc_class_flag () = ()
  method! clear_objc_class_flag () = ()
  method! objc_class_flag = false
  method! enter_objc_message_expr () = ()
  method! exit_objc_message_expr () = ()
  method! objc_message_expr_level = 0
  method! in_objc_message_expr = false
  method! set_objc_block_flag () = ()
  method! clear_objc_block_flag () = ()
  method! objc_block_flag = false
  method! set_objc_sel_flag () = ()
  method! clear_objc_sel_flag () = ()
  method! objc_sel_flag = false
  method! set_objc_meth_sel_flag () = ()
  method! clear_objc_meth_sel_flag () = ()
  method! objc_meth_sel_flag = false
  method! set_objc_meth_decl_flag () = ()
  method! clear_objc_meth_decl_flag () = ()
  method! objc_meth_decl_flag = false
  method! set_objc_superclass_flag () = ()
  method! clear_objc_superclass_flag () = ()
  method! objc_superclass_flag = false
  method! set_objc_cat_flag () = ()
  method! clear_objc_cat_flag () = ()
  method! objc_cat_flag = false
  method! set_objc_protocol_ref_flag () = ()
  method! clear_objc_protocol_ref_flag () = ()
  method! objc_protocol_ref_flag = false
  method! set_dtor_flag () = ()
  method! clear_dtor_flag () = ()
  method! dtor_flag = false
  method! set_pp_func_body_odd_flag () = ()
  method! clear_pp_func_body_odd_flag () = ()
  method! pp_func_body_odd_flag = false
  method! set_class_name_flag () = ()
  method! clear_class_name_flag () = ()
  method! class_name_flag = false
  method! set_cast_head_flag () = ()
  method! clear_cast_head_flag () = ()
  method! cast_head_flag = false
  method! set_broken_flag () = ()
  method! clear_broken_flag () = ()
  method! broken_flag = false
  method! set_ns_alias_flag () = ()
  method! clear_ns_alias_flag () = ()
  method! ns_alias_flag = false
  method! set_end_of_objc_meth_sel_flag () = ()
  method! clear_end_of_objc_meth_sel_flag () = ()
  method! end_of_objc_meth_sel_flag = false
  method! set_end_of_objc_meth_type_flag () = ()
  method! clear_end_of_objc_meth_type_flag () = ()
  method! end_of_objc_meth_type_flag = false
  method! set_end_of_objc_property_attrs_decl_flag () = ()
  method! clear_end_of_objc_property_attrs_decl_flag () = ()
  method! end_of_objc_property_attrs_decl_flag = false
  method! set_end_of_objc_protocol_ref_list_flag () = ()
  method! clear_end_of_objc_protocol_ref_list_flag () = ()
  method! end_of_objc_protocol_ref_list_flag = false
  method! set_end_of_decl_spec_macro_call_flag () = ()
  method! clear_end_of_decl_spec_macro_call_flag () = ()
  method! end_of_decl_spec_macro_call_flag = false
  method! set_end_of_attr_macro_call_flag () = ()
  method! clear_end_of_attr_macro_call_flag () = ()
  method! end_of_attr_macro_call_flag = false
  method! set_end_of_type_macro_call_flag () = ()
  method! clear_end_of_type_macro_call_flag () = ()
  method! end_of_type_macro_call_flag = false
  method! set_str_flag () = ()
  method! clear_str_flag () = ()
  method! str_flag = false
  method! set_ty_param_rhs_flag () = ()
  method! clear_ty_param_rhs_flag () = ()
  method! ty_param_rhs_flag = false
  method! set_end_of_if_head_flag () = ()
  method! clear_end_of_if_head_flag () = ()
  method! end_of_if_head_flag = false
  method! set_trailing_retty_flag () = ()
  method! clear_trailing_retty_flag () = ()
  method! trailing_retty_flag = false
  method! set_end_of_id_macro_call_flag () = ()
  method! clear_end_of_id_macro_call_flag () = ()
  method! end_of_id_macro_call_flag = false
  method! set_end_of_literal_macro_call_flag () = ()
  method! clear_end_of_literal_macro_call_flag () = ()
  method! end_of_literal_macro_call_flag = false
  method! set_end_of_decltype_flag () = ()
  method! clear_end_of_decltype_flag () = ()
  method! end_of_decltype_flag = false
  method! set_end_of_noptr_dtor_paren_flag () = ()
  method! clear_end_of_noptr_dtor_paren_flag () = ()
  method! end_of_noptr_dtor_paren_flag = false
  method! set_end_of_sizeof_flag () = ()
  method! clear_end_of_sizeof_flag () = ()
  method! end_of_sizeof_flag = false
  method! set_end_of_handler_head_flag () = ()
  method! clear_end_of_handler_head_flag () = ()
  method! end_of_handler_head_flag = false
  method! set_end_of_broken_decl_section_flag () = ()
  method! clear_end_of_broken_decl_section_flag () = ()
  method! end_of_broken_decl_section_flag = false
  method! set_end_of_label_flag () = ()
  method! clear_end_of_label_flag () = ()
  method! end_of_label_flag = false
  method! set_end_of_mem_initializer_flag () = ()
  method! clear_end_of_mem_initializer_flag () = ()
  method! end_of_mem_initializer_flag = false
  method! set_attr_flag () = ()
  method! clear_attr_flag () = ()
  method! attr_flag = false
  method! set_linkage_spec_flag () = ()
  method! clear_linkage_spec_flag () = ()
  method! linkage_spec_flag = false
  method! set_condition_flag () = ()
  method! clear_condition_flag () = ()
  method! condition_flag = false
  method! set_mem_acc_flag () = ()
  method! clear_mem_acc_flag () = ()
  method! mem_acc_flag = false
  method! set_alias_flag () = ()
  method! clear_alias_flag () = ()
  method! alias_flag = false
  method! set_using_flag () = ()
  method! clear_using_flag () = ()
  method! using_flag = false
  method! set_mock_qualifier_flag () = ()
  method! clear_mock_qualifier_flag () = ()
  method! mock_qualifier_flag = false
  method! set_end_of_str_section_flag () = ()
  method! clear_end_of_str_section_flag () = ()
  method! end_of_str_section_flag = false
  method! set_new_flag () = ()
  method! clear_new_flag () = ()
  method! new_flag = false
  method! set_concept_flag () = ()
  method! clear_concept_flag () = ()
  method! concept_flag = false
  method! set_requires_clause_flag () = ()
  method! clear_requires_clause_flag () = ()
  method! requires_clause_flag = false
  method! set_rhs_flag () = ()
  method! clear_rhs_flag () = ()
  method! rhs_flag = false
  method! set_eq_init_flag () = ()
  method! clear_eq_init_flag () = ()
  method! eq_init_flag = false
  method! enter_sizeof_ty () = ()
  method! exit_sizeof_ty () = ()
  method! sizeof_ty_flag = false
  method! enter_lambda_intro () = ()
  method! exit_lambda_intro () = ()
  method! lambda_intro_flag = false
  method! enter_ctor_init () = ()
  method! exit_ctor_init () = ()
  method! ctor_init_flag = false
  method! enter_stmts () = ()
  method! exit_stmts () = ()
  method! stmts_flag = false
  method! enter_base_clause () = ()
  method! exit_base_clause () = ()
  method! base_clause_flag = false
  method! enter_asm _ = ()
  method! exit_asm () = ()
  method! asm_flag = false
  method! asm_paren_level = 0
  method! enter_braced_asm () = ()
  method! exit_braced_asm () = ()
  method! braced_asm_flag = false
  method! enter_asm_block () = ()
  method! exit_asm_block () = ()
  method! asm_block_flag = false
  method! enter_enum_head () = ()
  method! exit_enum_head () = ()
  method! enum_head_flag = false
  method! enter_ty_param () = ()
  method! exit_ty_param () = ()
  method! ty_param_flag = false
  method! enter_exec_config () = ()
  method! exit_exec_config () = ()
  method! exec_config_flag = false
  method! enter_decltype () = ()
  method! exit_decltype () = ()
  method! decltype_flag = false
  method! enter_alignas () = ()
  method! exit_alignas () = ()
  method! alignas_flag = false
  method! enter_alignof () = ()
  method! exit_alignof () = ()
  method! alignof_flag = false
  method! enter_noexcept () = ()
  method! exit_noexcept () = ()
  method! noexcept_flag = false
  method! enter_macro_arg () = ()
  method! exit_macro_arg () = ()
  method! macro_arg_level = 0
  method! macro_arg_flag = false
  method! enter_pp_line () = ()
  method! exit_pp_line () = ()
  method! pp_line_flag = false
  method! enter_pp_if () = ()
  method! exit_pp_if () = ()
  method! pp_if_flag = false
  method! enter_pp_ifdef () = ()
  method! exit_pp_ifdef () = ()
  method! pp_ifdef_flag = false
  method! enter_pp_group () = ()
  method! exit_pp_group ?(last=false) () = ignore last
  method! enter_pp_if_section _ _ _ _ = ()
  method! exit_pp_if_section ?(odd=false) () = ignore odd
  method! pp_if_section_stack = Stack.create()
  method! pp_group_rel_brace_level_stack = Stack.create()
  method! pp_if_section_level = 0
  method! pp_if_section_top_info = assert false
  method! last_pp_if_section_info = assert false
  method! pp_if_section_nth_info _ = assert false
  method! pp_if_section_rel_brace_level = 0
  method! pp_odd_if_section_rel_brace_level = 0
  method! pp_if_section_rel_paren_level = 0
  method! pp_top_label = L.DUMMY
  method! set_pp_top_label _ = ()
  method! pp_if_section_flag = false
  method! add_pp_elif () = ()
  method! pp_elif_flag = false
  method! add_pp_else () = ()
  method! clear_lbrace_info () = ()
  method! set_lbrace_info _ = ()
  method! get_lbrace_info () = 0
  method! incr_lbrace_info () = ()
  method! decr_lbrace_info () = ()
  method! clear_rbrace_info () = ()
  method! set_rbrace_info _ = ()
  method! get_rbrace_info () = 0
  method! incr_rbrace_info () = ()
  method! decr_rbrace_info () = ()
  method! set_odd_info () = ()
  method! set_odd_canceled_info () = ()
  method! get_odd_info () = false
  method! set_broken_info () = ()
  method! get_broken_info () = false
  method! set_paren_closing_info () = ()
  method! get_paren_closing_info () = false
  method! set_brace_paren_closing_info () = ()
  method! get_brace_paren_closing_info () = false
  method! set_brace_closing_info _ = ()
  method! incr_brace_closing_info() = ()
  method! get_brace_closing_info () = 0
  method! set_brace_opening_info () = ()
  method! clear_brace_opening_info () = ()
  method! get_brace_opening_info () = false
  method! set_func_head_info () = ()
  method! get_func_head_info () = false
  method! set_broken_func_head_info () = ()
  method! get_broken_func_head_info () = false
  method! set_templ_closing_info () = ()
  method! get_templ_closing_info () = false
  method! set_func_body_info () = ()
  method! get_func_body_info () = false
  method! set_semicolon_info () = ()
  method! clear_semicolon_info () = ()
  method! get_semicolon_info () = false
  method! set_comma_info () = ()
  method! get_comma_info () = false
  method! set_cond_expr_info () = ()
  method! get_cond_expr_info () = false
  method! set_cond_expr__info () = ()
  method! get_cond_expr__info () = false
  method! set_asm_info () = ()
  method! get_asm_info () = false
  method! set_begin_asm_info () = ()
  method! get_begin_asm_info () = false
  method! set_lack_of_dtor_info () = ()
  method! get_lack_of_dtor_info () = false
  method! set_class_brace_opening_info () = ()
  method! get_class_brace_opening_info () = false
  method! set_follows_comma_info () = ()
  method! get_follows_comma_info () = false
  method! get_pp_if_compl_info () = {Pinfo.c_brace=0;Pinfo.c_paren=0}
  method! get_pp_if_compl_brace_info () = 0
  method! get_pp_if_compl_paren_info () = 0
  method! reset_pp_if_compl_info () = ()
  method! set_cond_sub_info _ = ()
  method! get_cond_sub_info () = Pinfo.PP_NONE
  method! pp_else_flag = false
  method! alt_pp_branch_flag = false
  method! check_pp_branch_cond _ = false
  method! bracket_stack = Stack.create()
  method! bracket_stack_top = BK_SUBSCR
  method! bracket_stack_to_string = ""
  method! _open_bracket (_ : bracket_kind) = ()
  method! _close_bracket () = ()
  method! open_paren _ = ()
  method! open_paren_normal ?(kind=PKS_NONE) () = ignore kind
  method! open_paren_arg () = ()
  method! close_paren ?(pseudo=false) () = ignore pseudo
  method! paren_level = 0
  method! paren_stack_top = PK_NORMAL PKS_NONE
  method! at_arg_paren = false
  method! at_arg_paren_2 = false
  method! _arg_paren_flag = false
  method! at_type_paren = false
  method! at_type_paren_2 = false
  method! at_fold_paren = false
  method! at_fold_paren_2 = false
  method! at_macro_arg_paren = false
  method! at_macro_arg_paren_2 = false
  method! at_paren = false
  method! at_paren_2 = false
  method! at_if_paren = false
  method! at_bracket = false
  method! change_paren_kind _ = ()
  method! get_paren_stack () = Stack.create()
  method! enter_top_stmts _ = ()
  method! exit_top_stmts () = ()
  method! top_stmts_flag = false
  method! top_stmts_top = 0
  method! enter_templ_param_arg () = ()
  method! exit_templ_param_arg () = ()
  method! templ_param_arg_level = 0
  method! templ_param_arg_stack_top = 0
  method! get_templ_param_arg_stack() = Stack.create()
  method! enter_typename () = ()
  method! exit_typename () = ()
  method! set_typename_level _ = ()
  method! reset_typename_level () = ()
  method! typename_level = 0
  method! typename_flag = false
  method! enter_braced_init () = ()
  method! exit_braced_init () = ()
  method! set_braced_init_level _ = ()
  method! reset_braced_init_level () = ()
  method! braced_init_level = 0
  method! braced_init_flag = false
  method! enter__pp_if_section () = ()
  method! exit__pp_if_section () = ()
  method! set__pp_if_section_level _ = ()
  method! reset__pp_if_section_level () = ()
  method! _pp_if_section_level = 0
  method! _pp_if_section_flag = false
  method! open_brace () = ()
  method! close_brace () = ()
  method! brace_level = 0
  method! rel_paren_level = 0
  method! open_bracket () = ()
  method! close_bracket () = ()
  method! bracket_level = 0
  method! set_bracket_level _ = ()
  method! open_pp_paren () = ()
  method! close_pp_paren () = ()
  method! pp_paren_level = 0
  method! set_pp_paren_level _ = ()
  method! odd_brace_lv_stack_to_string = ""
  method! open_odd_brace () = ()
  method! close_odd_brace () = ()
  method! pp_odd_if_section_level = 0
  method! odd_brace_level = 0

end

class dummy_stack = object (self)
  inherit N.stack

  method! enter_block ?(prefix="") ?(qname="") ?(no_tweak=false) _ =
    ignore prefix; ignore qname; ignore no_tweak

  method! exit_block () = ()
  method! enter_class _ = ()
  method! exit_class () = ()
  method! enter_template () = ()
  method! exit_template () = ()
  method! enter_namespace _ = ()
  method! exit_namespace () = self#top
  method! enter_enum _ = ()
  method! exit_enum () = ()
end

[%%capture_path
class env = object (self)
  inherit [Source.c] Env_base.c as super

  val bidgen = new BID.generator

  val mutable stack = new N.stack
  val mutable saved_stack = new N.stack
  val mutable top_frame = new N.stack_frame N.Scope.Top
  val mutable dtor_node = Ast.dummy_node

  val mutable lex_line_head_flag = true
  val mutable lex_pp_line_flag = false
  val mutable lex_ms_asm_line_flag = false
  val mutable pp_define_flag = false
  val mutable pp_define_body_flag = false
  val mutable pp_odd_flag = false
  val mutable pp_params_flag = false
  val mutable body_head_flag = false
  val mutable cast_key_flag = false
  val mutable conv_func_id_flag = false
  val mutable expr_flag = false
  val mutable for_range_init_flag = false
  val mutable in_body_brace_flag = false
  val mutable init_flag = false
  val mutable param_head_flag = false
  val mutable ty_param_key_flag = false
  val mutable typedef_flag = false
  val mutable using_ns_flag = false
  val mutable virtual_func_flag = false
  val mutable value_flag = false
  val mutable dtor_if_section_flag = false
  val mutable objc_flag = false

  val templ_head_stack = (Stack.create() : int Stack.t)
  val const_stack = Stack.create()

  val mutable in_body_brace_level = 0

  val mutable pstat = new pstat

  val pending_macro_tbl = (Hashtbl.create 0 :
                             (string, Ast.node * L.macro_kind * Obj.t) Hashtbl.t)

  val resolved_macro_tbl = (Hashtbl.create 0 : (string, Ast.node) Hashtbl.t)

  val malformed_macro_names = (Xset.create 0 : string Xset.t)

  val mutable access_spec_opt = (None : N.Spec.access_spec option)

  val mutable scanner_keep_flag = false
  val mutable scanner_replay_flag = false

  val inline_asm_functions = (Xset.create 0 : string Xset.t)

  val mutable unqualified_name = ""
  val mutable function_name = ""
  val mutable name_prefix = ""

  val mutable dump_tokens_flag = false
  val mutable parse_tokens_flag = false

  initializer
    stack#push top_frame

  method set_dump_tokens_flag () =
    dump_tokens_flag <- true

  method dump_tokens_flag = dump_tokens_flag

  method set_parse_tokens_flag () =
    parse_tokens_flag <- true;
    pstat <- new dummy_pstat;
    stack <- new dummy_stack;
    stack#push top_frame

  method parse_tokens_flag = parse_tokens_flag

  method set_top_frame frm = top_frame <- frm

  method reset_name_prefix () = name_prefix <- ""
  method name_prefix = name_prefix
  method _set_name_prefix p =
    [%debug_log "p=%s" p];
    name_prefix <- p
  method set_name_prefix nd =
    let p = Ast.encode_nested_name_spec nd in
    [%debug_log "p=%s" p];
    name_prefix <- p

  method set_dtor_node nd =
    [%debug_log "@"];
    dtor_node <- nd

  method reset_dtor_node () =
    [%debug_log "@"];
    dtor_node <- Ast.dummy_node

  method get_dtor_prefix () =
    if self#stack#after_params then begin
      if dtor_node != Ast.dummy_node then
        let _q, _ = Ast.qn_wrap_of_declarator dtor_node in
        let q = Ast.prefix_of_encoded _q in
        q
      else
        ""
    end
    else
      ""

  method get_dtor_prefix_and_qn () =
    if self#stack#after_params then begin
      if dtor_node != Ast.dummy_node then
        let q, _ = Ast.qn_wrap_of_declarator dtor_node in
        let p = Ast.prefix_of_encoded q in
        p, q
      else
        "", ""
    end
    else
      "", ""

  method scanner_keep_flag = scanner_keep_flag
  method set_scanner_keep_flag() = scanner_keep_flag <- true
  method clear_scanner_keep_flag() = scanner_keep_flag <- false

  method scanner_replay_flag = scanner_replay_flag
  method set_scanner_replay_flag() = scanner_replay_flag <- true
  method clear_scanner_replay_flag() = scanner_replay_flag <- false

  method access_spec_opt = access_spec_opt

  method set_access_spec a =
    [%debug_log "%s -> %s"
      (opt_to_string N.Spec.access_spec_to_string access_spec_opt)
      (N.Spec.access_spec_to_string a)];
    access_spec_opt <- Some a

  method reset_access_spec () =
    [%debug_log "%s ->" (opt_to_string N.Spec.access_spec_to_string access_spec_opt)];
    access_spec_opt <- None

  method lookup_name ?(filt=fun _ -> true) n =
    stack#find_name ~filt n

  method lookup_namespace n =
    stack#find_namespace n

  method lookup_obj n =
    stack#find_obj n

  method lookup_type n =
    stack#find_type n

  method set_obj_external_name ?(prefix="") i (nd : Ast.node) =
    let p = stack#get_prefix ~prefix ~ns_only:true () in
    let qn = p^prefix^i in
    let info = I.from_name qn in
    [%debug_log "%s => %s" i (I.to_string info)];
    nd#set_info info

  method set_obj_binding ?(prefix="") i (nd : Ast.node) =
    try
      let spec = self#lookup_obj (prefix^i) in
      match spec#bid_opt with
      | Some bid -> begin
          let loc_opt =
            Some (UID.of_int spec#iod, conv_loc spec#lod)
          in
          let b = B.make_use ~loc_opt bid in
          [%debug_log "%s => %s" i (B.to_string b)];
          nd#set_binding b
      end
      | None -> ()
    with
      Not_found -> self#set_obj_external_name ~prefix i nd

  method set_type_external_name ?(prefix="") i (nd : Ast.node) =
    let p = stack#get_prefix ~prefix ~ns_only:true () in
    let qn = p^prefix^i in
    let info = I.from_name qn in
    [%debug_log "%s => %s" i (I.to_string info)];
    nd#set_info info

  method set_type_binding ?(prefix="") i (nd : Ast.node) =
    try
      let spec = self#lookup_type (prefix^i) in
      match spec#bid_opt with
      | Some bid -> begin
          let loc_opt =
            Some (UID.of_int spec#iod, conv_loc spec#lod)
          in
          let b = B.make_use ~loc_opt bid in
          [%debug_log "%s => %s" i (B.to_string b)];
          nd#set_binding b
      end
      | None -> ()
    with
      Not_found -> begin
        if not self#scanner_keep_flag && not self#scanner_replay_flag then begin
          self#set_type_external_name ~prefix i nd;
          (*!!!NG!!!let spec = new N.Spec.c ~prefix Ast.Loc.dummy 0 i N.Spec.Type in
          top_frame#register i spec*)
        end
      end

  method save_stack () =
    saved_stack <- stack;
    stack <- saved_stack#copy

  method restore_stack () =
    stack <- saved_stack#copy

  method reset_pstat () =
    pstat#reset()

  method! init =
    super#init;
    self#reset_pstat()

  method stack = stack
  method pstat = pstat
  method set_pstat s = pstat <- s
  method get_pstat () = pstat

  method _open_bracket = pstat#_open_bracket
  method __close_bracket = pstat#__close_bracket
  method _close_bracket = pstat#_close_bracket

  method open_paren x =
    if self#pp_line_flag then
      pstat#open_pp_paren()
    else
      pstat#open_paren x
  method paren_stack_top = pstat#paren_stack_top
  method close_paren ?(pseudo=false) () =
    if self#pp_line_flag then
      pstat#close_pp_paren()
    else
      pstat#close_paren ~pseudo ()
  method change_paren_kind = pstat#change_paren_kind
  method paren_level = pstat#paren_level
  method pp_paren_level = pstat#pp_paren_level
  method at_ini_brace = pstat#at_ini_brace
  method at_ini_brace_2 = pstat#at_ini_brace_2
  method at_class_brace = pstat#at_class_brace
  method at_brace = pstat#at_brace
  method at_brace_2 = pstat#at_brace_2
  method at_req_brace = pstat#at_req_brace
  method at_objc_msg = pstat#at_objc_msg
  method at_attr = pstat#at_attr
  method at_lam_intr = pstat#at_lam_intr
  method at_subscr = pstat#at_subscr
  method at_templ_arg = pstat#at_templ_arg
  method at_templ_arg_2 = pstat#at_templ_arg_2
  method at_templ_param = pstat#at_templ_param
  method at_templ_param_2 = pstat#at_templ_param_2
  method at_templ_param_arg_expr_2 = pstat#at_templ_param_arg_expr_2
  method at_arg_paren = pstat#at_arg_paren
  method at_arg_paren_2 = pstat#at_arg_paren_2
  method _arg_paren_flag = pstat#_arg_paren_flag
  method at_type_paren = pstat#at_type_paren
  method at_type_paren_2 = pstat#at_type_paren_2
  method at_fold_paren = pstat#at_fold_paren
  method at_fold_paren_2 = pstat#at_fold_paren_2
  method at_paren = pstat#at_paren
  method at_paren_2 = pstat#at_paren_2
  method at_if_paren = pstat#at_if_paren
  method at_macro_arg_paren = pstat#at_macro_arg_paren
  method at_macro_arg_paren_2 = pstat#at_macro_arg_paren_2
  method at_bracket = pstat#at_bracket
  method enter_templ_param_arg = pstat#enter_templ_param_arg
  method exit_templ_param_arg = pstat#exit_templ_param_arg
  method templ_param_arg_stack_top = pstat#templ_param_arg_stack_top
  method get_templ_param_arg_stack = pstat#get_templ_param_arg_stack
  method templ_param_arg_level = pstat#templ_param_arg_level
  method enter_typename = pstat#enter_typename
  method exit_typename = pstat#exit_typename
  method reset_typename_level = pstat#reset_typename_level
  method typename_level = pstat#typename_level
  method typename_flag = pstat#typename_flag
  method enter_braced_init = pstat#enter_braced_init
  method exit_braced_init = pstat#exit_braced_init
  method reset_braced_init_level = pstat#reset_braced_init_level
  method braced_init_level = pstat#braced_init_level
  method braced_init_flag = pstat#braced_init_flag
  method enter__pp_if_section = pstat#enter__pp_if_section
  method exit__pp_if_section = pstat#exit__pp_if_section
  method reset__pp_if_section_level = pstat#reset__pp_if_section_level
  method _pp_if_section_level = pstat#_pp_if_section_level
  method _pp_if_section_flag = pstat#_pp_if_section_flag
  method open_brace () = if self#pp_line_flag then () else pstat#open_brace()
  method close_brace () = if self#pp_line_flag then () else pstat#close_brace()
  method brace_level = pstat#brace_level
  method rel_paren_level = pstat#rel_paren_level
  method open_odd_brace () = pstat#open_odd_brace()
  method close_odd_brace () = pstat#close_odd_brace()
  method odd_brace_level = pstat#odd_brace_level
  method open_bracket = pstat#open_bracket
  method close_bracket = pstat#close_bracket
  method bracket_level = pstat#bracket_level
  method open_pp_paren = pstat#open_pp_paren
  method close_pp_paren = pstat#close_pp_paren
  method enter_top_stmts = pstat#enter_top_stmts
  method exit_top_stmts = pstat#exit_top_stmts
  method top_stmts_flag = pstat#top_stmts_flag
  method top_stmts_top = pstat#top_stmts_top

  val mutable current_source_digest_opt = None

  method! enter_source src =
    let x = super#enter_source src in
    current_source_digest_opt <- None;
    x

  method get_global_bid loc =
    let digest =
      match current_source_digest_opt with
      | Some d -> d
      | None ->
        let filename = self#current_filename in
        [%debug_log "filename=\"%s\"" filename];
        let stree = self#current_source#tree in
        let d = Xhash.to_hex (stree#get_entry filename)#file_digest in
        current_source_digest_opt <- (Some d);
        d
    in
    let s = sprintf "%s-%d_%d" digest loc.Astloc.start_offset loc.Astloc.end_offset in
    BID.make_global s

  method make_local_bid () =
    bidgen#gen

  method register_global_type i st ed =
    [%debug_log "i=%s" i];
    let loc = (Ast.lloc_of_lexposs st ed)#get_loc in
    let spec = new N.Spec.c loc Ast.dummy_node_id i N.Spec.Type in
    top_frame#register ~replace:true i spec

  method register_macro_obj i (nd : Ast.node) =
    [%debug_log "i=%s %s" i nd#to_string];
    let spec = new N.Spec.c nd#loc nd#id i N.Spec.MacroObj in
    top_frame#register ~replace:true i spec

  method register_macro_fun i (nd : Ast.node) =
    [%debug_log "i=%s %s" i nd#to_string];
    let spec = new N.Spec.c nd#loc nd#id i N.Spec.MacroFun in
    top_frame#register ~replace:true i spec

  method register_id_macro_fun i (nd : Ast.node) =
    [%debug_log "i=%s" i];
    let spec = new N.Spec.c nd#loc nd#id i N.Spec.IdMacroFun in
    top_frame#register ~replace:false i spec

  method undef_macro i =
    top_frame#remove_macro (Ast.mk_macro_call_id i);
    top_frame#remove_macro (Ast.mk_macro_id i)

  method register_namespace i (nd : Ast.node) (frm : N.stack_frame) =
    [%debug_log "i=%s" i];
    let spec =
      new N.Spec.c nd#loc nd#id i (N.Spec.Namespace (self#stack#make_def_adder frm))
    in
    frm#register i spec

  method register_using_decls nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let lod = nd#loc in
    let iod = nd#id in
    List.iter
      (fun (p, u) ->
        let spec = new N.Spec.c ~prefix:p lod iod u N.Spec.UsingDecl in
        frm#register u spec
      ) (Ast.qn_list_of_using_declaration nd)

  method register_using_enum_decls nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let lod = nd#loc in
    let iod = nd#id in
    List.iter
      (fun (p, u) ->
        let spec = new N.Spec.c ~prefix:p lod iod u N.Spec.UsingEnumDecl in
        frm#register u spec
      ) (Ast.qn_list_of_using_enum_declaration nd)

  method register_type_param nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let i, tp_spec = Ast.ident_type_param_spec_of_type_param nd in
    let uqn = I.encode_ident i in
    let frm = stack#top in
    let spec = new N.Spec.c nd#loc nd#id uqn (N.Spec.make_typaram tp_spec) in
    nd#set_info (I.from_spec spec);
    frm#register uqn spec

  method register_elaborated_type (nd : Ast.node) =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let ok =
      try
        match (List.hd (nd#nth_children 2))#label with
        | L.IdentifierMacroInvocation _ -> false
        | _ -> true
      with _ -> true
    in
    if ok then
    let frm = stack#top in
    let p = stack#get_prefix() in
    let qn =
      match nd#label with
      | ElaboratedTypeSpecifierClass i
      | ElaboratedTypeSpecifierStruct i
      | ElaboratedTypeSpecifierUnion i
      | ElaboratedTypeSpecifierEnum i -> i
      | _ -> assert false
    in
    let spec = new N.Spec.c ~prefix:p nd#loc nd#id qn N.Spec.Type in
    nd#set_info (I.from_spec spec);
    frm#register qn spec

  method register_class_head nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let ns = stack#get_prefix ~ns_only:true () in
    let qn, s = Ast.qn_class_spec_of_class ns nd in
    if qn = "" then
      ""
    else begin
      let frm = stack#top in
      let p = stack#get_prefix() in
      let k =
        match nd#label with
        | ClassHeadClass  -> N.Spec.Class s
        | ClassHeadStruct -> N.Spec.Struct s
        | ClassHeadUnion  -> N.Spec.Union s
        | ClassHeadMacro _ -> N.Spec.Class s
        | ClassHeadMacroInvocation _ -> N.Spec.Class s
        | ClassHeadMsRefClass -> N.Spec.Class s
        | _ -> assert false
      in
      let spec = new N.Spec.c ~prefix:p nd#loc nd#id qn k in
      nd#set_info (I.from_spec spec);
      frm#register qn spec;
      qn
    end

  method register_enum_head nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let ns = stack#get_prefix ~ns_only:true () in
    let qn, s = Ast.qn_enum_spec_of_enum ns nd in
    if qn = "" then
      ""
    else begin
      let frm = stack#top in
      let p = stack#get_prefix() in
      let k =
        match nd#label with
        | EnumHeadEnum | OpaqueEnumDeclaration -> N.Spec.Enum s
        | EnumHeadEnumClass | OpaqueEnumDeclarationClass -> N.Spec.EnumClass s
        | EnumHeadEnumStruct | OpaqueEnumDeclarationStruct -> N.Spec.EnumStruct s
        | EnumHeadEnumMacro i | OpaqueEnumDeclarationMacro i -> N.Spec.EnumMacro(i, s)
        | _ -> assert false
      in
      let spec = new N.Spec.c ~prefix:p nd#loc nd#id qn k in
      nd#set_info (I.from_spec spec);
      frm#register qn spec;
      qn
    end

  method register_function nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let qn, ty = Ast.qn_type_of_func_def nd in
    [%debug_log "qn=%s" qn];
    let frm = stack#top in
    let p = stack#get_prefix() in
    let bid = self#get_global_bid nd#loc in
    let kind =
      match self#access_spec_opt with
      | Some _ -> N.Spec.make_member self#access_spec_opt ty
      | None   -> N.Spec.make_function ty
    in
    let spec = new N.Spec.c ~bid_opt:(Some bid) ~prefix:p nd#loc nd#id qn kind in
    nd#set_info (I.from_spec spec);
    frm#register qn spec;
    qn

  method register_param_decl_clause (nd : Ast.node) =
    [%debug_log "%s" (L.to_string nd#label)];
    match nd#label with
    | ParameterDeclarationClause _ -> begin
        let rec doit index = function
          | [] -> ()
          | h::t -> begin
              let itl = self#register_fparam h in
              List.iter
                (fun (i, ty) ->
                  let pred = function L.Identifier x -> x = i | _ -> false in
                  let maxL = ref 0 in
                  List.iter
                    (fun (r : Ast.node) ->
                      List.iter
                        (fun (y : Ast.node) ->
                          let count = ref 0 in
                          let decltype_flag = ref false in
                          let count_scope (x : Ast.node) =
                            match x#label with
                            | DeclaratorFunc | NoptrDeclaratorFunc
                            | AbstractDeclaratorFunc | NoptrAbstractDeclaratorFunc
                              -> incr count
                            | TrailingReturnType -> decr count
                            | ParameterDeclaration _ when not !decltype_flag -> raise Exit
                            | DecltypeSpecifier -> decltype_flag := true
                            | _ -> ()
                          in
                          begin
                            try
                              y#iter_parents ~upto:(Some r) count_scope;
                            with
                              Exit -> ()
                          end;
                          let _L = !count + 1 in
                          if _L > !maxL then
                            maxL := _L
                        ) (Ast.find_nodes pred r);
                    ) t;
                  let prefix =
                    if !maxL > 0 then
                      sprintf "fL%dp" (!maxL-1)
                    else
                      "fp"
                  in
                  let cvq =
                    let stys = Type.get_top_level_type ty in
                    let l =
                      match stys with
                      | sty::_ -> Type.get_cv_qualifiers_of_simple_ty sty (* !!! *)
                      | _ -> assert false
                    in
                    String.concat ""
                      (List.fast_sort compare (List.map I.CvQualifier.encode l))
                  in
                  let encoded =
                    let rest =
                      if index = 0 then
                        "_"
                      else if index > 0 then
                        sprintf "%d_" (index-1)
                      else
                        assert false
                    in
                    sprintf "%s%s%s" prefix cvq rest
                  in
                  h#set_encoded encoded) itl;
              doit (index+1) t
          end
        in
        doit 0 nd#children
    end
    | _ -> invalid_arg "Cpp.Parser_aux.env#register_fparams"

  method register_templ_param (nd : Ast.node) =
    match nd#label with
    | TypeParameter _ -> self#register_type_param nd
    | TemplParamMacroInvocation _ -> ()
    | _ -> self#register_param nd

  method register_templ_params nds =
    List.iteri
      (fun index x ->
        self#register_templ_param x;
        let encoded =
          if index = 0 then
            "T_"
          else if index > 0 then
            sprintf "T%d_" (index-1)
          else
            assert false
        in
        x#set_encoded encoded
      ) nds

  method register_fparam nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    List.fold_left
      (fun l (n, qn, ty) ->
        if qn <> "" then begin
          let frm = stack#top in
          let bid = self#make_local_bid() in
          let spec = new N.Spec.c ~bid_opt:(Some bid) n#loc n#id qn (N.Spec.make_fparam ty) in
          n#set_info (I.from_spec spec);
          frm#register qn spec;
          (qn, ty)::l
        end
        else
          l
      ) [] (Ast.qn_type_list_of_param_decl nd)

  method register_param nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    List.iter
      (fun (n, qn, ty) ->
        if qn <> "" then begin
          let frm = stack#top in
          let bid = self#make_local_bid() in
          let spec = new N.Spec.c ~bid_opt:(Some bid) n#loc n#id qn (N.Spec.make_param ty) in
          n#set_info (I.from_spec spec);
          frm#register qn spec
        end
      ) (Ast.qn_type_list_of_param_decl nd)

  method register_exc_decl nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    try
      let n, qn, ty = Ast.qn_type_of_exc_decl nd in
      if qn <> "" then begin
        let frm = stack#top in
        let bid = self#make_local_bid() in
        let spec = new N.Spec.c ~bid_opt:(Some bid) n#loc n#id qn (N.Spec.make_param ty) in
        n#set_info (I.from_spec spec);
        frm#register qn spec
      end
    with
      Ast.Type_not_found -> ()

  method register_enumerator (nd : Ast.node) =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let scope = frm#scope in
    let p = stack#get_prefix() in
    try
      List.iter
        (fun (n, qn, ty) ->
          let kind = N.Spec.make_enumerator ty in
          let spec = new N.Spec.c ~prefix:p n#loc n#id qn kind in
          n#set_info (I.from_spec spec);
          frm#register qn spec
        ) (Ast.qn_type_list_of_enumerator scope nd)
    with
      _ -> ()

  method register_members nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let p = stack#get_prefix() in
    List.iter
      (fun (n, qn, ty) ->
        let spec =
          new N.Spec.c ~prefix:p n#loc n#id qn (N.Spec.make_member self#access_spec_opt ty)
        in
        n#set_info (I.from_spec spec);
        frm#register qn spec
      ) (Ast.qn_type_list_of_mem_decl nd)

  method register_variables nd =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let is_local =
      match frm#scope with
      | Block _ | Params -> true
      | _ -> false
    in
    [%debug_log "is_local=%B" is_local];
    let p =
      if is_local then
        ""
      else
        stack#get_prefix()
    in
    List.iter
      (fun (n, qn, ty) ->
        [%debug_log "qn=%s ty=%s" qn (Type.to_string ty)];
        let t = Type.wrap ty in
        Type.hoist_typedef t;
        let typedef_flag = t.Type.t_typedef in
        [%debug_log "typedef_flag=%B" typedef_flag];
        let bid =
          if is_local then
            self#make_local_bid()
          else
            self#get_global_bid n#loc
        in
        let bid_opt = Some bid in
        let section_info_opt =
          try
            Some self#pp_if_section_top_info
          with
            _ -> None
        in
        let lod = n#loc in
        let iod = n#id in
        let kind =
          if typedef_flag then
            N.Spec.Type
          else
            N.Spec.make_variable ty
        in
        let spec =
          new N.Spec.c ~bid_opt ~prefix:p ~is_local ~section_info_opt lod iod qn kind
        in
        n#set_info (I.from_spec spec);
        if is_local then begin
          n#set_binding (B.make_unknown_def bid is_local)
        end;
        frm#register qn spec;
        begin
          let name = I.decode_ident qn in
          let flag, lab =
            match (n#label : L.t) with
            | InitDeclarator _ -> true, L.InitDeclarator name
            | ParameterDeclaration _ -> true, L.ParameterDeclaration name
            | x -> false, x
          in
          if flag then
            n#relab lab
        end
      ) (Ast.qn_type_list_of_simple_decl nd)

  method register_label ?(replace=false) (nd : Ast.node) =
    [%debug_log "nd=%s" (L.to_string nd#label)];
    let frm = stack#top in
    let i = nd#get_name in
    if replace || try (frm#find i)#kind != N.Spec.Label with _ -> true then begin
      let spec = new N.Spec.c nd#loc nd#id i N.Spec.Label in
      frm#register ~replace i spec
    end

  method register_resolved_macro name nd =
    [%debug_log "%s -> %s" name (L.to_string nd#label)];
    Hashtbl.add resolved_macro_tbl name nd

  method find_resolved_macro name =
    [%debug_log "%s" name];
    Hashtbl.find resolved_macro_tbl name

  method find_all_resolved_macro name =
    [%debug_log "%s" name];
    Hashtbl.find_all resolved_macro_tbl name

  method register_pending_macro name parent_nd macro_kind tok_lst =
    [%debug_log "%s: %s" name (L.macro_kind_to_string macro_kind)];
    Hashtbl.add pending_macro_tbl name (parent_nd, macro_kind, tok_lst)

  method iter_pending_macro f =
    Hashtbl.iter f pending_macro_tbl

  method find_pending_macro name =
    [%debug_log "%s" name];
    Hashtbl.find pending_macro_tbl name

  method register_malformed_macro name =
    [%debug_log "%s" name];
    Xset.add malformed_macro_names name

  method is_malformed_macro name =
    [%debug_log "%s" name];
    Xset.mem malformed_macro_names name

  method register_inline_asm_function name =
    [%debug_log "%s" name];
    Xset.add inline_asm_functions name

  method is_inline_asm_function name =
    let b = Xset.mem inline_asm_functions name in
    [%debug_log "%s -> %B" name b];
    b

  method get_unqualified_name() = unqualified_name
  method set_unqualified_name n =
    [%debug_log "%s" n];
    unqualified_name <- n
  method clear_unqualified_name() = [%debug_log "called"]; unqualified_name <- ""

  method get_function_name() = function_name
  method set_function_name() =
    let n = self#get_unqualified_name() in
    [%debug_log "%s" n];
    function_name <- n
  method clear_function_name() = [%debug_log "called"]; function_name <- ""

  method set_lex_line_head_flag () =
    [%debug_log "lex_line_head_flag set"];
    lex_line_head_flag <- true

  method clear_lex_line_head_flag () =
    [%debug_log "lex_line_head_flag cleared"];
    lex_line_head_flag <- false

  method lex_line_head_flag = lex_line_head_flag

  method enter_lex_pp_line () =
    [%debug_log "entering lex_pp_line"];
    lex_pp_line_flag <- true

  method exit_lex_pp_line () =
    if lex_pp_line_flag then begin
      [%debug_log "exiting lex_pp_line"];
      lex_pp_line_flag <- false
    end

  method lex_pp_line_flag = lex_pp_line_flag

  method enter_lex_ms_asm_line () =
    [%debug_log "entering lex_ms_asm_line"];
    lex_ms_asm_line_flag <- true

  method exit_lex_ms_asm_line () =
    if lex_ms_asm_line_flag then begin
      [%debug_log "exiting lex_ms_asm_line"];
      lex_ms_asm_line_flag <- false
    end

  method lex_ms_asm_line_flag = lex_ms_asm_line_flag

  method pp_line_flag = pstat#pp_line_flag
  method enter_pp_line = pstat#enter_pp_line
  method exit_pp_line = pstat#exit_pp_line

  method pp_if_flag = pstat#pp_if_flag
  method enter_pp_if = pstat#enter_pp_if
  method exit_pp_if = pstat#exit_pp_if

  method pp_ifdef_flag = pstat#pp_ifdef_flag
  method enter_pp_ifdef = pstat#enter_pp_ifdef
  method exit_pp_ifdef = pstat#exit_pp_ifdef

  method enter_pp_define () =
    [%debug_log "entering pp_define"];
    pp_define_flag <- true

  method exit_pp_define () =
    [%debug_log "exiting pp_define"];
    pp_define_flag <- false

  method pp_define_flag = pp_define_flag

  method enter_pp_define_body () =
    [%debug_log "entering pp_define_body"];
    pp_define_body_flag <- true

  method exit_pp_define_body () =
    [%debug_log "exiting pp_define_body"];
    pp_define_body_flag <- false

  method pp_define_body_flag = pp_define_body_flag

  method enter_templ_head lv =
    [%debug_log "entering templ_head (lv=%d)" lv];
    Stack.push lv templ_head_stack

  method exit_templ_head () =
    [%debug_log "exiting templ_head..."];
    let lv = Stack.pop templ_head_stack in
    let _ = lv in
    [%debug_log "templ_head exited (lv=%d)" lv]

  method templ_head_level = Stack.length templ_head_stack
  method templ_head_lv = Stack.top templ_head_stack
  method templ_head_flag = not (Stack.is_empty templ_head_stack)

  method enter_pp_group = pstat#enter_pp_group
  method exit_pp_group = pstat#exit_pp_group
  method enter_pp_if_section = pstat#enter_pp_if_section
  method exit_pp_if_section = pstat#exit_pp_if_section
  method pp_if_section_level = pstat#pp_if_section_level
  method pp_if_section_top_info = pstat#pp_if_section_top_info
  method pp_if_section_nth_info = pstat#pp_if_section_nth_info

  method pp_odd_if_section_level = pstat#pp_odd_if_section_level

  method pp_if_section_rel_brace_level = pstat#pp_if_section_rel_brace_level
  method pp_if_section_rel_paren_level = pstat#pp_if_section_rel_paren_level
  method pp_odd_if_section_rel_brace_level = pstat#pp_odd_if_section_rel_brace_level
  method pp_if_section_flag = pstat#pp_if_section_flag

  method enter_templ_arg = pstat#enter_templ_arg
  method exit_templ_arg = pstat#exit_templ_arg
  method templ_arg_flag = pstat#templ_arg_flag
  method ty_templ_id_flag = pstat#ty_templ_id_flag
  method last_ty_templ_id_flag = pstat#last_ty_templ_id_flag

  method set_for_flag = pstat#set_for_flag
  method clear_for_flag = pstat#clear_for_flag
  method for_flag = pstat#for_flag

  method set_templ_flag = pstat#set_templ_flag
  method clear_templ_flag = pstat#clear_templ_flag
  method templ_flag = pstat#templ_flag

  method set_start_of_func_body_flag = pstat#set_start_of_func_body_flag
  method clear_start_of_func_body_flag = pstat#clear_start_of_func_body_flag
  method start_of_func_body_flag = pstat#start_of_func_body_flag

  method set_end_of_old_param_decl_flag = pstat#set_end_of_old_param_decl_flag
  method clear_end_of_old_param_decl_flag = pstat#clear_end_of_old_param_decl_flag
  method end_of_old_param_decl_flag = pstat#end_of_old_param_decl_flag

  method set_end_of_lambda_templ_flag = pstat#set_end_of_lambda_templ_flag
  method clear_end_of_lambda_templ_flag = pstat#clear_end_of_lambda_templ_flag
  method end_of_lambda_templ_flag = pstat#end_of_lambda_templ_flag

  method set_old_param_decl_flag = pstat#set_old_param_decl_flag
  method clear_old_param_decl_flag = pstat#clear_old_param_decl_flag
  method old_param_decl_flag = pstat#old_param_decl_flag

  method set_end_of_class_spec_flag = pstat#set_end_of_class_spec_flag
  method clear_end_of_class_spec_flag = pstat#clear_end_of_class_spec_flag
  method end_of_class_spec_flag = pstat#end_of_class_spec_flag

  method set_end_of_enum_spec_flag = pstat#set_end_of_enum_spec_flag
  method clear_end_of_enum_spec_flag = pstat#clear_end_of_enum_spec_flag
  method end_of_enum_spec_flag = pstat#end_of_enum_spec_flag

  method set_end_of_cast_type_flag = pstat#set_end_of_cast_type_flag
  method clear_end_of_cast_type_flag = pstat#clear_end_of_cast_type_flag
  method end_of_cast_type_flag = pstat#end_of_cast_type_flag

  method set_end_of_templ_head_flag = pstat#set_end_of_templ_head_flag
  method clear_end_of_templ_head_flag = pstat#clear_end_of_templ_head_flag
  method end_of_templ_head_flag = pstat#end_of_templ_head_flag

  method set_end_of_params_flag = pstat#set_end_of_params_flag
  method clear_end_of_params_flag = pstat#clear_end_of_params_flag
  method end_of_params_flag = pstat#end_of_params_flag

  method set_end_of_req_params_flag = pstat#set_end_of_req_params_flag
  method clear_end_of_req_params_flag = pstat#clear_end_of_req_params_flag
  method end_of_req_params_flag = pstat#end_of_req_params_flag

  method set_decl_stmt_block_flag = pstat#set_decl_stmt_block_flag
  method clear_decl_stmt_block_flag = pstat#clear_decl_stmt_block_flag
  method decl_stmt_block_flag = pstat#decl_stmt_block_flag

  method set_lambda_dtor_flag = pstat#set_lambda_dtor_flag
  method clear_lambda_dtor_flag = pstat#clear_lambda_dtor_flag
  method lambda_dtor_flag = pstat#lambda_dtor_flag

  method set_asm_shader_flag = pstat#set_asm_shader_flag
  method clear_asm_shader_flag = pstat#clear_asm_shader_flag
  method asm_shader_flag = pstat#asm_shader_flag

  method set_dsl_flag = pstat#set_dsl_flag
  method clear_dsl_flag = pstat#clear_dsl_flag
  method dsl_flag = pstat#dsl_flag

  method set_objc_class_interface_flag () =
    pstat#set_objc_class_interface_flag();
    objc_flag <- true
  method clear_objc_class_interface_flag = pstat#clear_objc_class_interface_flag
  method objc_class_interface_flag = pstat#objc_class_interface_flag

  method set_objc_protocol_decl_flag () =
    pstat#set_objc_protocol_decl_flag();
    objc_flag <- true
  method clear_objc_protocol_decl_flag = pstat#clear_objc_protocol_decl_flag
  method objc_protocol_decl_flag = pstat#objc_protocol_decl_flag

  method set_objc_class_flag () =
    pstat#set_objc_class_flag();
    objc_flag <- true
  method clear_objc_class_flag = pstat#clear_objc_class_flag
  method objc_class_flag = pstat#objc_class_flag

  method enter_objc_message_expr = pstat#enter_objc_message_expr
  method exit_objc_message_expr = pstat#exit_objc_message_expr
  method objc_message_expr_level = pstat#objc_message_expr_level
  method in_objc_message_expr = pstat#in_objc_message_expr

  method set_objc_block_flag = pstat#set_objc_block_flag
  method clear_objc_block_flag = pstat#clear_objc_block_flag
  method objc_block_flag = pstat#objc_block_flag

  method set_objc_sel_flag = pstat#set_objc_sel_flag
  method clear_objc_sel_flag = pstat#clear_objc_sel_flag
  method objc_sel_flag = pstat#objc_sel_flag

  method set_objc_meth_sel_flag = pstat#set_objc_meth_sel_flag
  method clear_objc_meth_sel_flag = pstat#clear_objc_meth_sel_flag
  method objc_meth_sel_flag = pstat#objc_meth_sel_flag

  method set_objc_meth_decl_flag = pstat#set_objc_meth_decl_flag
  method clear_objc_meth_decl_flag = pstat#clear_objc_meth_decl_flag
  method objc_meth_decl_flag = pstat#objc_meth_decl_flag

  method set_objc_superclass_flag = pstat#set_objc_superclass_flag
  method clear_objc_superclass_flag = pstat#clear_objc_superclass_flag
  method objc_superclass_flag = pstat#objc_superclass_flag

  method set_objc_cat_flag = pstat#set_objc_cat_flag
  method clear_objc_cat_flag = pstat#clear_objc_cat_flag
  method objc_cat_flag = pstat#objc_cat_flag

  method set_objc_protocol_ref_flag = pstat#set_objc_protocol_ref_flag
  method clear_objc_protocol_ref_flag = pstat#clear_objc_protocol_ref_flag
  method objc_protocol_ref_flag = pstat#objc_protocol_ref_flag

  method set_dtor_flag = pstat#set_dtor_flag
  method clear_dtor_flag = pstat#clear_dtor_flag
  method dtor_flag = pstat#dtor_flag

  method set_pp_func_body_odd_flag = pstat#set_pp_func_body_odd_flag
  method clear_pp_func_body_odd_flag = pstat#clear_pp_func_body_odd_flag
  method pp_func_body_odd_flag = pstat#pp_func_body_odd_flag

  method set_class_name_flag = pstat#set_class_name_flag
  method clear_class_name_flag = pstat#clear_class_name_flag
  method class_name_flag = pstat#class_name_flag

  method set_cast_head_flag = pstat#set_cast_head_flag
  method clear_cast_head_flag = pstat#clear_cast_head_flag
  method cast_head_flag = pstat#cast_head_flag

  method set_broken_flag = pstat#set_broken_flag
  method clear_broken_flag = pstat#clear_broken_flag
  method broken_flag = pstat#broken_flag

  method set_ns_alias_flag = pstat#set_ns_alias_flag
  method clear_ns_alias_flag = pstat#clear_ns_alias_flag
  method ns_alias_flag = pstat#ns_alias_flag

  method set_end_of_objc_meth_sel_flag = pstat#set_end_of_objc_meth_sel_flag
  method clear_end_of_objc_meth_sel_flag = pstat#clear_end_of_objc_meth_sel_flag
  method end_of_objc_meth_sel_flag = pstat#end_of_objc_meth_sel_flag

  method set_end_of_objc_meth_type_flag = pstat#set_end_of_objc_meth_type_flag
  method clear_end_of_objc_meth_type_flag = pstat#clear_end_of_objc_meth_type_flag
  method end_of_objc_meth_type_flag = pstat#end_of_objc_meth_type_flag

  method set_end_of_objc_property_attrs_decl_flag = pstat#set_end_of_objc_property_attrs_decl_flag
  method clear_end_of_objc_property_attrs_decl_flag = pstat#clear_end_of_objc_property_attrs_decl_flag
  method end_of_objc_property_attrs_decl_flag = pstat#end_of_objc_property_attrs_decl_flag

  method set_end_of_objc_protocol_ref_list_flag = pstat#set_end_of_objc_protocol_ref_list_flag
  method clear_end_of_objc_protocol_ref_list_flag = pstat#clear_end_of_objc_protocol_ref_list_flag
  method end_of_objc_protocol_ref_list_flag = pstat#end_of_objc_protocol_ref_list_flag

  method set_end_of_decl_spec_macro_call_flag = pstat#set_end_of_decl_spec_macro_call_flag
  method clear_end_of_decl_spec_macro_call_flag = pstat#clear_end_of_decl_spec_macro_call_flag
  method end_of_decl_spec_macro_call_flag = pstat#end_of_decl_spec_macro_call_flag

  method set_end_of_attr_macro_call_flag = pstat#set_end_of_attr_macro_call_flag
  method clear_end_of_attr_macro_call_flag = pstat#clear_end_of_attr_macro_call_flag
  method end_of_attr_macro_call_flag = pstat#end_of_attr_macro_call_flag

  method set_end_of_type_macro_call_flag = pstat#set_end_of_type_macro_call_flag
  method clear_end_of_type_macro_call_flag = pstat#clear_end_of_type_macro_call_flag
  method end_of_type_macro_call_flag = pstat#end_of_type_macro_call_flag

  method set_str_flag = pstat#set_str_flag
  method clear_str_flag = pstat#clear_str_flag
  method str_flag = pstat#str_flag

  method set_ty_param_rhs_flag = pstat#set_ty_param_rhs_flag
  method clear_ty_param_rhs_flag = pstat#clear_ty_param_rhs_flag
  method ty_param_rhs_flag = pstat#ty_param_rhs_flag

  method set_end_of_if_head_flag = pstat#set_end_of_if_head_flag
  method clear_end_of_if_head_flag = pstat#clear_end_of_if_head_flag
  method end_of_if_head_flag = pstat#end_of_if_head_flag

  method set_end_of_id_macro_call_flag = pstat#set_end_of_id_macro_call_flag
  method clear_end_of_id_macro_call_flag = pstat#clear_end_of_id_macro_call_flag
  method end_of_id_macro_call_flag = pstat#end_of_id_macro_call_flag

  method set_end_of_literal_macro_call_flag = pstat#set_end_of_literal_macro_call_flag
  method clear_end_of_literal_macro_call_flag = pstat#clear_end_of_literal_macro_call_flag
  method end_of_literal_macro_call_flag = pstat#end_of_literal_macro_call_flag

  method set_end_of_decltype_flag = pstat#set_end_of_decltype_flag
  method clear_end_of_decltype_flag = pstat#clear_end_of_decltype_flag
  method end_of_decltype_flag = pstat#end_of_decltype_flag

  method set_end_of_noptr_dtor_paren_flag = pstat#set_end_of_noptr_dtor_paren_flag
  method clear_end_of_noptr_dtor_paren_flag = pstat#clear_end_of_noptr_dtor_paren_flag
  method end_of_noptr_dtor_paren_flag = pstat#end_of_noptr_dtor_paren_flag

  method set_end_of_sizeof_flag = pstat#set_end_of_sizeof_flag
  method clear_end_of_sizeof_flag = pstat#clear_end_of_sizeof_flag
  method end_of_sizeof_flag = pstat#end_of_sizeof_flag

  method set_end_of_handler_head_flag = pstat#set_end_of_handler_head_flag
  method clear_end_of_handler_head_flag = pstat#clear_end_of_handler_head_flag
  method end_of_handler_head_flag = pstat#end_of_handler_head_flag

  method set_end_of_broken_decl_section_flag = pstat#set_end_of_broken_decl_section_flag
  method clear_end_of_broken_decl_section_flag = pstat#clear_end_of_broken_decl_section_flag
  method end_of_broken_decl_section_flag = pstat#end_of_broken_decl_section_flag

  method set_end_of_label_flag = pstat#set_end_of_label_flag
  method clear_end_of_label_flag = pstat#clear_end_of_label_flag
  method end_of_label_flag = pstat#end_of_label_flag

  method set_end_of_mem_initializer_flag = pstat#set_end_of_mem_initializer_flag
  method clear_end_of_mem_initializer_flag = pstat#clear_end_of_mem_initializer_flag
  method end_of_mem_initializer_flag = pstat#end_of_mem_initializer_flag

  method set_attr_flag = pstat#set_attr_flag
  method clear_attr_flag = pstat#clear_attr_flag
  method attr_flag = pstat#attr_flag

  method set_linkage_spec_flag = pstat#set_linkage_spec_flag
  method clear_linkage_spec_flag = pstat#clear_linkage_spec_flag
  method linkage_spec_flag = pstat#linkage_spec_flag

  method set_condition_flag = pstat#set_condition_flag
  method clear_condition_flag = pstat#clear_condition_flag
  method condition_flag = pstat#condition_flag

  method set_mem_acc_flag = pstat#set_mem_acc_flag
  method clear_mem_acc_flag = pstat#clear_mem_acc_flag
  method mem_acc_flag = pstat#mem_acc_flag

  method set_using_flag = pstat#set_using_flag
  method clear_using_flag = pstat#clear_using_flag
  method using_flag = pstat#using_flag

  method set_mock_qualifier_flag = pstat#set_mock_qualifier_flag
  method clear_mock_qualifier_flag = pstat#clear_mock_qualifier_flag
  method mock_qualifier_flag = pstat#mock_qualifier_flag

  method set_end_of_str_section_flag = pstat#set_end_of_str_section_flag
  method clear_end_of_str_section_flag = pstat#clear_end_of_str_section_flag
  method end_of_str_section_flag = pstat#end_of_str_section_flag

  method set_new_flag = pstat#set_new_flag
  method clear_new_flag = pstat#clear_new_flag
  method new_flag = pstat#new_flag

  method set_concept_flag = pstat#set_concept_flag
  method clear_concept_flag = pstat#clear_concept_flag
  method concept_flag = pstat#concept_flag

  method set_requires_clause_flag = pstat#set_requires_clause_flag
  method clear_requires_clause_flag = pstat#clear_requires_clause_flag
  method requires_clause_flag = pstat#requires_clause_flag

  method set_rhs_flag = pstat#set_rhs_flag
  method clear_rhs_flag = pstat#clear_rhs_flag
  method rhs_flag = pstat#rhs_flag

  method set_eq_init_flag = pstat#set_eq_init_flag
  method clear_eq_init_flag = pstat#clear_eq_init_flag
  method eq_init_flag = pstat#eq_init_flag

  method set_alias_flag = pstat#set_alias_flag
  method clear_alias_flag = pstat#clear_alias_flag
  method alias_flag = pstat#alias_flag

  method set_trailing_retty_flag = pstat#set_trailing_retty_flag
  method clear_trailing_retty_flag = pstat#clear_trailing_retty_flag
  method trailing_retty_flag = pstat#trailing_retty_flag

  method enter_pp_ifx_d = pstat#enter_pp_ifx_d
  method exit_pp_ifx_d = pstat#exit_pp_ifx_d
  method pp_ifx_d_flag = pstat#pp_ifx_d_flag

  method pp_top_label = pstat#pp_top_label
  method set_pp_top_label = pstat#set_pp_top_label

  method add_pp_elif = pstat#add_pp_elif
  method pp_elif_flag = pstat#pp_elif_flag

  method add_pp_else = pstat#add_pp_else
  method pp_else_flag = pstat#pp_else_flag

  method clear_lbrace_info = pstat#clear_lbrace_info
  method set_lbrace_info = pstat#set_lbrace_info
  method get_lbrace_info = pstat#get_lbrace_info
  method incr_lbrace_info = pstat#incr_lbrace_info
  method decr_lbrace_info = pstat#decr_lbrace_info
  method clear_rbrace_info = pstat#clear_rbrace_info
  method set_rbrace_info = pstat#set_rbrace_info
  method get_rbrace_info = pstat#get_rbrace_info
  method incr_rbrace_info = pstat#incr_rbrace_info
  method decr_rbrace_info = pstat#decr_rbrace_info
  method set_odd_info = pstat#set_odd_info
  method get_odd_info = pstat#get_odd_info
  method set_broken_info = pstat#set_broken_info
  method get_broken_info = pstat#get_broken_info
  method set_paren_closing_info = pstat#set_paren_closing_info
  method get_paren_closing_info = pstat#get_paren_closing_info
  method set_brace_paren_closing_info = pstat#set_brace_paren_closing_info
  method get_brace_paren_closing_info = pstat#get_brace_paren_closing_info
  method set_brace_closing_info = pstat#set_brace_closing_info
  method incr_brace_closing_info = pstat#incr_brace_closing_info
  method get_brace_closing_info = pstat#get_brace_closing_info
  method set_brace_opening_info = pstat#set_brace_opening_info
  method clear_brace_opening_info = pstat#clear_brace_opening_info
  method get_brace_opening_info = pstat#get_brace_opening_info
  method set_func_head_info = pstat#set_func_head_info
  method get_func_head_info = pstat#get_func_head_info
  method set_broken_func_head_info = pstat#set_broken_func_head_info
  method get_broken_func_head_info = pstat#get_broken_func_head_info
  method set_templ_closing_info = pstat#set_templ_closing_info
  method get_templ_closing_info = pstat#get_templ_closing_info
  method set_func_body_info = pstat#set_func_body_info
  method get_func_body_info = pstat#get_func_body_info
  method set_semicolon_info = pstat#set_semicolon_info
  method clear_semicolon_info = pstat#clear_semicolon_info
  method get_semicolon_info = pstat#get_semicolon_info
  method set_comma_info = pstat#set_comma_info
  method get_comma_info = pstat#get_comma_info
  method set_cond_expr_info = pstat#set_cond_expr_info
  method get_cond_expr_info = pstat#get_cond_expr_info
  method set_cond_expr__info = pstat#set_cond_expr__info
  method get_cond_expr__info = pstat#get_cond_expr__info
  method set_asm_info = pstat#set_asm_info
  method get_asm_info = pstat#get_asm_info
  method set_begin_asm_info = pstat#set_begin_asm_info
  method get_begin_asm_info = pstat#get_begin_asm_info
  method set_lack_of_dtor_info = pstat#set_lack_of_dtor_info
  method get_lack_of_dtor_info = pstat#get_lack_of_dtor_info
  method set_class_brace_opening_info = pstat#set_class_brace_opening_info
  method get_class_brace_opening_info = pstat#get_class_brace_opening_info
  method set_follows_comma_info = pstat#set_follows_comma_info
  method get_follows_comma_info = pstat#get_follows_comma_info
  method set_cond_sub_info = pstat#set_cond_sub_info
  method get_cond_sub_info = pstat#get_cond_sub_info
  method get_pp_if_compl_info = pstat#get_pp_if_compl_info
  method get_pp_if_compl_brace_info = pstat#get_pp_if_compl_brace_info
  method get_pp_if_compl_paren_info = pstat#get_pp_if_compl_paren_info
  method reset_pp_if_compl_info = pstat#reset_pp_if_compl_info

  method alt_pp_branch_flag = pstat#alt_pp_branch_flag

  method set_in_body_brace_flag () =
    [%debug_log "in_body_brace_flag set"];
    in_body_brace_flag <- true;
    in_body_brace_level <- 0

  method clear_in_body_brace_flag () =
    [%debug_log "in_body_brace_flag_cleared"];
    in_body_brace_flag <- false;
    in_body_brace_level <- 0

  method in_body_brace_flag = in_body_brace_flag

  method open_in_body_brace () =
    if in_body_brace_flag then begin
      [%debug_log "opening in_body_brace"];
      in_body_brace_level <- in_body_brace_level + 1
    end

  method close_in_body_brace () =
    if in_body_brace_flag && in_body_brace_level > 0 then begin
      [%debug_log "closing in_body_brace"];
      in_body_brace_level <- in_body_brace_level - 1
    end

  method in_body_brace_level = in_body_brace_level

  method enter_sizeof_ty = pstat#enter_sizeof_ty
  method exit_sizeof_ty = pstat#exit_sizeof_ty
  method sizeof_ty_flag = pstat#sizeof_ty_flag

  method enter_lambda_intro = pstat#enter_lambda_intro
  method exit_lambda_intro = pstat#exit_lambda_intro
  method lambda_intro_flag = pstat#lambda_intro_flag

  method enter_ctor_init = pstat#enter_ctor_init
  method exit_ctor_init = pstat#exit_ctor_init
  method ctor_init_flag = pstat#ctor_init_flag

  method enter_stmts = pstat#enter_stmts
  method exit_stmts = pstat#exit_stmts
  method stmts_flag = pstat#stmts_flag

  method enter_base_clause = pstat#enter_base_clause
  method exit_base_clause = pstat#exit_base_clause
  method base_clause_flag = pstat#base_clause_flag

  method enter_asm = pstat#enter_asm
  method exit_asm = pstat#exit_asm
  method asm_flag = pstat#asm_flag
  method asm_paren_level = pstat#asm_paren_level

  method enter_braced_asm = pstat#enter_braced_asm
  method exit_braced_asm = pstat#exit_braced_asm
  method braced_asm_flag = pstat#braced_asm_flag

  method enter_asm_block = pstat#enter_asm_block
  method exit_asm_block = pstat#exit_asm_block
  method asm_block_flag = pstat#asm_block_flag

  method enter_enum_head = pstat#enter_enum_head
  method exit_enum_head = pstat#exit_enum_head
  method enum_head_flag = pstat#enum_head_flag

  method enter_ty_param = pstat#enter_ty_param
  method exit_ty_param = pstat#exit_ty_param
  method ty_param_flag = pstat#ty_param_flag

  method enter_exec_config = pstat#enter_exec_config
  method exit_exec_config = pstat#exit_exec_config
  method exec_config_flag = pstat#exec_config_flag

  method enter_decltype = pstat#enter_decltype
  method exit_decltype = pstat#exit_decltype
  method decltype_flag = pstat#decltype_flag

  method enter_alignas = pstat#enter_alignas
  method exit_alignas = pstat#exit_alignas
  method alignas_flag = pstat#alignas_flag

  method enter_alignof = pstat#enter_alignof
  method exit_alignof = pstat#exit_alignof
  method alignof_flag = pstat#alignof_flag

  method enter_noexcept = pstat#enter_noexcept
  method exit_noexcept = pstat#exit_noexcept
  method noexcept_flag = pstat#noexcept_flag

  method enter_macro_arg = pstat#enter_macro_arg
  method exit_macro_arg = pstat#exit_macro_arg
  method macro_arg_flag = pstat#macro_arg_flag
  method macro_arg_level = pstat#macro_arg_level

  method set_body_head_flag () =
    [%debug_log "body_head_flag set"];
    body_head_flag <- true

  method clear_body_head_flag () =
    if body_head_flag then begin
      [%debug_log "body_head_flag cleared"];
      body_head_flag <- false
    end

  method body_head_flag = body_head_flag

  method set_typedef_flag () =
    [%debug_log "typedef_flag set"];
    typedef_flag <- true

  method clear_typedef_flag () =
    if typedef_flag then begin
      [%debug_log "typedef_flag cleared"];
      typedef_flag <- false
    end

  method typedef_flag = typedef_flag

  method set_for_range_init_flag () =
    [%debug_log "for_range_init_flag set"];
    for_range_init_flag <- true

  method clear_for_range_init_flag () =
    if for_range_init_flag then begin
      [%debug_log "for_range_init_flag cleared"];
      for_range_init_flag <- false
    end

  method for_range_init_flag = for_range_init_flag

  method set_ty_param_key_flag () =
    [%debug_log "ty_param_key_flag set"];
    ty_param_key_flag <- true

  method clear_ty_param_key_flag () =
    if ty_param_key_flag then begin
      [%debug_log "ty_param_key_flag cleared"];
      ty_param_key_flag <- false
    end

  method ty_param_key_flag = ty_param_key_flag

  method set_param_head_flag () =
    [%debug_log "param_head_flag set"];
    param_head_flag <- true

  method clear_param_head_flag () =
    if param_head_flag then begin
      [%debug_log "param_head_flag cleared"];
      param_head_flag <- false
    end

  method param_head_flag = param_head_flag

  method set_cast_key_flag () =
    if not self#pp_line_flag then begin
      [%debug_log "cast_key_flag set"];
      cast_key_flag <- true
    end

  method clear_cast_key_flag () =
    if cast_key_flag then begin
      [%debug_log "cast_key_flag cleared"];
      cast_key_flag <- false
    end

  method cast_key_flag = cast_key_flag

  method set_conv_func_id_flag () =
    [%debug_log "conv_func_id_flag set"];
    conv_func_id_flag <- true

  method clear_conv_func_id_flag () =
    if conv_func_id_flag then begin
      [%debug_log "conv_func_id_flag cleared"];
      conv_func_id_flag <- false
    end

  method conv_func_id_flag = conv_func_id_flag

  method set_init_flag () =
    [%debug_log "init_flag set"];
    init_flag <- true

  method clear_init_flag () =
    if init_flag then begin
      [%debug_log "init_flag cleared"];
      init_flag <- false
    end

  method init_flag = init_flag

  method set_pp_odd_flag () =
    [%debug_log "pp_odd_flag set"];
    pp_odd_flag <- true

  method clear_pp_odd_flag () =
    if pp_odd_flag then begin
      [%debug_log "pp_odd_flag cleared"];
      pp_odd_flag <- false
    end

  method pp_odd_flag = pp_odd_flag

  method set_expr_flag () =
    [%debug_log "expr_flag set"];
    expr_flag <- true;
    try
      match self#pstat#bracket_stack_top with
      | BK_TEMPL_PARAM c | BK_TEMPL_ARG c -> c.tpac_expr_flag <- true
      | _ -> ()
    with
      _ -> ()


  method clear_expr_flag () =
    if expr_flag then begin
      [%debug_log "expr_flag cleared"];
      expr_flag <- false
    end

  method expr_flag = expr_flag

  method set_virtual_func_flag () =
    [%debug_log "virtual_func_flag set"];
    virtual_func_flag <- true

  method clear_virtual_func_flag () =
    if virtual_func_flag then begin
      [%debug_log "virtual_func_flag cleared"];
      virtual_func_flag <- false
    end

  method virtual_func_flag = virtual_func_flag

  method set_value_flag () =
    [%debug_log "value_flag set"];
    value_flag <- true

  method clear_value_flag () =
    if value_flag then begin
      [%debug_log "value_flag cleared"];
      value_flag <- false
    end

  method value_flag = value_flag

  method set_dtor_if_section_flag () =
    [%debug_log "dtor_if_section_flag set"];
    dtor_if_section_flag <- true

  method clear_dtor_if_section_flag () =
    if dtor_if_section_flag then begin
      [%debug_log "dtor_if_section_flag cleared"];
      dtor_if_section_flag <- false
    end

  method dtor_if_section_flag = dtor_if_section_flag

  method objc_flag = objc_flag

  method set_using_ns_flag () =
    [%debug_log "using_ns_flag set"];
    using_ns_flag <- true

  method clear_using_ns_flag () =
    if using_ns_flag then begin
      [%debug_log "using_ns_flag cleared"];
      using_ns_flag <- false
    end

  method using_ns_flag = using_ns_flag

  method set_pp_params_flag () =
    [%debug_log "pp_params_flag set"];
    pp_params_flag <- true

  method clear_pp_params_flag () =
    if pp_params_flag then begin
      [%debug_log "pp_params_flag cleared"];
      pp_params_flag <- false
    end

  method pp_params_flag = pp_params_flag

  method enter_const () =
    let tlv = self#templ_param_arg_level in
    let plv = self#paren_level in
    Stack.push (tlv, plv) const_stack;
    [%debug_log "entering const (tlv:%d,plv%d)" tlv plv]

  method exit_const () =
    try
      let (tlv, plv) = Stack.top const_stack in
      if tlv = self#templ_param_arg_level && plv = self#paren_level then begin
        [%debug_log "exiting const..."];
        let (t, p) = Stack.pop const_stack in
        let _ = t in
        let _ = p in
        [%debug_log "const exited (tlv:%d,plv:%d)" t p];
      end
    with
      Stack.Empty -> ()

  method const_flag = not (Stack.is_empty const_stack)

end (* of class env *)
]

module type STATE_T = sig
  val env           : env
end


module F (Stat : STATE_T) = struct

  include Stat

end (* of functor Parser_aux.F *)