cgrammar 0.9.1

A comprehensive C language grammar parser library written in Rust, implementing the C23 standard (ISO/IEC 9899:2023).
Documentation
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
//! Visitor pattern implementation for traversing the C AST.
//!
//! This module provides a flexible visitor pattern for traversing and analyzing
//! C abstract syntax trees. It distinguishes between different semantic types
//! of identifiers (variable names, type names, labels, etc.) to enable more
//! precise analysis and transformation of C code.
//!
//! # Example
//!
//! ```ignore
//! struct MyVisitor {
//!     variable_count: usize,
//! }
//!
//! impl<'a> Visitor<'a> for MyVisitor {
//!     type Result = ();
//!
//!     fn visit_variable_name(&mut self, id: &'a Identifier) {
//!         self.variable_count += 1;
//!         Self::Result::output()
//!     }
//! }
//! ```

use std::ops::ControlFlow;

use crate::{Identifier, ast::*};

/// A trait that represents the result type of visitor operations.
///
/// This trait allows visitor methods to return different result types:
/// - `()` for simple traversal without returning a value
/// - `ControlFlow<T>` for early termination with a value
/// - Custom types implementing `VisitorResult` for complex scenarios
///
/// The trait provides mechanisms to work with Rust's `?` operator equivalent
/// through the `branch()` and `from_branch()` methods.
pub trait VisitorResult {
    /// The type of value returned when breaking early from traversal.
    type Residual;

    /// Creates a successful output value.
    fn output() -> Self;

    /// Creates a result from a residual value (used when breaking early).
    fn from_residual(residual: Self::Residual) -> Self;

    /// Creates a result from a control flow, handling both continue and break
    /// cases.
    fn from_branch(b: ControlFlow<Self::Residual>) -> Self;

    /// Converts this result into a control flow for early termination handling.
    fn branch(self) -> ControlFlow<Self::Residual>;
}

/// Implementation of `VisitorResult` for unit type `()`.
///
/// This implementation is used when the visitor doesn't need to return values
/// or break early from traversal. It simply processes each node and continues.
impl VisitorResult for () {
    type Residual = core::convert::Infallible;

    fn output() -> Self {}

    fn from_residual(_: Self::Residual) -> Self {}

    fn from_branch(_: ControlFlow<Self::Residual>) -> Self {}

    fn branch(self) -> ControlFlow<Self::Residual> {
        ControlFlow::Continue(())
    }
}

impl<T> VisitorResult for Result<(), T> {
    type Residual = T;

    fn output() -> Self {
        Ok(())
    }

    fn from_residual(residual: Self::Residual) -> Self {
        Err(residual)
    }

    fn from_branch(b: ControlFlow<Self::Residual>) -> Self {
        match b {
            ControlFlow::Break(r) => Err(r),
            ControlFlow::Continue(()) => Ok(()),
        }
    }

    fn branch(self) -> ControlFlow<Self::Residual> {
        match self {
            Ok(()) => ControlFlow::Continue(()),
            Err(r) => ControlFlow::Break(r),
        }
    }
}

/// Implementation of `VisitorResult` for `ControlFlow<T>`.
///
/// This implementation allows visitors to return `ControlFlow::Break(value)`
/// to terminate traversal early and `ControlFlow::Continue(())` to continue.
impl<T> VisitorResult for ControlFlow<T> {
    type Residual = T;

    fn output() -> Self {
        ControlFlow::Continue(())
    }

    fn from_residual(residual: Self::Residual) -> Self {
        ControlFlow::Break(residual)
    }

    fn from_branch(b: Self) -> Self {
        b
    }

    fn branch(self) -> Self {
        self
    }
}

/// The main visitor trait for traversing C AST nodes.
///
/// Implementers of this trait can customize behavior for different AST node
/// types. The trait provides default implementations that perform recursive
/// traversal via corresponding `walk_*` functions.
///
/// # Result Type
///
/// The associated `Result` type determines how visitor methods report their
/// outcome. Common choices are:
/// - `()` for simple analysis without early termination
/// - `ControlFlow<T>` for analysis that may terminate early with a result
///
/// # Default Behavior
///
/// Each visit method has a default implementation that calls the corresponding
/// `walk_*` function, which performs recursive traversal of child nodes.
/// Override a visit method to insert custom logic before, after, or instead of
/// the default traversal.
pub trait Visitor<'a> {
    /// The result type produced by visitor operations.
    type Result: VisitorResult;

    /// Visits a variable name identifier.
    ///
    /// This is called when encountering an identifier in an expression context
    /// (e.g., variable references) or in a declarator (e.g., variable
    /// declarations).
    ///
    /// # Examples
    /// - `x` in `x = 5`
    /// - `printf` in `printf("hello")`
    /// - Variable declarations: `int x;`
    fn visit_variable_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a typedef name identifier.
    ///
    /// This is called when encountering a typedef name used as a type
    /// specifier.
    ///
    /// # Examples
    /// - `size_t` in `size_t len;`
    /// - `FILE` in `FILE* fp;`
    fn visit_type_name_identifier(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enumeration constant identifier.
    ///
    /// This is called when encountering an enumeration constant in an
    /// expression.
    ///
    /// # Examples
    /// - `RED` in `color = RED;` where RED is an enum constant
    fn visit_enum_constant(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a label name identifier.
    ///
    /// This is called when encountering a goto label or a label in switch
    /// statements.
    ///
    /// # Examples
    /// - `error_handler:` in label declarations
    /// - `error_handler` in `goto error_handler;`
    fn visit_label_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a struct or union member name identifier.
    ///
    /// This is called when accessing a struct/union member via `.` or `->`
    /// operators, or in designators of initializers.
    ///
    /// # Examples
    /// - `x` in `point.x`
    /// - `next` in `node->next`
    fn visit_member_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a struct type identifier.
    ///
    /// This is called when encountering a struct name in a struct specifier.
    ///
    /// # Examples
    /// - `Point` in `struct Point { int x; int y; }`
    /// - `Node` in `struct Node* next;`
    fn visit_struct_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enum type identifier.
    ///
    /// This is called when encountering an enum name in an enum specifier.
    ///
    /// # Examples
    /// - `Color` in `enum Color { RED, GREEN, BLUE }`
    /// - `Status` in `enum Status code;`
    fn visit_enum_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enumerator name identifier.
    ///
    /// This is called when encountering an enumerator in an enum definition.
    ///
    /// # Examples
    /// - `RED` in `enum Color { RED, GREEN, BLUE }`
    /// - Each name in enumeration values
    fn visit_enumerator_name(&mut self, _: &'a Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a translation unit (the root of a C program).
    ///
    /// This is the top-level method that traverses the entire AST.
    /// Override this to perform initialization or finalization of analysis.
    fn visit_translation_unit(&mut self, tu: &'a TranslationUnit) -> Self::Result {
        walk_translation_unit(self, tu)
    }

    /// Visits an external declaration (function definition or global
    /// declaration).
    fn visit_external_declaration(&mut self, d: &'a ExternalDeclaration) -> Self::Result {
        walk_external_declaration(self, d)
    }

    /// Visits a function definition.
    fn visit_function_definition(&mut self, f: &'a FunctionDefinition) -> Self::Result {
        walk_function_definition(self, f)
    }

    /// Visits an attribute specifier.
    fn visit_attribute_specifier(&mut self, a: &'a AttributeSpecifier) -> Self::Result {
        walk_attribute_specifier(self, a)
    }

    /// Visits an attribute.
    fn visit_attribute(&mut self, _: &'a Attribute) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an asm attribute specifier.
    fn visit_asm_attribute_specifier(&mut self, _: &'a StringLiterals) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a statement.
    fn visit_statement(&mut self, s: &'a Statement) -> Self::Result {
        walk_statement(self, s)
    }

    /// Visits an unlabeled statement.
    fn visit_unlabeled_statement(&mut self, s: &'a UnlabeledStatement) -> Self::Result {
        walk_unlabeled_statement(self, s)
    }

    /// Visits an expression.
    fn visit_expression(&mut self, e: &'a Expression) -> Self::Result {
        walk_expression(self, e)
    }

    /// Visits a declaration.
    fn visit_declaration(&mut self, d: &'a Declaration) -> Self::Result {
        walk_declaration(self, d)
    }

    /// Visits a declarator.
    fn visit_declarator(&mut self, d: &'a Declarator) -> Self::Result {
        walk_declarator(self, d)
    }

    /// Visits a direct declarator.
    fn visit_direct_declarator(&mut self, d: &'a DirectDeclarator) -> Self::Result {
        walk_direct_declarator(self, d)
    }

    /// Visits an initializer.
    fn visit_initializer(&mut self, i: &'a Initializer) -> Self::Result {
        walk_initializer(self, i)
    }

    /// Visits a braced initializer.
    fn visit_braced_initializer(&mut self, b: &'a BracedInitializer) -> Self::Result {
        walk_braced_initializer(self, b)
    }

    /// Visits a designated initializer.
    fn visit_designated_initializer(&mut self, d: &'a DesignatedInitializer) -> Self::Result {
        walk_designated_initializer(self, d)
    }

    /// Visits a designation.
    fn visit_designation(&mut self, d: &'a Designation) -> Self::Result {
        walk_designation(self, d)
    }

    /// Visits a designator.
    fn visit_designator(&mut self, d: &'a Designator) -> Self::Result {
        walk_designator(self, d)
    }

    /// Visits a constant expression.
    fn visit_constant_expression(&mut self, c: &'a ConstantExpression) -> Self::Result {
        walk_constant_expression(self, c)
    }

    /// Visits a postfix expression.
    fn visit_postfix_expression(&mut self, p: &'a PostfixExpression) -> Self::Result {
        walk_postfix_expression(self, p)
    }

    /// Visits a primary expression.
    fn visit_primary_expression(&mut self, p: &'a PrimaryExpression) -> Self::Result {
        walk_primary_expression(self, p)
    }

    /// Visits a generic selection.
    fn visit_generic_selection(&mut self, g: &'a GenericSelection) -> Self::Result {
        walk_generic_selection(self, g)
    }

    /// Visits a unary expression.
    fn visit_unary_expression(&mut self, u: &'a UnaryExpression) -> Self::Result {
        walk_unary_expression(self, u)
    }

    /// Visits a cast expression.
    fn visit_cast_expression(&mut self, c: &'a CastExpression) -> Self::Result {
        walk_cast_expression(self, c)
    }

    /// Visits a compound statement (block of statements).
    fn visit_compound_statement(&mut self, c: &'a CompoundStatement) -> Self::Result {
        walk_compound_statement(self, c)
    }

    /// Visits a block item.
    fn visit_block_item(&mut self, bi: &'a BlockItem) -> Self::Result {
        walk_block_item(self, bi)
    }

    /// Visits declaration specifiers.
    fn visit_declaration_specifiers(&mut self, s: &'a DeclarationSpecifiers) -> Self::Result {
        walk_declaration_specifiers(self, s)
    }

    /// Visits a type specifier or qualifier.
    fn visit_type_specifier_qualifier(&mut self, x: &'a TypeSpecifierQualifier) -> Self::Result {
        walk_type_specifier_qualifier(self, x)
    }

    /// Visits a type specifier.
    fn visit_type_specifier(&mut self, ts: &'a TypeSpecifier) -> Self::Result {
        walk_type_specifier(self, ts)
    }

    /// Visits an atomic type specifier.
    fn visit_atomic_type_specifier(&mut self, a: &'a AtomicTypeSpecifier) -> Self::Result {
        walk_atomic_type_specifier(self, a)
    }

    /// Visits a typeof specifier.
    fn visit_typeof(&mut self, t: &'a TypeofSpecifier) -> Self::Result {
        walk_typeof(self, t)
    }

    /// Visits a specifier qualifier list.
    fn visit_specifier_qualifier_list(&mut self, s: &'a SpecifierQualifierList) -> Self::Result {
        walk_specifier_qualifier_list(self, s)
    }

    /// Visits a type name.
    fn visit_type_name(&mut self, tn: &'a TypeName) -> Self::Result {
        walk_type_name(self, tn)
    }

    /// Visits an abstract declarator.
    fn visit_abstract_declarator(&mut self, a: &'a AbstractDeclarator) -> Self::Result {
        walk_abstract_declarator(self, a)
    }

    /// Visits a direct abstract declarator.
    fn visit_direct_abstract_declarator(&mut self, d: &'a DirectAbstractDeclarator) -> Self::Result {
        walk_direct_abstract_declarator(self, d)
    }

    /// Visits a labeled statement.
    fn visit_labeled_statement(&mut self, ls: &'a LabeledStatement) -> Self::Result {
        walk_labeled_statement(self, ls)
    }

    /// Visits a label.
    fn visit_label(&mut self, l: &'a Label) -> Self::Result {
        walk_label(self, l)
    }

    /// Visits an expression statement.
    fn visit_expression_statement(&mut self, e: &'a ExpressionStatement) -> Self::Result {
        walk_expression_statement(self, e)
    }

    /// Visits a primary block.
    fn visit_primary_block(&mut self, pb: &'a PrimaryBlock) -> Self::Result {
        walk_primary_block(self, pb)
    }

    /// Visits a jump statement.
    fn visit_jump_statement(&mut self, j: &'a JumpStatement) -> Self::Result {
        walk_jump_statement(self, j)
    }

    /// Visits a selection statement.
    fn visit_selection_statement(&mut self, s: &'a SelectionStatement) -> Self::Result {
        walk_selection_statement(self, s)
    }

    /// Visits an iteration statement.
    fn visit_iteration_statement(&mut self, i: &'a IterationStatement) -> Self::Result {
        walk_iteration_statement(self, i)
    }

    /// Visits a for init clause.
    fn visit_for_init(&mut self, fi: &'a ForInit) -> Self::Result {
        walk_for_init(self, fi)
    }

    /// Visits a binary expression.
    fn visit_binary_expression(&mut self, b: &'a BinaryExpression) -> Self::Result {
        walk_binary_expression(self, b)
    }

    /// Visits a conditional expression.
    fn visit_conditional_expression(&mut self, c: &'a ConditionalExpression) -> Self::Result {
        walk_conditional_expression(self, c)
    }

    /// Visits an assignment expression.
    fn visit_assignment_expression(&mut self, a: &'a AssignmentExpression) -> Self::Result {
        walk_assignment_expression(self, a)
    }

    /// Visits a comma expression.
    fn visit_comma_expression(&mut self, c: &'a CommaExpression) -> Self::Result {
        walk_comma_expression(self, c)
    }

    /// Visits a binary operator.
    fn visit_binary_operator(&mut self, _: &'a BinaryOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an assignment operator.
    fn visit_assignment_operator(&mut self, _: &'a AssignmentOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a compound literal.
    fn visit_compound_literal(&mut self, cl: &'a CompoundLiteral) -> Self::Result {
        walk_compound_literal(self, cl)
    }

    /// Visits a storage class specifier.
    fn visit_storage_class_specifier(&mut self, _: &'a StorageClassSpecifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a unary operator.
    fn visit_unary_operator(&mut self, _: &'a UnaryOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an init declarator.
    fn visit_init_declarator(&mut self, id: &'a InitDeclarator) -> Self::Result {
        walk_init_declarator(self, id)
    }

    /// Visits a static assert declaration.
    fn visit_static_assert_declaration(&mut self, sa: &'a StaticAssertDeclaration) -> Self::Result {
        walk_static_assert_declaration(self, sa)
    }

    /// Visits a static assert message.
    fn visit_static_assert_message(&mut self, _: &'a StringLiterals) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a declaration specifier.
    fn visit_declaration_specifier(&mut self, ds: &'a DeclarationSpecifier) -> Self::Result {
        walk_declaration_specifier(self, ds)
    }

    /// Visits a function specifier.
    fn visit_function_specifier(&mut self, _: &'a FunctionSpecifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a type qualifier.
    fn visit_type_qualifier(&mut self, _: &'a TypeQualifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an alignment specifier.
    fn visit_alignment_specifier(&mut self, a: &'a AlignmentSpecifier) -> Self::Result {
        walk_alignment_specifier(self, a)
    }

    /// Visits a struct or union specifier.
    fn visit_struct_union_specifier(&mut self, s: &'a StructOrUnionSpecifier) -> Self::Result {
        walk_struct_union_specifier(self, s)
    }

    /// Visits an enum specifier.
    fn visit_enum_specifier(&mut self, e: &'a EnumSpecifier) -> Self::Result {
        walk_enum_specifier(self, e)
    }

    /// Visits a struct or union keyword.
    fn visit_struct_or_union(&mut self, _: &'a StructOrUnion) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a member declaration.
    fn visit_member_declaration(&mut self, md: &'a MemberDeclaration) -> Self::Result {
        walk_member_declaration(self, md)
    }

    /// Visits a member declarator.
    fn visit_member_declarator(&mut self, md: &'a MemberDeclarator) -> Self::Result {
        walk_member_declarator(self, md)
    }

    /// Visits an enumerator.
    fn visit_enumerator(&mut self, e: &'a Enumerator) -> Self::Result {
        walk_enumerator(self, e)
    }

    /// Visits a pointer.
    fn visit_pointer(&mut self, p: &'a Pointer) -> Self::Result {
        walk_pointer(self, p)
    }

    /// Visits a pointer or block indicator.
    fn visit_pointer_or_block(&mut self, _: &'a PointerOrBlock) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an array declarator.
    fn visit_array_declarator(&mut self, d: &'a ArrayDeclarator) -> Self::Result {
        walk_array_declarator(self, d)
    }

    /// Visits a parameter type list.
    fn visit_parameter_type_list(&mut self, ptl: &'a ParameterTypeList) -> Self::Result {
        walk_parameter_type_list(self, ptl)
    }

    /// Visits a parameter declaration.
    fn visit_parameter_declaration(&mut self, pd: &'a ParameterDeclaration) -> Self::Result {
        walk_parameter_declaration(self, pd)
    }

    /// Visits a parameter declaration kind.
    fn visit_parameter_declaration_kind(&mut self, pdk: &'a ParameterDeclarationKind) -> Self::Result {
        walk_parameter_declaration_kind(self, pdk)
    }
}

macro_rules! tr {
    ($e:expr) => {{
        let br = $e.branch();
        if let ControlFlow::Break(res) = br {
            return V::Result::from_residual(res);
        }
    }};
}

/// Walk a translation unit.
pub fn walk_translation_unit<'a, V: Visitor<'a> + ?Sized>(v: &mut V, tu: &'a TranslationUnit) -> V::Result {
    for ed in &tu.external_declarations {
        tr!(v.visit_external_declaration(ed));
    }
    V::Result::output()
}

/// Walk an external declaration.
pub fn walk_external_declaration<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a ExternalDeclaration) -> V::Result {
    match d {
        ExternalDeclaration::Function(f) => v.visit_function_definition(f),
        ExternalDeclaration::Declaration(d) => v.visit_declaration(d),
    }
}

/// Walk a function definition.
pub fn walk_function_definition<'a, V: Visitor<'a> + ?Sized>(v: &mut V, f: &'a FunctionDefinition) -> V::Result {
    for attr in &f.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    tr!(v.visit_declaration_specifiers(&f.specifiers));
    tr!(v.visit_declarator(&f.declarator));
    v.visit_compound_statement(&f.body)
}

/// Walk a statement.
pub fn walk_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, s: &'a Statement) -> V::Result {
    match &s.kind {
        StatementKind::Labeled(ls) => v.visit_labeled_statement(ls),
        StatementKind::Unlabeled(u) => v.visit_unlabeled_statement(u),
    }
}

/// Walk a labeled statement.
pub fn walk_labeled_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, ls: &'a LabeledStatement) -> V::Result {
    tr!(v.visit_label(&ls.label));
    v.visit_statement(&ls.statement)
}

/// Walk a label.
pub fn walk_label<'a, V: Visitor<'a> + ?Sized>(v: &mut V, l: &'a Label) -> V::Result {
    match l {
        Label::Identifier { attributes, identifier } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier(attribute));
            }
            v.visit_label_name(identifier)
        }
        Label::Case { attributes, expression } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier(attribute));
            }
            v.visit_constant_expression(expression)
        }
        Label::Default { attributes } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier(attribute));
            }
            V::Result::output()
        }
    }
}

/// Walk an unlabeled statement.
pub fn walk_unlabeled_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, s: &'a UnlabeledStatement) -> V::Result {
    match s {
        UnlabeledStatement::Expression(es) => v.visit_expression_statement(es),
        UnlabeledStatement::Primary { attributes, block } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier(attribute));
            }
            v.visit_primary_block(block)
        }
        UnlabeledStatement::Jump { attributes, statement } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier(attribute));
            }
            v.visit_jump_statement(statement)
        }
    }
}

/// Walk an expression statement.
pub fn walk_expression_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, e: &'a ExpressionStatement) -> V::Result {
    if let Some(expr) = &e.expression {
        tr!(v.visit_expression(expr));
    }
    V::Result::output()
}

/// Walk a primary block.
pub fn walk_primary_block<'a, V: Visitor<'a> + ?Sized>(v: &mut V, pb: &'a PrimaryBlock) -> V::Result {
    match pb {
        PrimaryBlock::Compound(c) => v.visit_compound_statement(c),
        PrimaryBlock::Selection(sel) => v.visit_selection_statement(sel),
        PrimaryBlock::Iteration(iter) => v.visit_iteration_statement(iter),
    }
}

/// Walk a compound statement.
pub fn walk_compound_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, c: &'a CompoundStatement) -> V::Result {
    for item in &c.items {
        tr!(v.visit_block_item(item));
    }
    V::Result::output()
}

/// Walk a block item.
pub fn walk_block_item<'a, V: Visitor<'a> + ?Sized>(v: &mut V, bi: &'a BlockItem) -> V::Result {
    match bi {
        BlockItem::Declaration(d) => v.visit_declaration(d),
        BlockItem::Statement(u) => v.visit_unlabeled_statement(u),
        BlockItem::Label(l) => v.visit_label(l),
    }
}

/// Walk a selection statement.
pub fn walk_selection_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, s: &'a SelectionStatement) -> V::Result {
    match s {
        SelectionStatement::If { condition, then_stmt, else_stmt } => {
            tr!(v.visit_expression(condition));
            tr!(v.visit_statement(then_stmt));
            if let Some(e) = else_stmt {
                tr!(v.visit_statement(e));
            }
            V::Result::output()
        }
        SelectionStatement::Switch { expression, statement } => {
            tr!(v.visit_expression(expression));
            v.visit_statement(statement)
        }
    }
}

/// Walk an iteration statement.
pub fn walk_iteration_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, i: &'a IterationStatement) -> V::Result {
    match i {
        IterationStatement::While { condition, body } => {
            tr!(v.visit_expression(condition));
            v.visit_statement(body)
        }
        IterationStatement::DoWhile { body, condition } => {
            tr!(v.visit_statement(body));
            v.visit_expression(condition)
        }
        IterationStatement::For { init, condition, update, body } => {
            if let Some(i) = init {
                v.visit_for_init(i);
            }
            if let Some(c) = condition {
                tr!(v.visit_expression(c));
            }
            if let Some(u) = update {
                tr!(v.visit_expression(u));
            }
            v.visit_statement(body)
        }
        IterationStatement::Error => V::Result::output(),
    }
}

/// Walk a for init.
pub fn walk_for_init<'a, V: Visitor<'a> + ?Sized>(v: &mut V, fi: &'a ForInit) -> V::Result {
    match fi {
        ForInit::Expression(e) => v.visit_expression(e),
        ForInit::Declaration(d) => v.visit_declaration(d),
    }
}

/// Walk a jump statement.
pub fn walk_jump_statement<'a, V: Visitor<'a> + ?Sized>(v: &mut V, j: &'a JumpStatement) -> V::Result {
    match j {
        JumpStatement::Goto(id) => v.visit_label_name(id),
        JumpStatement::Continue | JumpStatement::Break => V::Result::output(),
        JumpStatement::Return(expr) => {
            if let Some(e) = expr {
                tr!(v.visit_expression(e));
            }
            V::Result::output()
        }
    }
}

/// Walk an expression.
pub fn walk_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, e: &'a Expression) -> V::Result {
    match &e.kind {
        ExpressionKind::Postfix(p) => v.visit_postfix_expression(p),
        ExpressionKind::Unary(u) => v.visit_unary_expression(u),
        ExpressionKind::Cast(c) => v.visit_cast_expression(c),
        ExpressionKind::Binary(b) => v.visit_binary_expression(b),
        ExpressionKind::Conditional(c) => v.visit_conditional_expression(c),
        ExpressionKind::Assignment(a) => v.visit_assignment_expression(a),
        ExpressionKind::Comma(c) => v.visit_comma_expression(c),
        ExpressionKind::Error => V::Result::output(),
    }
}

/// Walk a binary expression.
pub fn walk_binary_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, b: &'a BinaryExpression) -> V::Result {
    tr!(v.visit_expression(&b.left));
    tr!(v.visit_binary_operator(&b.operator));
    v.visit_expression(&b.right)
}

/// Walk a conditional expression.
pub fn walk_conditional_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, c: &'a ConditionalExpression) -> V::Result {
    tr!(v.visit_expression(&c.condition));
    tr!(v.visit_expression(&c.then_expr));
    v.visit_expression(&c.else_expr)
}

/// Walk an assignment expression.
pub fn walk_assignment_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, a: &'a AssignmentExpression) -> V::Result {
    tr!(v.visit_expression(&a.left));
    tr!(v.visit_assignment_operator(&a.operator));
    v.visit_expression(&a.right)
}

/// Walk a comma expression.
pub fn walk_comma_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, c: &'a CommaExpression) -> V::Result {
    for e in &c.expressions {
        tr!(v.visit_expression(e));
    }
    V::Result::output()
}

/// Walk a postfix expression.
pub fn walk_postfix_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, p: &'a PostfixExpression) -> V::Result {
    match p {
        PostfixExpression::Primary(pr) => v.visit_primary_expression(pr),
        PostfixExpression::ArrayAccess { array, index } => {
            tr!(v.visit_postfix_expression(array));
            v.visit_expression(index)
        }
        PostfixExpression::FunctionCall { function, arguments } => {
            tr!(v.visit_postfix_expression(function));
            for a in arguments {
                tr!(v.visit_expression(a));
            }
            V::Result::output()
        }
        PostfixExpression::MemberAccess { object, member } => {
            tr!(v.visit_postfix_expression(object));
            v.visit_member_name(member)
        }
        PostfixExpression::MemberAccessPtr { object, member } => {
            tr!(v.visit_postfix_expression(object));
            v.visit_member_name(member)
        }
        PostfixExpression::PostIncrement(inner) | PostfixExpression::PostDecrement(inner) => {
            v.visit_postfix_expression(inner)
        }
        PostfixExpression::CompoundLiteral(cl) => v.visit_compound_literal(cl),
    }
}

/// Walk a compound literal.
pub fn walk_compound_literal<'a, V: Visitor<'a> + ?Sized>(v: &mut V, cl: &'a CompoundLiteral) -> V::Result {
    for specifier in &cl.storage_class_specifiers {
        tr!(v.visit_storage_class_specifier(specifier));
    }
    tr!(v.visit_type_name(&cl.type_name));
    v.visit_braced_initializer(&cl.initializer)
}

/// Walk a primary expression.
fn walk_primary_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, pr: &'a PrimaryExpression) -> V::Result {
    match pr {
        PrimaryExpression::Identifier(id) => v.visit_variable_name(id),
        PrimaryExpression::EnumerationConstant(id) => v.visit_enum_constant(id),
        PrimaryExpression::Parenthesized(e) => v.visit_expression(e),
        PrimaryExpression::Generic(g) => v.visit_generic_selection(g),
        _ => V::Result::output(),
    }
}

/// Walk a generic selection.
fn walk_generic_selection<'a, V: Visitor<'a> + ?Sized>(v: &mut V, g: &'a GenericSelection) -> V::Result {
    tr!(v.visit_expression(&g.controlling_expression));
    for assoc in &g.associations {
        match assoc {
            GenericAssociation::Type { type_name, expression } => {
                tr!(v.visit_type_name(type_name));
                tr!(v.visit_expression(expression))
            }
            GenericAssociation::Default { expression } => tr!(v.visit_expression(expression)),
        };
    }
    V::Result::output()
}

/// Walk a unary expression.
pub fn walk_unary_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, u: &'a UnaryExpression) -> V::Result {
    match u {
        UnaryExpression::Postfix(p) => v.visit_postfix_expression(p),
        UnaryExpression::PreIncrement(inner) | UnaryExpression::PreDecrement(inner) => v.visit_unary_expression(inner),
        UnaryExpression::Unary { operator, operand } => {
            tr!(v.visit_unary_operator(operator));
            v.visit_cast_expression(operand)
        }
        UnaryExpression::Sizeof(inner) => v.visit_unary_expression(inner),
        UnaryExpression::SizeofType(tn) | UnaryExpression::Alignof(tn) => v.visit_type_name(tn),
    }
}

/// Walk a cast expression.
pub fn walk_cast_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, c: &'a CastExpression) -> V::Result {
    match c {
        CastExpression::Unary(u) => v.visit_unary_expression(u),
        CastExpression::Cast { type_name, expression } => {
            tr!(v.visit_type_name(type_name));
            v.visit_cast_expression(expression)
        }
    }
}

/// Walk a declaration.
pub fn walk_declaration<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a Declaration) -> V::Result {
    match &d.kind {
        DeclarationKind::Normal { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            tr!(v.visit_declaration_specifiers(specifiers));
            for init in declarators {
                tr!(v.visit_init_declarator(init));
            }
            V::Result::output()
        }
        DeclarationKind::Typedef { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            tr!(v.visit_declaration_specifiers(specifiers));
            for d in declarators {
                tr!(v.visit_declarator(d));
            }
            V::Result::output()
        }
        DeclarationKind::StaticAssert(sa) => v.visit_static_assert_declaration(sa),
        DeclarationKind::Attribute(attrs) => {
            for attr in attrs {
                tr!(v.visit_attribute_specifier(attr));
            }
            V::Result::output()
        }
        DeclarationKind::Error => V::Result::output(),
    }
}

/// Walk an init declarator.
pub fn walk_init_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, id: &'a InitDeclarator) -> V::Result {
    tr!(v.visit_declarator(&id.declarator));
    if let Some(init) = &id.initializer {
        tr!(v.visit_initializer(init));
    }
    V::Result::output()
}

/// Walk a static assert declaration.
pub fn walk_static_assert_declaration<'a, V: Visitor<'a> + ?Sized>(
    v: &mut V,
    sa: &'a StaticAssertDeclaration,
) -> V::Result {
    tr!(v.visit_constant_expression(&sa.condition));
    if let Some(msg) = &sa.message {
        tr!(v.visit_static_assert_message(msg));
    }
    V::Result::output()
}

/// Walk declaration specifiers.
pub fn walk_declaration_specifiers<'a, V: Visitor<'a> + ?Sized>(v: &mut V, s: &'a DeclarationSpecifiers) -> V::Result {
    for it in &s.specifiers {
        tr!(v.visit_declaration_specifier(it));
    }
    for attr in &s.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    V::Result::output()
}

/// Walk a declaration specifier.
pub fn walk_declaration_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, ds: &'a DeclarationSpecifier) -> V::Result {
    match ds {
        DeclarationSpecifier::StorageClass(scs) => v.visit_storage_class_specifier(scs),
        DeclarationSpecifier::TypeSpecifierQualifier(tsq) => v.visit_type_specifier_qualifier(tsq),
        DeclarationSpecifier::Function(fs) => v.visit_function_specifier(fs),
    }
}

/// Walk a type specifier or qualifier.
pub fn walk_type_specifier_qualifier<'a, V: Visitor<'a> + ?Sized>(
    v: &mut V,
    x: &'a TypeSpecifierQualifier,
) -> V::Result {
    match x {
        TypeSpecifierQualifier::TypeSpecifier(ts) => v.visit_type_specifier(ts),
        TypeSpecifierQualifier::TypeQualifier(tq) => v.visit_type_qualifier(tq),
        TypeSpecifierQualifier::AlignmentSpecifier(a) => v.visit_alignment_specifier(a),
    }
}

/// Walk an alignment specifier.
pub fn walk_alignment_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, a: &'a AlignmentSpecifier) -> V::Result {
    match a {
        AlignmentSpecifier::Type(tn) => v.visit_type_name(tn),
        AlignmentSpecifier::Expression(e) => v.visit_constant_expression(e),
    }
}

/// Walk a type specifier.
pub fn walk_type_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, ts: &'a TypeSpecifier) -> V::Result {
    match ts {
        TypeSpecifier::Struct(s) => v.visit_struct_union_specifier(s),
        TypeSpecifier::Enum(e) => v.visit_enum_specifier(e),
        TypeSpecifier::TypedefName(id) => v.visit_type_name_identifier(id),
        TypeSpecifier::Atomic(a) => v.visit_atomic_type_specifier(a),
        TypeSpecifier::Typeof(t) => v.visit_typeof(t),
        TypeSpecifier::BitInt(c) => v.visit_constant_expression(c),
        TypeSpecifier::Void
        | TypeSpecifier::Char
        | TypeSpecifier::Short
        | TypeSpecifier::Int
        | TypeSpecifier::Long
        | TypeSpecifier::Float
        | TypeSpecifier::Double
        | TypeSpecifier::Signed
        | TypeSpecifier::Unsigned
        | TypeSpecifier::Bool
        | TypeSpecifier::Complex
        | TypeSpecifier::Decimal32
        | TypeSpecifier::Decimal64
        | TypeSpecifier::Decimal128 => V::Result::output(),
    }
}

/// Walk a struct or union specifier.
pub fn walk_struct_union_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, s: &'a StructOrUnionSpecifier) -> V::Result {
    tr!(v.visit_struct_or_union(&s.kind));
    for attr in &s.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    if let Some(id) = &s.identifier {
        tr!(v.visit_struct_name(id));
    }
    if let Some(members) = &s.members {
        for m in members {
            tr!(v.visit_member_declaration(m));
        }
    }
    V::Result::output()
}

/// Walk a member declaration.
pub fn walk_member_declaration<'a, V: Visitor<'a> + ?Sized>(v: &mut V, md: &'a MemberDeclaration) -> V::Result {
    match md {
        MemberDeclaration::Normal { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            tr!(v.visit_specifier_qualifier_list(specifiers));
            for d in declarators {
                tr!(v.visit_member_declarator(d));
            }
            V::Result::output()
        }
        MemberDeclaration::StaticAssert(sa) => v.visit_static_assert_declaration(sa),
        MemberDeclaration::Error => V::Result::output(),
    }
}

/// Walk a member declarator.
pub fn walk_member_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, md: &'a MemberDeclarator) -> V::Result {
    match md {
        MemberDeclarator::Declarator(d) => v.visit_declarator(d),
        MemberDeclarator::BitField { declarator, width } => {
            if let Some(d) = declarator {
                tr!(v.visit_declarator(d));
            }
            v.visit_constant_expression(width)
        }
    }
}

/// Walk an enum specifier.
pub fn walk_enum_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, e: &'a EnumSpecifier) -> V::Result {
    for attr in &e.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    if let Some(id) = &e.identifier {
        tr!(v.visit_enum_name(id));
    }
    if let Some(sql) = &e.type_specifier {
        tr!(v.visit_specifier_qualifier_list(sql));
    }
    if let Some(enumerators) = &e.enumerators {
        for en in enumerators {
            tr!(v.visit_enumerator(en));
        }
    }
    V::Result::output()
}

/// Walk an enumerator.
pub fn walk_enumerator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, e: &'a Enumerator) -> V::Result {
    tr!(v.visit_enumerator_name(&e.name));
    for attr in &e.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    if let Some(value) = &e.value {
        tr!(v.visit_constant_expression(value));
    }
    V::Result::output()
}

/// Walk an atomic type specifier.
pub fn walk_atomic_type_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, a: &'a AtomicTypeSpecifier) -> V::Result {
    v.visit_type_name(&a.type_name)
}

/// Walk a typeof specifier.
pub fn walk_typeof<'a, V: Visitor<'a> + ?Sized>(v: &mut V, t: &'a TypeofSpecifier) -> V::Result {
    match t {
        TypeofSpecifier::Typeof(arg) | TypeofSpecifier::TypeofUnqual(arg) => match arg {
            TypeofSpecifierArgument::Expression(e) => v.visit_expression(e),
            TypeofSpecifierArgument::TypeName(tn) => v.visit_type_name(tn),
            TypeofSpecifierArgument::Error => V::Result::output(),
        },
    }
}

/// Walk a specifier qualifier list.
pub fn walk_specifier_qualifier_list<'a, V: Visitor<'a> + ?Sized>(
    v: &mut V,
    s: &'a SpecifierQualifierList,
) -> V::Result {
    for item in &s.items {
        tr!(v.visit_type_specifier_qualifier(item));
    }
    for attr in &s.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    V::Result::output()
}

/// Walk a declarator.
pub fn walk_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a Declarator) -> V::Result {
    match d {
        Declarator::Direct(dd) => v.visit_direct_declarator(dd),
        Declarator::Pointer { pointer, declarator } => {
            tr!(v.visit_pointer(pointer));
            v.visit_declarator(declarator)
        }
        Declarator::Error => V::Result::output(),
    }
}

/// Walk a pointer.
pub fn walk_pointer<'a, V: Visitor<'a> + ?Sized>(v: &mut V, p: &'a Pointer) -> V::Result {
    tr!(v.visit_pointer_or_block(&p.pointer_or_block));
    for attr in &p.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    for tq in &p.type_qualifiers {
        tr!(v.visit_type_qualifier(tq));
    }
    V::Result::output()
}

/// Walk a direct declarator.
pub fn walk_direct_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a DirectDeclarator) -> V::Result {
    match d {
        DirectDeclarator::Identifier { identifier, attributes } => {
            tr!(v.visit_variable_name(identifier));
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            V::Result::output()
        }
        DirectDeclarator::Parenthesized(inner) => v.visit_declarator(inner),
        DirectDeclarator::Array { declarator, attributes, array_declarator } => {
            tr!(v.visit_direct_declarator(declarator));
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            v.visit_array_declarator(array_declarator)
        }
        DirectDeclarator::Function { declarator, attributes, parameters } => {
            tr!(v.visit_direct_declarator(declarator));
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            v.visit_parameter_type_list(parameters)
        }
    }
}

/// Walk an array declarator.
pub fn walk_array_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a ArrayDeclarator) -> V::Result {
    match d {
        ArrayDeclarator::Normal { type_qualifiers, size } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier(tq));
            }
            if let Some(expr) = size {
                tr!(v.visit_expression(expr));
            }
            V::Result::output()
        }
        ArrayDeclarator::Static { type_qualifiers, size } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier(tq));
            }
            v.visit_expression(size)
        }
        ArrayDeclarator::VLA { type_qualifiers } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier(tq));
            }
            V::Result::output()
        }
        ArrayDeclarator::Error => V::Result::output(),
    }
}

/// Walk a parameter type list.
pub fn walk_parameter_type_list<'a, V: Visitor<'a> + ?Sized>(v: &mut V, ptl: &'a ParameterTypeList) -> V::Result {
    match ptl {
        ParameterTypeList::Parameters(params) | ParameterTypeList::Variadic(params) => {
            for p in params {
                tr!(v.visit_parameter_declaration(p));
            }
            V::Result::output()
        }
        ParameterTypeList::OnlyVariadic => V::Result::output(),
    }
}

/// Walk a parameter declaration.
pub fn walk_parameter_declaration<'a, V: Visitor<'a> + ?Sized>(v: &mut V, pd: &'a ParameterDeclaration) -> V::Result {
    for attr in &pd.attributes {
        tr!(v.visit_attribute_specifier(attr));
    }
    tr!(v.visit_declaration_specifiers(&pd.specifiers));
    if let Some(kind) = &pd.declarator {
        tr!(v.visit_parameter_declaration_kind(kind));
    }
    V::Result::output()
}

/// Walk a parameter declaration kind.
pub fn walk_parameter_declaration_kind<'a, V: Visitor<'a> + ?Sized>(
    v: &mut V,
    pdk: &'a ParameterDeclarationKind,
) -> V::Result {
    match pdk {
        ParameterDeclarationKind::Declarator(d) => v.visit_declarator(d),
        ParameterDeclarationKind::Abstract(a) => v.visit_abstract_declarator(a),
    }
}

/// Walk an initializer.
pub fn walk_initializer<'a, V: Visitor<'a> + ?Sized>(v: &mut V, i: &'a Initializer) -> V::Result {
    match i {
        Initializer::Expression(e) => v.visit_expression(e),
        Initializer::Braced(b) => v.visit_braced_initializer(b),
    }
}

/// Walk a braced initializer.
fn walk_braced_initializer<'a, V: Visitor<'a> + ?Sized>(v: &mut V, b: &'a BracedInitializer) -> V::Result {
    for init in &b.initializers {
        tr!(v.visit_designated_initializer(init));
    }
    V::Result::output()
}

/// Walk a designated initializer.
pub fn walk_designated_initializer<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a DesignatedInitializer) -> V::Result {
    if let Some(designation) = &d.designation {
        tr!(v.visit_designation(designation));
    }
    v.visit_initializer(&d.initializer)
}

/// Walk a designation.
pub fn walk_designation<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a Designation) -> V::Result {
    tr!(v.visit_designator(&d.designator));
    if let Some(designation) = &d.designation {
        tr!(v.visit_designation(designation));
    }
    V::Result::output()
}

/// Walk a designator.
pub fn walk_designator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, d: &'a Designator) -> V::Result {
    match d {
        Designator::Array(expr) => v.visit_constant_expression(expr),
        Designator::Member(identifier) => v.visit_member_name(identifier),
    }
}

/// Walk a constant expression.
pub fn walk_constant_expression<'a, V: Visitor<'a> + ?Sized>(v: &mut V, e: &'a ConstantExpression) -> V::Result {
    match e {
        ConstantExpression::Expression(expr) => v.visit_expression(expr),
        ConstantExpression::Error => V::Result::output(),
    }
}

/// Walk a type name (used in casts, sizeof, alignof, etc.).
pub fn walk_type_name<'a, V: Visitor<'a> + ?Sized>(v: &mut V, tn: &'a TypeName) -> V::Result {
    match tn {
        TypeName::TypeName { specifiers, abstract_declarator } => {
            tr!(v.visit_specifier_qualifier_list(specifiers));
            if let Some(ad) = abstract_declarator {
                tr!(v.visit_abstract_declarator(ad));
            }
            V::Result::output()
        }
        TypeName::Error => V::Result::output(),
    }
}

/// Walk an abstract declarator.
pub fn walk_abstract_declarator<'a, V: Visitor<'a> + ?Sized>(v: &mut V, a: &'a AbstractDeclarator) -> V::Result {
    match a {
        AbstractDeclarator::Direct(d) => v.visit_direct_abstract_declarator(d),
        AbstractDeclarator::Pointer { pointer, abstract_declarator } => {
            tr!(v.visit_pointer(pointer));
            if let Some(ad) = abstract_declarator {
                tr!(v.visit_abstract_declarator(ad));
            }
            V::Result::output()
        }
        AbstractDeclarator::Error => V::Result::output(),
    }
}

/// Walk a direct abstract declarator.
pub fn walk_direct_abstract_declarator<'a, V: Visitor<'a> + ?Sized>(
    v: &mut V,
    d: &'a DirectAbstractDeclarator,
) -> V::Result {
    match d {
        DirectAbstractDeclarator::Parenthesized(ad) => v.visit_abstract_declarator(ad),
        DirectAbstractDeclarator::Array { declarator, attributes, array_declarator } => {
            if let Some(dd) = declarator {
                tr!(v.visit_direct_abstract_declarator(dd));
            }
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            v.visit_array_declarator(array_declarator)
        }
        DirectAbstractDeclarator::Function { declarator, attributes, parameters } => {
            if let Some(dd) = declarator {
                tr!(v.visit_direct_abstract_declarator(dd))
            }
            for attr in attributes {
                tr!(v.visit_attribute_specifier(attr));
            }
            v.visit_parameter_type_list(parameters)
        }
    }
}

/// Walk an attribute specifier.
pub fn walk_attribute_specifier<'a, V: Visitor<'a> + ?Sized>(v: &mut V, a: &'a AttributeSpecifier) -> V::Result {
    match a {
        AttributeSpecifier::Attributes(attributes) => {
            for attr in attributes {
                tr!(v.visit_attribute(attr));
            }
        }
        AttributeSpecifier::Asm(string_literals) => {
            tr!(v.visit_asm_attribute_specifier(string_literals));
        }
        AttributeSpecifier::Error => {}
    }
    V::Result::output()
}

// ============================================================================
// Mutable Visitor Trait
// ============================================================================

/// The mutable visitor trait for traversing and modifying C AST nodes.
///
/// This trait is similar to [`Visitor`] but provides mutable access to AST
/// nodes, allowing modifications during traversal.
///
/// # Example
///
/// ```ignore
/// struct RenameVisitor {
///     old_name: String,
///     new_name: String,
/// }
///
/// impl<'a> VisitorMut<'a> for RenameVisitor {
///     type Result = ();
///
///     fn visit_variable_name_mut(&mut self, id: &'a mut Identifier) {
///         if id.name == self.old_name {
///             id.name = self.new_name.clone();
///         }
///         Self::Result::output()
///     }
/// }
/// ```
pub trait VisitorMut<'a> {
    /// The result type produced by visitor operations.
    type Result: VisitorResult;

    /// Visits a variable name identifier with mutable access.
    fn visit_variable_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a typedef name identifier with mutable access.
    fn visit_type_name_identifier_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enumeration constant identifier with mutable access.
    fn visit_enum_constant_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a label name identifier with mutable access.
    fn visit_label_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a struct or union member name identifier with mutable access.
    fn visit_member_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a struct type identifier with mutable access.
    fn visit_struct_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enum type identifier with mutable access.
    fn visit_enum_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an enumerator name identifier with mutable access.
    fn visit_enumerator_name_mut(&mut self, _: &'a mut Identifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a translation unit with mutable access.
    fn visit_translation_unit_mut(&mut self, tu: &'a mut TranslationUnit) -> Self::Result {
        walk_translation_unit_mut(self, tu)
    }

    /// Visits an external declaration with mutable access.
    fn visit_external_declaration_mut(&mut self, d: &'a mut ExternalDeclaration) -> Self::Result {
        walk_external_declaration_mut(self, d)
    }

    /// Visits a function definition with mutable access.
    fn visit_function_definition_mut(&mut self, f: &'a mut FunctionDefinition) -> Self::Result {
        walk_function_definition_mut(self, f)
    }

    /// Visits an attribute specifier with mutable access.
    fn visit_attribute_specifier_mut(&mut self, a: &'a mut AttributeSpecifier) -> Self::Result {
        walk_attribute_specifier_mut(self, a)
    }

    /// Visits an attribute with mutable access.
    fn visit_attribute_mut(&mut self, _: &'a mut Attribute) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an asm attribute specifier with mutable access.
    fn visit_asm_attribute_specifier_mut(&mut self, _: &'a mut StringLiterals) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a statement with mutable access.
    fn visit_statement_mut(&mut self, s: &'a mut Statement) -> Self::Result {
        walk_statement_mut(self, s)
    }

    /// Visits an unlabeled statement with mutable access.
    fn visit_unlabeled_statement_mut(&mut self, s: &'a mut UnlabeledStatement) -> Self::Result {
        walk_unlabeled_statement_mut(self, s)
    }

    /// Visits an expression with mutable access.
    fn visit_expression_mut(&mut self, e: &'a mut Expression) -> Self::Result {
        walk_expression_mut(self, e)
    }

    /// Visits a declaration with mutable access.
    fn visit_declaration_mut(&mut self, d: &'a mut Declaration) -> Self::Result {
        walk_declaration_mut(self, d)
    }

    /// Visits a declarator with mutable access.
    fn visit_declarator_mut(&mut self, d: &'a mut Declarator) -> Self::Result {
        walk_declarator_mut(self, d)
    }

    /// Visits a direct declarator with mutable access.
    fn visit_direct_declarator_mut(&mut self, d: &'a mut DirectDeclarator) -> Self::Result {
        walk_direct_declarator_mut(self, d)
    }

    /// Visits an initializer with mutable access.
    fn visit_initializer_mut(&mut self, i: &'a mut Initializer) -> Self::Result {
        walk_initializer_mut(self, i)
    }

    /// Visits a braced initializer with mutable access.
    fn visit_braced_initializer_mut(&mut self, b: &'a mut BracedInitializer) -> Self::Result {
        walk_braced_initializer_mut(self, b)
    }

    /// Visits a designated initializer with mutable access.
    fn visit_designated_initializer_mut(&mut self, d: &'a mut DesignatedInitializer) -> Self::Result {
        walk_designated_initializer_mut(self, d)
    }

    /// Visits a designation with mutable access.
    fn visit_designation_mut(&mut self, d: &'a mut Designation) -> Self::Result {
        walk_designation_mut(self, d)
    }

    /// Visits a designator with mutable access.
    fn visit_designator_mut(&mut self, d: &'a mut Designator) -> Self::Result {
        walk_designator_mut(self, d)
    }

    /// Visits a constant expression with mutable access.
    fn visit_constant_expression_mut(&mut self, c: &'a mut ConstantExpression) -> Self::Result {
        walk_constant_expression_mut(self, c)
    }

    /// Visits a postfix expression with mutable access.
    fn visit_postfix_expression_mut(&mut self, p: &'a mut PostfixExpression) -> Self::Result {
        walk_postfix_expression_mut(self, p)
    }

    /// Visits a primary expression with mutable access.
    fn visit_primary_expression_mut(&mut self, p: &'a mut PrimaryExpression) -> Self::Result {
        walk_primary_expression_mut(self, p)
    }

    /// Visits a generic selection with mutable access.
    fn visit_generic_selection_mut(&mut self, g: &'a mut GenericSelection) -> Self::Result {
        walk_generic_selection_mut(self, g)
    }

    /// Visits a unary expression with mutable access.
    fn visit_unary_expression_mut(&mut self, u: &'a mut UnaryExpression) -> Self::Result {
        walk_unary_expression_mut(self, u)
    }

    /// Visits a cast expression with mutable access.
    fn visit_cast_expression_mut(&mut self, c: &'a mut CastExpression) -> Self::Result {
        walk_cast_expression_mut(self, c)
    }

    /// Visits a compound statement with mutable access.
    fn visit_compound_statement_mut(&mut self, c: &'a mut CompoundStatement) -> Self::Result {
        walk_compound_statement_mut(self, c)
    }

    /// Visits a block item with mutable access.
    fn visit_block_item_mut(&mut self, b: &'a mut BlockItem) -> Self::Result {
        walk_block_item_mut(self, b)
    }

    /// Visits declaration specifiers with mutable access.
    fn visit_declaration_specifiers_mut(&mut self, s: &'a mut DeclarationSpecifiers) -> Self::Result {
        walk_declaration_specifiers_mut(self, s)
    }

    /// Visits a type specifier or qualifier with mutable access.
    fn visit_type_specifier_qualifier_mut(&mut self, x: &'a mut TypeSpecifierQualifier) -> Self::Result {
        walk_type_specifier_qualifier_mut(self, x)
    }

    /// Visits a type specifier with mutable access.
    fn visit_type_specifier_mut(&mut self, ts: &'a mut TypeSpecifier) -> Self::Result {
        walk_type_specifier_mut(self, ts)
    }

    /// Visits an atomic type specifier with mutable access.
    fn visit_atomic_type_specifier_mut(&mut self, a: &'a mut AtomicTypeSpecifier) -> Self::Result {
        walk_atomic_type_specifier_mut(self, a)
    }

    /// Visits a typeof specifier with mutable access.
    fn visit_typeof_mut(&mut self, t: &'a mut TypeofSpecifier) -> Self::Result {
        walk_typeof_mut(self, t)
    }

    /// Visits a specifier qualifier list with mutable access.
    fn visit_specifier_qualifier_list_mut(&mut self, s: &'a mut SpecifierQualifierList) -> Self::Result {
        walk_specifier_qualifier_list_mut(self, s)
    }

    /// Visits a type name with mutable access.
    fn visit_type_name_mut(&mut self, tn: &'a mut TypeName) -> Self::Result {
        walk_type_name_mut(self, tn)
    }

    /// Visits an abstract declarator with mutable access.
    fn visit_abstract_declarator_mut(&mut self, a: &'a mut AbstractDeclarator) -> Self::Result {
        walk_abstract_declarator_mut(self, a)
    }

    /// Visits a direct abstract declarator with mutable access.
    fn visit_direct_abstract_declarator_mut(&mut self, d: &'a mut DirectAbstractDeclarator) -> Self::Result {
        walk_direct_abstract_declarator_mut(self, d)
    }

    /// Visits a labeled statement with mutable access.
    fn visit_labeled_statement_mut(&mut self, ls: &'a mut LabeledStatement) -> Self::Result {
        walk_labeled_statement_mut(self, ls)
    }

    /// Visits a label with mutable access.
    fn visit_label_mut(&mut self, l: &'a mut Label) -> Self::Result {
        walk_label_mut(self, l)
    }

    /// Visits an expression statement with mutable access.
    fn visit_expression_statement_mut(&mut self, e: &'a mut ExpressionStatement) -> Self::Result {
        walk_expression_statement_mut(self, e)
    }

    /// Visits a primary block with mutable access.
    fn visit_primary_block_mut(&mut self, pb: &'a mut PrimaryBlock) -> Self::Result {
        walk_primary_block_mut(self, pb)
    }

    /// Visits a jump statement with mutable access.
    fn visit_jump_statement_mut(&mut self, j: &'a mut JumpStatement) -> Self::Result {
        walk_jump_statement_mut(self, j)
    }

    /// Visits a selection statement with mutable access.
    fn visit_selection_statement_mut(&mut self, s: &'a mut SelectionStatement) -> Self::Result {
        walk_selection_statement_mut(self, s)
    }

    /// Visits an iteration statement with mutable access.
    fn visit_iteration_statement_mut(&mut self, i: &'a mut IterationStatement) -> Self::Result {
        walk_iteration_statement_mut(self, i)
    }

    /// Visits a for init clause with mutable access.
    fn visit_for_init_mut(&mut self, fi: &'a mut ForInit) -> Self::Result {
        walk_for_init_mut(self, fi)
    }

    /// Visits a binary expression with mutable access.
    fn visit_binary_expression_mut(&mut self, b: &'a mut BinaryExpression) -> Self::Result {
        walk_binary_expression_mut(self, b)
    }

    /// Visits a conditional expression with mutable access.
    fn visit_conditional_expression_mut(&mut self, c: &'a mut ConditionalExpression) -> Self::Result {
        walk_conditional_expression_mut(self, c)
    }

    /// Visits an assignment expression with mutable access.
    fn visit_assignment_expression_mut(&mut self, a: &'a mut AssignmentExpression) -> Self::Result {
        walk_assignment_expression_mut(self, a)
    }

    /// Visits a comma expression with mutable access.
    fn visit_comma_expression_mut(&mut self, c: &'a mut CommaExpression) -> Self::Result {
        walk_comma_expression_mut(self, c)
    }

    /// Visits a binary operator with mutable access.
    fn visit_binary_operator_mut(&mut self, _: &'a mut BinaryOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an assignment operator with mutable access.
    fn visit_assignment_operator_mut(&mut self, _: &'a mut AssignmentOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a compound literal with mutable access.
    fn visit_compound_literal_mut(&mut self, cl: &'a mut CompoundLiteral) -> Self::Result {
        walk_compound_literal_mut(self, cl)
    }

    /// Visits a storage class specifier with mutable access.
    fn visit_storage_class_specifier_mut(&mut self, _: &'a mut StorageClassSpecifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a unary operator with mutable access.
    fn visit_unary_operator_mut(&mut self, _: &'a mut UnaryOperator) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an init declarator with mutable access.
    fn visit_init_declarator_mut(&mut self, id: &'a mut InitDeclarator) -> Self::Result {
        walk_init_declarator_mut(self, id)
    }

    /// Visits a static assert declaration with mutable access.
    fn visit_static_assert_declaration_mut(&mut self, sa: &'a mut StaticAssertDeclaration) -> Self::Result {
        walk_static_assert_declaration_mut(self, sa)
    }

    /// Visits a static assert message with mutable access.
    fn visit_static_assert_message_mut(&mut self, _: &'a mut StringLiterals) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a declaration specifier with mutable access.
    fn visit_declaration_specifier_mut(&mut self, ds: &'a mut DeclarationSpecifier) -> Self::Result {
        walk_declaration_specifier_mut(self, ds)
    }

    /// Visits a function specifier with mutable access.
    fn visit_function_specifier_mut(&mut self, _: &'a mut FunctionSpecifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a type qualifier with mutable access.
    fn visit_type_qualifier_mut(&mut self, _: &'a mut TypeQualifier) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an alignment specifier with mutable access.
    fn visit_alignment_specifier_mut(&mut self, a: &'a mut AlignmentSpecifier) -> Self::Result {
        walk_alignment_specifier_mut(self, a)
    }

    /// Visits a struct or union specifier with mutable access.
    fn visit_struct_union_specifier_mut(&mut self, s: &'a mut StructOrUnionSpecifier) -> Self::Result {
        walk_struct_union_specifier_mut(self, s)
    }

    /// Visits an enum specifier with mutable access.
    fn visit_enum_specifier_mut(&mut self, e: &'a mut EnumSpecifier) -> Self::Result {
        walk_enum_specifier_mut(self, e)
    }

    /// Visits a struct or union keyword with mutable access.
    fn visit_struct_or_union_mut(&mut self, _: &'a mut StructOrUnion) -> Self::Result {
        Self::Result::output()
    }

    /// Visits a member declaration with mutable access.
    fn visit_member_declaration_mut(&mut self, md: &'a mut MemberDeclaration) -> Self::Result {
        walk_member_declaration_mut(self, md)
    }

    /// Visits a member declarator with mutable access.
    fn visit_member_declarator_mut(&mut self, md: &'a mut MemberDeclarator) -> Self::Result {
        walk_member_declarator_mut(self, md)
    }

    /// Visits an enumerator with mutable access.
    fn visit_enumerator_mut(&mut self, e: &'a mut Enumerator) -> Self::Result {
        walk_enumerator_mut(self, e)
    }

    /// Visits a pointer with mutable access.
    fn visit_pointer_mut(&mut self, p: &'a mut Pointer) -> Self::Result {
        walk_pointer_mut(self, p)
    }

    /// Visits a pointer or block indicator with mutable access.
    fn visit_pointer_or_block_mut(&mut self, _: &'a mut PointerOrBlock) -> Self::Result {
        Self::Result::output()
    }

    /// Visits an array declarator with mutable access.
    fn visit_array_declarator_mut(&mut self, d: &'a mut ArrayDeclarator) -> Self::Result {
        walk_array_declarator_mut(self, d)
    }

    /// Visits a parameter type list with mutable access.
    fn visit_parameter_type_list_mut(&mut self, ptl: &'a mut ParameterTypeList) -> Self::Result {
        walk_parameter_type_list_mut(self, ptl)
    }

    /// Visits a parameter declaration with mutable access.
    fn visit_parameter_declaration_mut(&mut self, pd: &'a mut ParameterDeclaration) -> Self::Result {
        walk_parameter_declaration_mut(self, pd)
    }

    /// Visits a parameter declaration kind with mutable access.
    fn visit_parameter_declaration_kind_mut(&mut self, pdk: &'a mut ParameterDeclarationKind) -> Self::Result {
        walk_parameter_declaration_kind_mut(self, pdk)
    }
}

// ============================================================================
// Mutable Walker Functions
// ============================================================================

/// Walk a translation unit with mutable access.
pub fn walk_translation_unit_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, tu: &'a mut TranslationUnit) -> V::Result {
    for ed in &mut tu.external_declarations {
        tr!(v.visit_external_declaration_mut(ed));
    }
    V::Result::output()
}

/// Walk an external declaration with mutable access.
pub fn walk_external_declaration_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    d: &'a mut ExternalDeclaration,
) -> V::Result {
    match d {
        ExternalDeclaration::Function(f) => v.visit_function_definition_mut(f),
        ExternalDeclaration::Declaration(d) => v.visit_declaration_mut(d),
    }
}

/// Walk a function definition with mutable access.
pub fn walk_function_definition_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    f: &'a mut FunctionDefinition,
) -> V::Result {
    for attr in &mut f.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    tr!(v.visit_declaration_specifiers_mut(&mut f.specifiers));
    tr!(v.visit_declarator_mut(&mut f.declarator));
    v.visit_compound_statement_mut(&mut f.body)
}

/// Walk a statement with mutable access.
pub fn walk_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, s: &'a mut Statement) -> V::Result {
    match &mut s.kind {
        StatementKind::Labeled(ls) => v.visit_labeled_statement_mut(ls),
        StatementKind::Unlabeled(u) => v.visit_unlabeled_statement_mut(u),
    }
}

/// Walk a labeled statement with mutable access.
pub fn walk_labeled_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    ls: &'a mut LabeledStatement,
) -> V::Result {
    tr!(v.visit_label_mut(&mut ls.label));
    v.visit_statement_mut(&mut ls.statement)
}

/// Walk a label with mutable access.
pub fn walk_label_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, l: &'a mut Label) -> V::Result {
    match l {
        Label::Identifier { attributes, identifier } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier_mut(attribute));
            }
            v.visit_label_name_mut(identifier)
        }
        Label::Case { attributes, expression } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier_mut(attribute));
            }
            v.visit_constant_expression_mut(expression)
        }
        Label::Default { attributes } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier_mut(attribute));
            }
            V::Result::output()
        }
    }
}

/// Walk an unlabeled statement with mutable access.
pub fn walk_unlabeled_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    s: &'a mut UnlabeledStatement,
) -> V::Result {
    match s {
        UnlabeledStatement::Expression(es) => v.visit_expression_statement_mut(es),
        UnlabeledStatement::Primary { attributes, block } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier_mut(attribute));
            }
            v.visit_primary_block_mut(block)
        }
        UnlabeledStatement::Jump { attributes, statement } => {
            for attribute in attributes {
                tr!(v.visit_attribute_specifier_mut(attribute));
            }
            v.visit_jump_statement_mut(statement)
        }
    }
}

/// Walk an expression statement with mutable access.
pub fn walk_expression_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    e: &'a mut ExpressionStatement,
) -> V::Result {
    if let Some(expr) = &mut e.expression {
        tr!(v.visit_expression_mut(expr));
    }
    V::Result::output()
}

/// Walk a primary block with mutable access.
pub fn walk_primary_block_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, pb: &'a mut PrimaryBlock) -> V::Result {
    match pb {
        PrimaryBlock::Compound(c) => v.visit_compound_statement_mut(c),
        PrimaryBlock::Selection(sel) => v.visit_selection_statement_mut(sel),
        PrimaryBlock::Iteration(iter) => v.visit_iteration_statement_mut(iter),
    }
}

/// Walk a compound statement with mutable access.
pub fn walk_compound_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    c: &'a mut CompoundStatement,
) -> V::Result {
    for item in &mut c.items {
        tr!(v.visit_block_item_mut(item));
    }
    V::Result::output()
}

/// Walk a block item with mutable access.
pub fn walk_block_item_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, b: &'a mut BlockItem) -> V::Result {
    match b {
        BlockItem::Declaration(d) => v.visit_declaration_mut(d),
        BlockItem::Statement(u) => v.visit_unlabeled_statement_mut(u),
        BlockItem::Label(l) => v.visit_label_mut(l),
    }
}

/// Walk a selection statement with mutable access.
pub fn walk_selection_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    s: &'a mut SelectionStatement,
) -> V::Result {
    match s {
        SelectionStatement::If { condition, then_stmt, else_stmt } => {
            tr!(v.visit_expression_mut(condition));
            tr!(v.visit_statement_mut(then_stmt));
            if let Some(e) = else_stmt {
                tr!(v.visit_statement_mut(e));
            }
            V::Result::output()
        }
        SelectionStatement::Switch { expression, statement } => {
            tr!(v.visit_expression_mut(expression));
            v.visit_statement_mut(statement)
        }
    }
}

/// Walk an iteration statement with mutable access.
pub fn walk_iteration_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    i: &'a mut IterationStatement,
) -> V::Result {
    match i {
        IterationStatement::While { condition, body } => {
            tr!(v.visit_expression_mut(condition));
            v.visit_statement_mut(body)
        }
        IterationStatement::DoWhile { body, condition } => {
            tr!(v.visit_statement_mut(body));
            v.visit_expression_mut(condition)
        }
        IterationStatement::For { init, condition, update, body } => {
            if let Some(i) = init {
                v.visit_for_init_mut(i);
            }
            if let Some(c) = condition {
                tr!(v.visit_expression_mut(c));
            }
            if let Some(u) = update {
                tr!(v.visit_expression_mut(u));
            }
            v.visit_statement_mut(body)
        }
        IterationStatement::Error => V::Result::output(),
    }
}

/// Walk a for init with mutable access.
pub fn walk_for_init_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, fi: &'a mut ForInit) -> V::Result {
    match fi {
        ForInit::Expression(e) => v.visit_expression_mut(e),
        ForInit::Declaration(d) => v.visit_declaration_mut(d),
    }
}

/// Walk a jump statement with mutable access.
pub fn walk_jump_statement_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, j: &'a mut JumpStatement) -> V::Result {
    match j {
        JumpStatement::Goto(id) => v.visit_label_name_mut(id),
        JumpStatement::Continue | JumpStatement::Break => V::Result::output(),
        JumpStatement::Return(expr) => {
            if let Some(e) = expr {
                tr!(v.visit_expression_mut(e));
            }
            V::Result::output()
        }
    }
}

/// Walk an expression with mutable access.
pub fn walk_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, e: &'a mut Expression) -> V::Result {
    match &mut e.kind {
        ExpressionKind::Postfix(p) => v.visit_postfix_expression_mut(p),
        ExpressionKind::Unary(u) => v.visit_unary_expression_mut(u),
        ExpressionKind::Cast(c) => v.visit_cast_expression_mut(c),
        ExpressionKind::Binary(b) => v.visit_binary_expression_mut(b),
        ExpressionKind::Conditional(c) => v.visit_conditional_expression_mut(c),
        ExpressionKind::Assignment(a) => v.visit_assignment_expression_mut(a),
        ExpressionKind::Comma(c) => v.visit_comma_expression_mut(c),
        ExpressionKind::Error => V::Result::output(),
    }
}

/// Walk a binary expression with mutable access.
pub fn walk_binary_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, b: &'a mut BinaryExpression) -> V::Result {
    tr!(v.visit_expression_mut(&mut b.left));
    tr!(v.visit_binary_operator_mut(&mut b.operator));
    v.visit_expression_mut(&mut b.right)
}

/// Walk a conditional expression with mutable access.
pub fn walk_conditional_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    c: &'a mut ConditionalExpression,
) -> V::Result {
    tr!(v.visit_expression_mut(&mut c.condition));
    tr!(v.visit_expression_mut(&mut c.then_expr));
    v.visit_expression_mut(&mut c.else_expr)
}

/// Walk an assignment expression with mutable access.
pub fn walk_assignment_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    a: &'a mut AssignmentExpression,
) -> V::Result {
    tr!(v.visit_expression_mut(&mut a.left));
    tr!(v.visit_assignment_operator_mut(&mut a.operator));
    v.visit_expression_mut(&mut a.right)
}

/// Walk a comma expression with mutable access.
pub fn walk_comma_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, c: &'a mut CommaExpression) -> V::Result {
    for e in &mut c.expressions {
        tr!(v.visit_expression_mut(e));
    }
    V::Result::output()
}

/// Walk a postfix expression with mutable access.
pub fn walk_postfix_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    p: &'a mut PostfixExpression,
) -> V::Result {
    match p {
        PostfixExpression::Primary(pr) => v.visit_primary_expression_mut(pr),
        PostfixExpression::ArrayAccess { array, index } => {
            tr!(v.visit_postfix_expression_mut(array));
            v.visit_expression_mut(index)
        }
        PostfixExpression::FunctionCall { function, arguments } => {
            tr!(v.visit_postfix_expression_mut(function));
            for a in arguments {
                tr!(v.visit_expression_mut(a));
            }
            V::Result::output()
        }
        PostfixExpression::MemberAccess { object, member } => {
            tr!(v.visit_postfix_expression_mut(object));
            v.visit_member_name_mut(member)
        }
        PostfixExpression::MemberAccessPtr { object, member } => {
            tr!(v.visit_postfix_expression_mut(object));
            v.visit_member_name_mut(member)
        }
        PostfixExpression::PostIncrement(inner) | PostfixExpression::PostDecrement(inner) => {
            v.visit_postfix_expression_mut(inner)
        }
        PostfixExpression::CompoundLiteral(cl) => v.visit_compound_literal_mut(cl),
    }
}

/// Walk a compound literal with mutable access.
pub fn walk_compound_literal_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, cl: &'a mut CompoundLiteral) -> V::Result {
    for specifier in &mut cl.storage_class_specifiers {
        tr!(v.visit_storage_class_specifier_mut(specifier));
    }
    tr!(v.visit_type_name_mut(&mut cl.type_name));
    v.visit_braced_initializer_mut(&mut cl.initializer)
}

/// Walk a primary expression with mutable access.
pub fn walk_primary_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    pr: &'a mut PrimaryExpression,
) -> V::Result {
    match pr {
        PrimaryExpression::Identifier(id) => v.visit_variable_name_mut(id),
        PrimaryExpression::EnumerationConstant(id) => v.visit_enum_constant_mut(id),
        PrimaryExpression::Parenthesized(e) => v.visit_expression_mut(e),
        PrimaryExpression::Generic(g) => v.visit_generic_selection_mut(g),
        _ => V::Result::output(),
    }
}

/// Walk a generic selection with mutable access.
pub fn walk_generic_selection_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, g: &'a mut GenericSelection) -> V::Result {
    tr!(v.visit_expression_mut(&mut g.controlling_expression));
    for assoc in &mut g.associations {
        match assoc {
            GenericAssociation::Type { type_name, expression } => {
                tr!(v.visit_type_name_mut(type_name));
                tr!(v.visit_expression_mut(expression))
            }
            GenericAssociation::Default { expression } => tr!(v.visit_expression_mut(expression)),
        };
    }
    V::Result::output()
}

/// Walk a unary expression with mutable access.
pub fn walk_unary_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, u: &'a mut UnaryExpression) -> V::Result {
    match u {
        UnaryExpression::Postfix(p) => v.visit_postfix_expression_mut(p),
        UnaryExpression::PreIncrement(inner) | UnaryExpression::PreDecrement(inner) => {
            v.visit_unary_expression_mut(inner)
        }
        UnaryExpression::Unary { operator, operand } => {
            tr!(v.visit_unary_operator_mut(operator));
            v.visit_cast_expression_mut(operand)
        }
        UnaryExpression::Sizeof(inner) => v.visit_unary_expression_mut(inner),
        UnaryExpression::SizeofType(tn) | UnaryExpression::Alignof(tn) => v.visit_type_name_mut(tn),
    }
}

/// Walk a cast expression with mutable access.
pub fn walk_cast_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, c: &'a mut CastExpression) -> V::Result {
    match c {
        CastExpression::Unary(u) => v.visit_unary_expression_mut(u),
        CastExpression::Cast { type_name, expression } => {
            tr!(v.visit_type_name_mut(type_name));
            v.visit_cast_expression_mut(expression)
        }
    }
}

/// Walk a declaration with mutable access.
pub fn walk_declaration_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut Declaration) -> V::Result {
    match &mut d.kind {
        DeclarationKind::Normal { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            tr!(v.visit_declaration_specifiers_mut(specifiers));
            for init in declarators {
                tr!(v.visit_init_declarator_mut(init));
            }
            V::Result::output()
        }
        DeclarationKind::Typedef { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            tr!(v.visit_declaration_specifiers_mut(specifiers));
            for d in declarators {
                tr!(v.visit_declarator_mut(d));
            }
            V::Result::output()
        }
        DeclarationKind::StaticAssert(sa) => v.visit_static_assert_declaration_mut(sa),
        DeclarationKind::Attribute(attrs) => {
            for attr in attrs {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            V::Result::output()
        }
        DeclarationKind::Error => V::Result::output(),
    }
}

/// Walk an init declarator with mutable access.
pub fn walk_init_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, id: &'a mut InitDeclarator) -> V::Result {
    tr!(v.visit_declarator_mut(&mut id.declarator));
    if let Some(init) = &mut id.initializer {
        tr!(v.visit_initializer_mut(init));
    }
    V::Result::output()
}

/// Walk a static assert declaration with mutable access.
pub fn walk_static_assert_declaration_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    sa: &'a mut StaticAssertDeclaration,
) -> V::Result {
    tr!(v.visit_constant_expression_mut(&mut sa.condition));
    if let Some(msg) = &mut sa.message {
        tr!(v.visit_static_assert_message_mut(msg));
    }
    V::Result::output()
}

/// Walk declaration specifiers with mutable access.
pub fn walk_declaration_specifiers_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    s: &'a mut DeclarationSpecifiers,
) -> V::Result {
    for it in &mut s.specifiers {
        tr!(v.visit_declaration_specifier_mut(it));
    }
    for attr in &mut s.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    V::Result::output()
}

/// Walk a declaration specifier with mutable access.
pub fn walk_declaration_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    ds: &'a mut DeclarationSpecifier,
) -> V::Result {
    match ds {
        DeclarationSpecifier::StorageClass(scs) => v.visit_storage_class_specifier_mut(scs),
        DeclarationSpecifier::TypeSpecifierQualifier(tsq) => v.visit_type_specifier_qualifier_mut(tsq),
        DeclarationSpecifier::Function(fs) => v.visit_function_specifier_mut(fs),
    }
}

/// Walk a type specifier or qualifier with mutable access.
pub fn walk_type_specifier_qualifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    x: &'a mut TypeSpecifierQualifier,
) -> V::Result {
    match x {
        TypeSpecifierQualifier::TypeSpecifier(ts) => v.visit_type_specifier_mut(ts),
        TypeSpecifierQualifier::TypeQualifier(tq) => v.visit_type_qualifier_mut(tq),
        TypeSpecifierQualifier::AlignmentSpecifier(a) => v.visit_alignment_specifier_mut(a),
    }
}

/// Walk an alignment specifier with mutable access.
pub fn walk_alignment_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    a: &'a mut AlignmentSpecifier,
) -> V::Result {
    match a {
        AlignmentSpecifier::Type(tn) => v.visit_type_name_mut(tn),
        AlignmentSpecifier::Expression(e) => v.visit_constant_expression_mut(e),
    }
}

/// Walk a type specifier with mutable access.
pub fn walk_type_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, ts: &'a mut TypeSpecifier) -> V::Result {
    match ts {
        TypeSpecifier::Struct(s) => v.visit_struct_union_specifier_mut(s),
        TypeSpecifier::Enum(e) => v.visit_enum_specifier_mut(e),
        TypeSpecifier::TypedefName(id) => v.visit_type_name_identifier_mut(id),
        TypeSpecifier::Atomic(a) => v.visit_atomic_type_specifier_mut(a),
        TypeSpecifier::Typeof(t) => v.visit_typeof_mut(t),
        TypeSpecifier::BitInt(c) => v.visit_constant_expression_mut(c),
        TypeSpecifier::Void
        | TypeSpecifier::Char
        | TypeSpecifier::Short
        | TypeSpecifier::Int
        | TypeSpecifier::Long
        | TypeSpecifier::Float
        | TypeSpecifier::Double
        | TypeSpecifier::Signed
        | TypeSpecifier::Unsigned
        | TypeSpecifier::Bool
        | TypeSpecifier::Complex
        | TypeSpecifier::Decimal32
        | TypeSpecifier::Decimal64
        | TypeSpecifier::Decimal128 => V::Result::output(),
    }
}

/// Walk a struct or union specifier with mutable access.
pub fn walk_struct_union_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    s: &'a mut StructOrUnionSpecifier,
) -> V::Result {
    tr!(v.visit_struct_or_union_mut(&mut s.kind));
    for attr in &mut s.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    if let Some(id) = &mut s.identifier {
        tr!(v.visit_struct_name_mut(id));
    }
    if let Some(members) = &mut s.members {
        for m in members {
            tr!(v.visit_member_declaration_mut(m));
        }
    }
    V::Result::output()
}

/// Walk a member declaration with mutable access.
pub fn walk_member_declaration_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    md: &'a mut MemberDeclaration,
) -> V::Result {
    match md {
        MemberDeclaration::Normal { attributes, specifiers, declarators } => {
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            tr!(v.visit_specifier_qualifier_list_mut(specifiers));
            for d in declarators {
                tr!(v.visit_member_declarator_mut(d));
            }
            V::Result::output()
        }
        MemberDeclaration::StaticAssert(sa) => v.visit_static_assert_declaration_mut(sa),
        MemberDeclaration::Error => V::Result::output(),
    }
}

/// Walk a member declarator with mutable access.
pub fn walk_member_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    md: &'a mut MemberDeclarator,
) -> V::Result {
    match md {
        MemberDeclarator::Declarator(d) => v.visit_declarator_mut(d),
        MemberDeclarator::BitField { declarator, width } => {
            if let Some(d) = declarator {
                tr!(v.visit_declarator_mut(d));
            }
            v.visit_constant_expression_mut(width)
        }
    }
}

/// Walk an enum specifier with mutable access.
pub fn walk_enum_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, e: &'a mut EnumSpecifier) -> V::Result {
    for attr in &mut e.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    if let Some(id) = &mut e.identifier {
        tr!(v.visit_enum_name_mut(id));
    }
    if let Some(sql) = &mut e.type_specifier {
        tr!(v.visit_specifier_qualifier_list_mut(sql));
    }
    if let Some(enumerators) = &mut e.enumerators {
        for en in enumerators {
            tr!(v.visit_enumerator_mut(en));
        }
    }
    V::Result::output()
}

/// Walk an enumerator with mutable access.
pub fn walk_enumerator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, e: &'a mut Enumerator) -> V::Result {
    tr!(v.visit_enumerator_name_mut(&mut e.name));
    for attr in &mut e.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    if let Some(value) = &mut e.value {
        tr!(v.visit_constant_expression_mut(value));
    }
    V::Result::output()
}

/// Walk an atomic type specifier with mutable access.
pub fn walk_atomic_type_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    a: &'a mut AtomicTypeSpecifier,
) -> V::Result {
    v.visit_type_name_mut(&mut a.type_name)
}

/// Walk a typeof specifier with mutable access.
pub fn walk_typeof_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, t: &'a mut TypeofSpecifier) -> V::Result {
    match t {
        TypeofSpecifier::Typeof(arg) | TypeofSpecifier::TypeofUnqual(arg) => match arg {
            TypeofSpecifierArgument::Expression(e) => v.visit_expression_mut(e),
            TypeofSpecifierArgument::TypeName(tn) => v.visit_type_name_mut(tn),
            TypeofSpecifierArgument::Error => V::Result::output(),
        },
    }
}

/// Walk a specifier qualifier list with mutable access.
pub fn walk_specifier_qualifier_list_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    s: &'a mut SpecifierQualifierList,
) -> V::Result {
    for item in &mut s.items {
        tr!(v.visit_type_specifier_qualifier_mut(item));
    }
    for attr in &mut s.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    V::Result::output()
}

/// Walk a declarator with mutable access.
pub fn walk_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut Declarator) -> V::Result {
    match d {
        Declarator::Direct(dd) => v.visit_direct_declarator_mut(dd),
        Declarator::Pointer { pointer, declarator } => {
            tr!(v.visit_pointer_mut(pointer));
            v.visit_declarator_mut(declarator)
        }
        Declarator::Error => V::Result::output(),
    }
}

/// Walk a pointer with mutable access.
pub fn walk_pointer_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, p: &'a mut Pointer) -> V::Result {
    tr!(v.visit_pointer_or_block_mut(&mut p.pointer_or_block));
    for attr in &mut p.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    for tq in &mut p.type_qualifiers {
        tr!(v.visit_type_qualifier_mut(tq));
    }
    V::Result::output()
}

/// Walk a direct declarator with mutable access.
pub fn walk_direct_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut DirectDeclarator) -> V::Result {
    match d {
        DirectDeclarator::Identifier { identifier, attributes } => {
            tr!(v.visit_variable_name_mut(identifier));
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            V::Result::output()
        }
        DirectDeclarator::Parenthesized(inner) => v.visit_declarator_mut(inner),
        DirectDeclarator::Array { declarator, attributes, array_declarator } => {
            tr!(v.visit_direct_declarator_mut(declarator));
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            v.visit_array_declarator_mut(array_declarator)
        }
        DirectDeclarator::Function { declarator, attributes, parameters } => {
            tr!(v.visit_direct_declarator_mut(declarator));
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            v.visit_parameter_type_list_mut(parameters)
        }
    }
}

/// Walk an array declarator with mutable access.
pub fn walk_array_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut ArrayDeclarator) -> V::Result {
    match d {
        ArrayDeclarator::Normal { type_qualifiers, size } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier_mut(tq));
            }
            if let Some(expr) = size {
                tr!(v.visit_expression_mut(expr));
            }
            V::Result::output()
        }
        ArrayDeclarator::Static { type_qualifiers, size } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier_mut(tq));
            }
            v.visit_expression_mut(size)
        }
        ArrayDeclarator::VLA { type_qualifiers } => {
            for tq in type_qualifiers {
                tr!(v.visit_type_qualifier_mut(tq));
            }
            V::Result::output()
        }
        ArrayDeclarator::Error => V::Result::output(),
    }
}

/// Walk a parameter type list with mutable access.
pub fn walk_parameter_type_list_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    ptl: &'a mut ParameterTypeList,
) -> V::Result {
    match ptl {
        ParameterTypeList::Parameters(params) | ParameterTypeList::Variadic(params) => {
            for p in params {
                tr!(v.visit_parameter_declaration_mut(p));
            }
            V::Result::output()
        }
        ParameterTypeList::OnlyVariadic => V::Result::output(),
    }
}

/// Walk a parameter declaration with mutable access.
pub fn walk_parameter_declaration_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    pd: &'a mut ParameterDeclaration,
) -> V::Result {
    for attr in &mut pd.attributes {
        tr!(v.visit_attribute_specifier_mut(attr));
    }
    tr!(v.visit_declaration_specifiers_mut(&mut pd.specifiers));
    if let Some(kind) = &mut pd.declarator {
        tr!(v.visit_parameter_declaration_kind_mut(kind));
    }
    V::Result::output()
}

/// Walk a parameter declaration kind with mutable access.
pub fn walk_parameter_declaration_kind_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    pdk: &'a mut ParameterDeclarationKind,
) -> V::Result {
    match pdk {
        ParameterDeclarationKind::Declarator(d) => v.visit_declarator_mut(d),
        ParameterDeclarationKind::Abstract(a) => v.visit_abstract_declarator_mut(a),
    }
}

/// Walk an initializer with mutable access.
pub fn walk_initializer_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, i: &'a mut Initializer) -> V::Result {
    match i {
        Initializer::Expression(e) => v.visit_expression_mut(e),
        Initializer::Braced(b) => v.visit_braced_initializer_mut(b),
    }
}

/// Walk a braced initializer with mutable access.
pub fn walk_braced_initializer_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    b: &'a mut BracedInitializer,
) -> V::Result {
    for init in &mut b.initializers {
        tr!(v.visit_designated_initializer_mut(init));
    }
    V::Result::output()
}

/// Walk a designated initializer with mutable access.
pub fn walk_designated_initializer_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    d: &'a mut DesignatedInitializer,
) -> V::Result {
    if let Some(designation) = &mut d.designation {
        tr!(v.visit_designation_mut(designation));
    }
    v.visit_initializer_mut(&mut d.initializer)
}

/// Walk a designation with mutable access.
pub fn walk_designation_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut Designation) -> V::Result {
    tr!(v.visit_designator_mut(&mut d.designator));
    if let Some(designation) = &mut d.designation {
        tr!(v.visit_designation_mut(designation));
    }
    V::Result::output()
}

/// Walk a designator with mutable access.
pub fn walk_designator_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, d: &'a mut Designator) -> V::Result {
    match d {
        Designator::Array(expr) => v.visit_constant_expression_mut(expr),
        Designator::Member(identifier) => v.visit_member_name_mut(identifier),
    }
}

/// Walk a constant expression with mutable access.
pub fn walk_constant_expression_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    e: &'a mut ConstantExpression,
) -> V::Result {
    match e {
        ConstantExpression::Expression(expr) => v.visit_expression_mut(expr),
        ConstantExpression::Error => V::Result::output(),
    }
}

/// Walk a type name with mutable access.
pub fn walk_type_name_mut<'a, V: VisitorMut<'a> + ?Sized>(v: &mut V, tn: &'a mut TypeName) -> V::Result {
    match tn {
        TypeName::TypeName { specifiers, abstract_declarator } => {
            tr!(v.visit_specifier_qualifier_list_mut(specifiers));
            if let Some(ad) = abstract_declarator {
                tr!(v.visit_abstract_declarator_mut(ad));
            }
            V::Result::output()
        }
        TypeName::Error => V::Result::output(),
    }
}

/// Walk an abstract declarator with mutable access.
pub fn walk_abstract_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    a: &'a mut AbstractDeclarator,
) -> V::Result {
    match a {
        AbstractDeclarator::Direct(d) => v.visit_direct_abstract_declarator_mut(d),
        AbstractDeclarator::Pointer { pointer, abstract_declarator } => {
            tr!(v.visit_pointer_mut(pointer));
            if let Some(ad) = abstract_declarator {
                tr!(v.visit_abstract_declarator_mut(ad));
            }
            V::Result::output()
        }
        AbstractDeclarator::Error => V::Result::output(),
    }
}

/// Walk a direct abstract declarator with mutable access.
pub fn walk_direct_abstract_declarator_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    d: &'a mut DirectAbstractDeclarator,
) -> V::Result {
    match d {
        DirectAbstractDeclarator::Parenthesized(ad) => v.visit_abstract_declarator_mut(ad),
        DirectAbstractDeclarator::Array { declarator, attributes, array_declarator } => {
            if let Some(dd) = declarator {
                tr!(v.visit_direct_abstract_declarator_mut(dd));
            }
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            v.visit_array_declarator_mut(array_declarator)
        }
        DirectAbstractDeclarator::Function { declarator, attributes, parameters } => {
            if let Some(dd) = declarator {
                tr!(v.visit_direct_abstract_declarator_mut(dd))
            }
            for attr in attributes {
                tr!(v.visit_attribute_specifier_mut(attr));
            }
            v.visit_parameter_type_list_mut(parameters)
        }
    }
}

/// Walk an attribute specifier with mutable access.
pub fn walk_attribute_specifier_mut<'a, V: VisitorMut<'a> + ?Sized>(
    v: &mut V,
    a: &'a mut AttributeSpecifier,
) -> V::Result {
    match a {
        AttributeSpecifier::Attributes(attributes) => {
            for attr in attributes {
                tr!(v.visit_attribute_mut(attr));
            }
        }
        AttributeSpecifier::Asm(string_literals) => {
            tr!(v.visit_asm_attribute_specifier_mut(string_literals));
        }
        AttributeSpecifier::Error => {}
    }
    V::Result::output()
}