File: cpproduce.cxx

package info (click to toggle)
libreoffice 4%3A26.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,833,120 kB
  • sloc: cpp: 4,395,780; xml: 499,109; java: 254,438; python: 81,820; ansic: 33,823; perl: 30,297; javascript: 19,722; sh: 12,050; makefile: 10,854; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,385; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (2705 lines) | stat: -rw-r--r-- 90,992 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "cpproduce.hxx"
#include <rtl/string.hxx>
#include "rustfile.hxx"
#include "type_analyzer.hxx"
#include "cpp_include_manager.hxx"
#include <codemaker/typemanager.hxx>
#include <codemaker/unotype.hxx>
#include <sal/log.hxx>
#include <sal/types.h>
#include <iostream>
#include <filesystem>
#include <string_view>
#include <algorithm>

CppProducer::CppProducer(const OString& outputDir, bool verbose, bool dryRun,
                         const rtl::Reference<TypeManager>& typeManager)
    : m_outputDir(outputDir)
    , m_verbose(verbose)
    , m_dryRun(dryRun)
    , m_typeManager(typeManager)
    , m_combinedSourceFile()
    , m_combinedHeaderFile()
{
}

void CppProducer::initializeCombinedFile()
{
    if (m_dryRun)
        return;

    // Create the combined source file (.cxx)
    m_combinedSourceFile = std::make_unique<CppFile>(m_outputDir, "rust_uno_bindings", ".cxx");
    std::filesystem::path sourceFilePath = m_combinedSourceFile->getPath();
    if (std::filesystem::exists(sourceFilePath))
    {
        std::filesystem::remove(sourceFilePath);
    }
    m_combinedSourceFile->openFile();

    // Include the header file
    m_combinedSourceFile->beginLine().append("#include \"rust_uno_bindings.hxx\"").endLine();
    m_combinedSourceFile->beginLine().append("").endLine();

    // Create the combined header file (.hxx)
    m_combinedHeaderFile = std::make_unique<CppFile>(m_outputDir, "rust_uno_bindings", ".hxx");
    std::filesystem::path headerFilePath = m_combinedHeaderFile->getPath();
    if (std::filesystem::exists(headerFilePath))
    {
        std::filesystem::remove(headerFilePath);
    }
    m_combinedHeaderFile->openFile();

    // Add header guard
    m_combinedHeaderFile->beginLine().append("#pragma once").endLine();
    m_combinedHeaderFile->beginLine().append("").endLine();

    // Add only sal/types.h which definitely exists
    m_combinedHeaderFile->beginLine().append("#include <sal/types.h>").endLine();
    m_combinedHeaderFile->beginLine().append("").endLine();
}

void CppProducer::finalizeCombinedFile()
{
    if (m_combinedSourceFile)
    {
        m_combinedSourceFile->closeFile();
        m_combinedSourceFile.reset();
    }

    if (m_combinedHeaderFile)
    {
        m_combinedHeaderFile->closeFile();
        m_combinedHeaderFile.reset();
    }
}

void CppProducer::produceEnum(std::string_view name,
                              const rtl::Reference<unoidl::EnumTypeEntity>& entity)
{
    if (m_verbose)
        std::cout << "[cpp-opaque-enum] " << name << " -> enum bridge functions" << '\n';

    generateEnumBridge(name, entity);
}

void CppProducer::produceStruct(std::string_view name,
                                const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    if (m_verbose)
        std::cout << "[cpp-opaque-struct] " << name
                  << " -> constructor/destructor + getter/setter functions" << '\n';

    generateStructWrapper(name, entity);
    // generateStructBridge(name, entity);
}

void CppProducer::produceInterface(std::string_view name,
                                   const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    if (m_verbose)
        std::cout << "[cpp-opaque-interface] " << name
                  << " -> opaque handle + method wrapper functions" << '\n';

    generateInterfaceHeader(name, entity);
    generateInterfaceSource(name, entity);
}

void CppProducer::produceService(
    std::string_view name, const rtl::Reference<unoidl::SingleInterfaceBasedServiceEntity>& entity)
{
    if (m_verbose)
        std::cout << "[cpp-opaque-service] " << name << " -> service creation bridge functions"
                  << '\n';

    generateServiceHeader(name, entity);
    generateServiceSource(name, entity);
}

void CppProducer::generateEnumBridge(std::string_view name,
                                     const rtl::Reference<unoidl::EnumTypeEntity>& entity)
{
    generateEnumHeader(name, entity);
    generateEnumSource(name, entity);
}

void CppProducer::generateStructWrapper(std::string_view name,
                                        const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    generateStructHeader(name, entity);
    generateStructSource(name, entity);
}

void CppProducer::generateStructBridge(std::string_view name,
                                       const rtl::Reference<unoidl::PlainStructTypeEntity>&)
{
    CppFile file(m_outputDir, name);

    if (m_dryRun)
        return;

    file.openFile();

    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Simple opaque struct bridge functions (like old FFI approach)
    OString className = getInterfaceClassName(name);
    OString functionPrefix = getCFunctionPrefix(name);

    file.beginLine()
        .append("// Opaque struct creation")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void* ")
        .append(functionPrefix)
        .append("_create()")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("return new ")
        .append(className)
        .append("();")
        .endLine()
        .endBlock();

    file.beginLine().append("").endLine();
    file.endBlock().append(" // extern \"C\"");

    file.closeFile();
}

void CppProducer::generateCBridgeIncludes(CppFile& file, std::string_view name,
                                          const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    // Use existing infrastructure for includes
    TypeAnalyzer analyzer(m_typeManager);
    TypeAnalyzer::TypeInfo typeInfo = analyzer.analyzeInterface(entity);
    CppIncludeManager includeManager(typeInfo);

    includeManager.dumpIncludes(file, name);
}

void CppProducer::generateCBridgeTypeDefinitions(CppFile& file, std::string_view handleTypeName)
{
    // Opaque handle typedef for type safety
    file.beginLine()
        .append("// Opaque handle for type-safe C FFI")
        .endLine()
        .beginLine()
        .append("typedef void* ")
        .append(handleTypeName)
        .append(";")
        .endLine()
        .beginLine()
        .append("")
        .endLine();
}

void CppProducer::generateCBridgeConstructors(CppFile& file, std::string_view className,
                                              std::string_view functionPrefix,
                                              std::string_view handleTypeName)
{
    // Opaque constructor function - creates interface instance from existing Reference
    file.beginLine()
        .append("// Opaque constructor - creates interface wrapper from UNO Reference")
        .endLine()
        .beginLine()
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_create_from_reference(void* xInterface)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (!xInterface) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Cast void* back to Reference<")
        .append(className)
        .append(">")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append(className)
        .append(">* pRef = static_cast<Reference<")
        .append(className)
        .append(">*>(xInterface);")
        .endLine()
        .beginLine()
        .append("if (!pRef->is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Create wrapper with interface reference")
        .endLine()
        .beginLine()
        .append("return new ")
        .append(className)
        .append("Wrapper(*pRef);")
        .endLine()
        .endBlock()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Opaque service creation - attempts to create UNO service")
        .endLine()
        .beginLine()
        .append("// Note: This is a simplified approach - real service creation")
        .endLine()
        .beginLine()
        .append("// would need ComponentContext and service name resolution")
        .endLine()
        .beginLine()
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_create_service(void* xContext, const char* serviceName)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (!xContext || !serviceName) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("try")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("// Cast context")
        .endLine()
        .beginLine()
        .append("Reference<XComponentContext>* pContext =")
        .endLine()
        .extraIndent()
        .beginLine()
        .append("static_cast<Reference<XComponentContext>*>(xContext);")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Create service")
        .endLine()
        .beginLine()
        .append("OUString svcName = OUString::createFromAscii(serviceName);")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append(className)
        .append("> xService(")
        .endLine()
        .extraIndent()
        .beginLine()
        .append("pContext->getServiceManager()->createInstanceWithContext(")
        .endLine()
        .extraIndent()
        .beginLine()
        .append("svcName, *pContext), UNO_QUERY);")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("if (!xService.is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Return wrapper")
        .endLine()
        .beginLine()
        .append("return new ")
        .append(className)
        .append("Wrapper(xService);")
        .endLine()
        .endBlock()
        .beginLine()
        .append("catch (const Exception& ex)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("// TODO: Log exception details")
        .endLine()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"UNO exception in interface method\");")
        .endLine()
        .beginLine()
        .append("return nullptr;")
        .endLine()
        .endBlock()
        .endBlock();
}

void CppProducer::generateCBridgeDestructor(CppFile& file, std::string_view className,
                                            std::string_view functionPrefix,
                                            std::string_view handleTypeName)
{
    // Opaque destructor function - destroys interface instance
    file.beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Opaque destructor - destroys interface wrapper")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_destroy(")
        .append(handleTypeName)
        .append(" handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("delete static_cast<")
        .append(className)
        .append("Wrapper*>(handle);")
        .endLine()
        .endBlock();
}

void CppProducer::generateCBridgeValidation(CppFile& file, std::string_view className,
                                            std::string_view functionPrefix,
                                            std::string_view handleTypeName)
{
    // Opaque validity check function
    file.beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Opaque validity check - tests if interface is valid")
        .endLine()
        .beginLine()
        .append("bool ")
        .append(functionPrefix)
        .append("_is_valid(")
        .append(handleTypeName)
        .append(" handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (!handle) return false;")
        .endLine()
        .beginLine()
        .append("return static_cast<")
        .append(className)
        .append("Wrapper*>(handle)->isValid();")
        .endLine()
        .endBlock();
}

void CppProducer::generateCBridgeMethods(CppFile& file, std::string_view className,
                                         std::string_view functionPrefix,
                                         std::string_view handleTypeName,
                                         const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    // Opaque method bridge functions - each method gets unique extern "C" function
    for (const auto& method : entity->getDirectMethods())
    {
        file.beginLine()
            .append("")
            .endLine()
            .beginLine()
            .append("// Opaque method bridge for ")
            .append(method.name)
            .endLine()
            .beginLine()
            .append(getMethodReturnType(method.returnType))
            .append(" ")
            .append(functionPrefix)
            .append("_")
            .append(method.name)
            .append("(")
            .append(handleTypeName)
            .append(" handle");

        // Use proper types instead of void* for parameters
        for (const auto& param : method.parameters)
        {
            file.append(", ").append(getCppTypeName(param.type)).append(" ").append(param.name);
        }

        file.append(")")
            .endLine()
            .beginBlock()
            .beginLine()
            .append("if (!handle) return ")
            .append(getMethodDefaultReturn(method.returnType))
            .append(";")
            .endLine()
            .beginLine()
            .append("")
            .endLine()
            .beginLine()
            .append("auto* wrapper = static_cast<")
            .append(className)
            .append("Wrapper*>(handle);")
            .endLine()
            .beginLine()
            .append("return wrapper->")
            .append(method.name)
            .append("(");

        // Pass through all opaque parameters
        bool first = true;
        for (const auto& param : method.parameters)
        {
            if (!first)
                file.append(", ");
            first = false;
            file.append(param.name);
        }

        file.append(");").endLine().endBlock();
    }
}

void CppProducer::generateCBridge(std::string_view name,
                                  const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    CppFile file(m_outputDir, name);

    if (m_dryRun)
        return;

    file.openFile();

    // Generate file setup and includes
    generateCBridgeIncludes(file, name, entity);

    // Generate type definitions
    OString className = getInterfaceClassName(name);
    OString functionPrefix = getCFunctionPrefix(name);
    OString handleTypeName = functionPrefix + "Handle";

    generateCBridgeTypeDefinitions(file, handleTypeName);

    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Generate constructor functions
    generateCBridgeConstructors(file, className, functionPrefix, handleTypeName);

    // Generate destructor function
    generateCBridgeDestructor(file, className, functionPrefix, handleTypeName);

    // Generate validation function
    generateCBridgeValidation(file, className, functionPrefix, handleTypeName);

    // Generate method bridge functions
    generateCBridgeMethods(file, className, functionPrefix, handleTypeName, entity);

    file.beginLine().append("").endLine();
    file.endBlock().append(" // extern \"C\"");

    file.closeFile();
}

void CppProducer::generateStructHeader(std::string_view name,
                                       const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    if (m_dryRun || !m_combinedHeaderFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedHeaderFile;
    file.openFileAppend();

    // Generate includes following the pattern used in generateStructSource
    file.beginLine().append("#include <sal/types.h>").endLine();
    file.beginLine().append("#include <com/sun/star/uno/Reference.hxx>").endLine();
    file.beginLine().append("#include <com/sun/star/uno/Any.hxx>").endLine();
    // Include the struct definition
    std::string headerName(name);
    std::replace(headerName.begin(), headerName.end(), '.', '/');
    file.beginLine().append("#include <").append(headerName).append(".hpp>").endLine();
    file.beginLine().append("").endLine();
    file.beginLine().append("using namespace com::sun::star::uno;").endLine();

    file.beginLine().append("extern \"C\"").endLine().beginBlock();
    // Add struct-specific namespace
    std::string cppNamespace(name);
    size_t lastDot = cppNamespace.rfind('.');
    if (lastDot != std::string::npos)
    {
        cppNamespace = cppNamespace.substr(0, lastDot);
        // Convert dots to double colons for C++ namespace syntax
        size_t pos = 0;
        while ((pos = cppNamespace.find('.', pos)) != std::string::npos)
        {
            cppNamespace.replace(pos, 1, "::");
            pos += 2;
        }
    }

    // Simple opaque struct bridge functions
    OString functionPrefix = getCFunctionPrefix(name);
    OString handleTypeName = functionPrefix + "Handle";
    file.beginLine()
        .append("// Opaque handle for type-safe C FFI")
        .endLine()
        .beginLine()
        .append("typedef void* ")
        .append(handleTypeName)
        .append(";")
        .endLine()
        .beginLine()
        .append("")
        .endLine();

    file.beginLine()
        .append("// Opaque struct creation")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_constructor();")
        .endLine();

    file.beginLine()
        .append("// Opaque handle destruction")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_destroy(")
        .append(handleTypeName)
        .append(" handle);")
        .endLine();

    file.beginLine()
        .append("// Struct from_ptr type casting")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_ptr(void* ptr);")
        .endLine();

    file.beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("// Getters/setters for direct struct members")
        .endLine();

    // Opaque member access functions - each member gets getter/setter
    for (const auto& member : entity->getDirectMembers())
    {
        file.beginLine()
            .append("// Opaque getter for ")
            .append(member.name)
            .append(" (type: ")
            .append(member.type)
            .append(")")
            .endLine()
            .beginLine()
            .append("SAL_DLLPUBLIC_EXPORT ")
            .append(getStructGetterReturnType(member.type))
            .append(" ")
            .append(functionPrefix)
            .append("_get_")
            .append(member.name)
            .append("(")
            .append(handleTypeName)
            .append(" handle);")
            .endLine();

        file.beginLine()
            .append("// Opaque setter for ")
            .append(member.name)
            .append(" (type: ")
            .append(member.type)
            .append(")")
            .endLine()
            .beginLine()
            .append("SAL_DLLPUBLIC_EXPORT void ")
            .append(functionPrefix)
            .append("_set_")
            .append(member.name)
            .append("(")
            .append(handleTypeName)
            .append(" handle, ")
            .append(getStructSetterParameterType(member.type))
            .append(" value);")
            .endLine();
    }
    file.endBlock().append("// extern \"C\"").endLine();
    file.closeFile();
}

// Unified include generation function to eliminate duplication
void CppProducer::generateCommonIncludes(CppFile& file, std::string_view name, bool needsLogging,
                                         bool needsUnoTypes)
{
    // Always include sal/types.h
    file.beginLine().append("#include <sal/types.h>").endLine();

    // Include logging if needed
    if (needsLogging)
    {
        file.beginLine().append("#include <sal/log.hxx>").endLine();
    }

    // Include UNO types if needed
    if (needsUnoTypes)
    {
        file.beginLine().append("#include <com/sun/star/uno/Reference.hxx>").endLine();
        file.beginLine().append("#include <com/sun/star/uno/Any.hxx>").endLine();
    }

    // Include the type-specific header
    std::string headerName(name);
    std::replace(headerName.begin(), headerName.end(), '.', '/');
    file.beginLine().append("#include <").append(headerName).append(".hpp>").endLine();
    file.beginLine().append("").endLine();
}

void CppProducer::generateStructSourceIncludes(CppFile& file, std::string_view name)
{
    generateCommonIncludes(file, name, false, true);
}

void CppProducer::generateEnumIncludes(CppFile& file, std::string_view name)
{
    generateCommonIncludes(file, name, false, false);
}

void CppProducer::generateEnumSourceIncludes(CppFile& file, std::string_view name)
{
    generateCommonIncludes(file, name, true, false);
}

void CppProducer::generateEnumHeader(std::string_view name,
                                     const rtl::Reference<unoidl::EnumTypeEntity>&)
{
    if (m_dryRun || !m_combinedHeaderFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedHeaderFile;
    file.openFileAppend();

    // Add separator comment for this enum
    file.beginLine().append("").endLine();
    file.beginLine().append("// === ").append(name).append(" ===").endLine();

    // Generate includes in combined file
    generateEnumIncludes(file, name);

    // Generate extern "C" declarations
    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Opaque enum conversion functions - treat enums as opaque values
    OString enumName = convertUnoTypeToCpp(OUString::createFromAscii(std::string(name)));
    OString functionPrefix = getCFunctionPrefix(name); // Use consistent double-underscore naming
    file.beginLine()
        .append("    SAL_DLLPUBLIC_EXPORT ")
        .append(enumName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_i32(sal_Int32 value);")
        .endLine();

    file.beginLine()
        .append("    SAL_DLLPUBLIC_EXPORT sal_Int32 ")
        .append(functionPrefix)
        .append("_to_i32(")
        .append(enumName)
        .append(" value);")
        .endLine();

    file.beginLine().append("}").endLine();

    file.closeFile();
}

void CppProducer::generateEnumSource(std::string_view name,
                                     const rtl::Reference<unoidl::EnumTypeEntity>&)
{
    if (m_dryRun || !m_combinedSourceFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedSourceFile;
    file.openFileAppend();

    // Add separator comment for this enum
    file.beginLine().append("").endLine();
    file.beginLine().append("// === ").append(name).append(" ===").endLine();

    // Generate includes for source file
    generateEnumSourceIncludes(file, name);

    // Generate extern "C" implementations
    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Opaque enum conversion functions implementations
    OString enumName = convertUnoTypeToCpp(OUString::createFromAscii(std::string(name)));
    OString functionPrefix = getCFunctionPrefix(name); // Use consistent double-underscore naming

    // from_i32 implementation
    file.beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(enumName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_i32(sal_Int32 value)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("return static_cast<")
        .append(enumName)
        .append(">(value);")
        .endLine()
        .endBlock();

    // to_i32 implementation
    file.beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT sal_Int32 ")
        .append(functionPrefix)
        .append("_to_i32(")
        .append(enumName)
        .append(" value)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("return static_cast<sal_Int32>(value);")
        .endLine()
        .endBlock();

    file.beginLine().append("}").endLine();

    file.closeFile();
}

// Unified namespace generation function to eliminate duplication
void CppProducer::generateSourceNamespaces(CppFile& file, std::string_view name)
{
    file.beginLine().append("using namespace com::sun::star::uno;").endLine();

    // Add type-specific namespace
    std::string cppNamespace(name);
    size_t lastDot = cppNamespace.rfind('.');
    if (lastDot != std::string::npos)
    {
        cppNamespace = cppNamespace.substr(0, lastDot);
        // Convert dots to double colons for C++ namespace syntax
        size_t pos = 0;
        while ((pos = cppNamespace.find('.', pos)) != std::string::npos)
        {
            cppNamespace.replace(pos, 1, "::");
            pos += 2;
        }
        file.beginLine().append("using namespace ").append(cppNamespace).append(";").endLine();
    }
    file.beginLine().append("").endLine();
}

void CppProducer::generateStructSourceNamespaces(CppFile& file, std::string_view name)
{
    generateSourceNamespaces(file, name);
}

void CppProducer::generateStructSourceBasicFunctions(CppFile& file, std::string_view functionPrefix,
                                                     std::string_view handleTypeName,
                                                     std::string_view className)
{
    // Generate struct creation function
    file.beginLine()
        .append("// Opaque struct creation")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_constructor()")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("return new ")
        .append(className)
        .append("();")
        .endLine()
        .endBlock()
        .beginLine()
        .append("")
        .endLine();

    // Generate struct destroy function
    file.beginLine()
        .append("// Opaque handle destruction")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_destroy(")
        .append(handleTypeName)
        .append(" handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("delete static_cast<")
        .append(className)
        .append("*>(handle);")
        .endLine()
        .endBlock()
        .beginLine()
        .append("")
        .endLine();

    // Generate from_ptr function for struct type casting
    file.beginLine()
        .append("// Struct from_ptr type casting")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_ptr(void* ptr)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (ptr == nullptr) return nullptr;")
        .endLine()
        .beginLine()
        .append("// For structs, we assume the pointer is already the correct type")
        .endLine()
        .beginLine()
        .append("// Create a copy of the struct")
        .endLine()
        .beginLine()
        .append("")
        .append(className)
        .append("* source = static_cast<")
        .append(className)
        .append("*>(ptr);")
        .endLine()
        .beginLine()
        .append("return new ")
        .append(className)
        .append("(*source);")
        .endLine()
        .endBlock()
        .beginLine()
        .append("")
        .endLine();
}

void CppProducer::generateStructSourceBaseMembers(
    CppFile& file, std::string_view functionPrefix, std::string_view handleTypeName,
    std::string_view className, const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    // Generate getters/setters for base type members (if struct has a base)
    if (!entity->getDirectBase().isEmpty())
    {
        file.beginLine()
            .append("// Getters/setters for base type members (")
            .append(entity->getDirectBase())
            .append(")")
            .endLine();

        // Get base type entity to access its members
        rtl::Reference<unoidl::Entity> baseEntity;
        codemaker::UnoType::Sort baseSort
            = m_typeManager->getSort(entity->getDirectBase(), &baseEntity);

        if (baseSort == codemaker::UnoType::Sort::PlainStruct)
        {
            rtl::Reference<unoidl::PlainStructTypeEntity> baseStruct(
                static_cast<unoidl::PlainStructTypeEntity*>(baseEntity.get()));

            for (const auto& baseMember : baseStruct->getDirectMembers())
            {
                generateStructMemberAccessors(file, functionPrefix, handleTypeName, className,
                                              baseMember);
            }
        }
    }
}

void CppProducer::generateStructSourceDirectMembers(
    CppFile& file, std::string_view functionPrefix, std::string_view handleTypeName,
    std::string_view className, const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    // Generate getters/setters for direct struct members
    file.beginLine().append("// Getters/setters for direct struct members").endLine();

    for (const auto& member : entity->getDirectMembers())
    {
        generateStructMemberAccessors(file, functionPrefix, handleTypeName, className, member);
    }
}

void CppProducer::generateStructMemberAccessors(CppFile& file, std::string_view functionPrefix,
                                                std::string_view handleTypeName,
                                                std::string_view className,
                                                const unoidl::PlainStructTypeEntity::Member& member)
{
    // Generate getter implementation
    file.beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(getStructGetterReturnType(member.type))
        .append(" ")
        .append(functionPrefix)
        .append("_get_")
        .append(member.name)
        .append("(")
        .append(handleTypeName)
        .append(" handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append(className)
        .append("* obj = static_cast<")
        .append(className)
        .append("*>(handle);")
        .endLine()
        .beginLine();

    // Handle return value conversion based on type
    if (member.type == u"string")
    {
        // For string types, return pointer to the OUString object
        file.append("return &(obj->").append(member.name).append(");");
    }
    else if (member.type == u"any")
    {
        // For any types, return pointer to the Any
        file.append("return &(obj->").append(member.name).append(");");
    }
    else if (member.type == u"boolean" || member.type == u"byte" || member.type == u"short"
             || member.type == u"unsigned short" || member.type == u"long"
             || member.type == u"unsigned long" || member.type == u"hyper"
             || member.type == u"unsigned hyper" || member.type == u"float"
             || member.type == u"double")
    {
        // For primitive types, return pointer to the member for direct access
        file.append("return &(obj->").append(member.name).append(");");
    }
    else
    {
        // For other types, return pointer to member
        file.append("return &(obj->").append(member.name).append(");");
    }

    file.endLine().endBlock();

    // Generate setter implementation
    file.beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_set_")
        .append(member.name)
        .append("(")
        .append(handleTypeName)
        .append(" handle, ")
        .append(getStructSetterParameterType(member.type))
        .append(" value)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append(className)
        .append("* obj = static_cast<")
        .append(className)
        .append("*>(handle);")
        .endLine()
        .beginLine()
        .append("obj->")
        .append(member.name);

    // Handle assignment based on parameter type
    OUString unoType = member.type;

    // Check if we're using typed primitive parameters (passed by value)
    if (unoType == u"boolean" || unoType == u"byte" || unoType == u"short"
        || unoType == u"unsigned short" || unoType == u"long" || unoType == u"unsigned long"
        || unoType == u"hyper" || unoType == u"unsigned hyper" || unoType == u"float"
        || unoType == u"double")
    {
        // For primitive types with typed parameters, assign directly (no dereferencing)
        file.append(" = value;");
    }
    else if (unoType == u"string")
    {
        // For string types, dereference the pointer to OUString
        file.append(" = *reinterpret_cast<const OUString*>(value);");
    }
    else if (unoType == u"any")
    {
        // For any types with typed parameters, dereference the uno_Any*
        file.append(" = *reinterpret_cast<const Any*>(value);");
    }
    else
    {
        // For other types (interfaces, structs, enums), use original logic with void*
        // Check if this is a UNO interface type using proper TypeManager classification
        if (isUnoInterface(unoType))
        {
            // For interface types, assign the pointer directly without dereferencing
            file.append(" = reinterpret_cast<")
                .append(convertUnoTypeToCpp(unoType))
                .append("*>(value);");
        }
        else
        {
            // For non-interface types, dereference the pointer
            file.append(" = *reinterpret_cast<const ")
                .append(convertUnoTypeToCpp(unoType))
                .append("*>(value);");
        }
    }
    file.endLine().endBlock().beginLine().append("").endLine();
}

void CppProducer::generateStructSource(std::string_view name,
                                       const rtl::Reference<unoidl::PlainStructTypeEntity>& entity)
{
    if (m_dryRun || !m_combinedSourceFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedSourceFile;
    file.openFileAppend();

    // Add separator comment for this struct
    file.beginLine().append("").endLine();
    file.beginLine().append("// === ").append(name).append(" ===").endLine();

    // Start isolated block for this struct to avoid namespace conflicts
    file.beginLine().append("namespace");
    file.beginBlock();

    // Generate includes
    generateStructSourceIncludes(file, name);

    // Generate namespaces (now in isolated scope)
    generateStructSourceNamespaces(file, name);

    OString functionPrefix = getCFunctionPrefix(name);
    OString handleTypeName = functionPrefix + "Handle";
    // Use fully qualified C++ type name to avoid namespace ambiguity
    OString className = convertUnoTypeToCpp(OUString::createFromAscii(std::string(name)));

    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Generate basic functions (creation/destruction)
    generateStructSourceBasicFunctions(file, functionPrefix, handleTypeName, className);

    // Generate accessors for base type members
    generateStructSourceBaseMembers(file, functionPrefix, handleTypeName, className, entity);

    // Generate accessors for direct members
    generateStructSourceDirectMembers(file, functionPrefix, handleTypeName, className, entity);

    file.endBlock().append(" // extern \"C\"").endLine();

    // End isolated block for this struct
    file.endBlock().append(" // End isolated block for ").append(name).endLine();

    file.closeFile();
}

// Helper functions
std::string_view CppProducer::splitName(std::string_view name)
{
    size_t split = name.find_last_of(".::");
    if (split != std::string_view::npos)
        return name.substr(split + 1);
    else
        return name;
}

OString CppProducer::getInterfaceClassName(std::string_view unoName)
{
    return OString(splitName(unoName));
}

OString CppProducer::getCFunctionPrefix(std::string_view unoName)
{
    // Convert com.sun.star.lang.XMain to com__sun__star__lang__XMain for function names
    OString temp(unoName);
    return temp.replaceAll("."_ostr, "__"_ostr);
}

OString CppProducer::getMethodReturnType(std::u16string_view returnType) const
{
    // Use the sophisticated type mapping from the old FFI producer
    return getCppTypeName(returnType);
}

OString CppProducer::getMethodDefaultReturn(std::u16string_view returnType) const
{
    // First resolve any typedefs to their underlying types
    OUString resolvedType = resolveTypedef(returnType);

    // Handle void vs non-void return types properly
    if (resolvedType == u"void")
        return ""_ostr; // void methods don't return anything

    // Return appropriate default values for different types
    if (resolvedType == u"double")
        return "0.0"_ostr;
    else if (resolvedType == u"float")
        return "0.0f"_ostr;
    else if (resolvedType == u"sal_Int32" || resolvedType == u"long" || resolvedType == u"sal_Int16"
             || resolvedType == u"short" || resolvedType == u"sal_Int8" || resolvedType == u"byte"
             || resolvedType == u"sal_uInt8" || resolvedType == u"sal_uInt16"
             || resolvedType == u"sal_uInt32" || resolvedType == u"sal_Int64"
             || resolvedType == u"sal_uInt64" || resolvedType == u"sal_Unicode"
             || resolvedType == u"unsigned short" || resolvedType == u"unsigned long"
             || resolvedType == u"unsigned hyper" || resolvedType == u"hyper")
        return "0"_ostr;
    else if (resolvedType == u"sal_Bool" || resolvedType == u"boolean")
        return "false"_ostr;
    else
    {
        // Check if it's an enum type
        if (isUnoType(resolvedType) && isUnoEnum(resolvedType))
        {
            // Return default enum value (first enum value, typically 0)
            OString returnTypeStr = u2b(resolvedType);
            size_t lastDot = returnTypeStr.lastIndexOf('.');
            std::string_view enumName = (lastDot != std::string_view::npos)
                                            ? returnTypeStr.subView(lastDot + 1)
                                            : returnTypeStr;
            return "static_cast<"_ostr + enumName + "_>(0)"_ostr;
        }
        // Check if it's a struct type
        else if (isUnoType(resolvedType) && isUnoStruct(resolvedType))
        {
            // Return empty struct for struct types
            return "{}"_ostr; // Empty struct literal
        }
        else
        {
            return "nullptr"_ostr; // For pointer/interface/any types
        }
    }
}

OString CppProducer::convertUnoTypeToCpp(std::u16string_view unoType) const
{
    std::string result(unoType.begin(), unoType.end());

    // Handle sequences: []type -> Sequence<type>
    int sequenceDepth = 0;
    while (result.starts_with("[]"))
    {
        result = result.substr(2);
        sequenceDepth++;
    }

    // Check if the inner type is an interface and wrap with Reference<> if needed for sequences
    bool needsReferenceWrapper = false;
    if (sequenceDepth > 0 && result.find(".") != std::string::npos)
    {
        // For UNO types with namespaces, check if it's an interface (before namespace conversion)
        rtl::Reference<unoidl::Entity> entity;
        OUString unoTypeName = OUString::createFromAscii(result);
        codemaker::UnoType::Sort sort = m_typeManager->getSort(unoTypeName, &entity);

        if (sort == codemaker::UnoType::Sort::Interface)
        {
            needsReferenceWrapper = true;
        }
    }

    // Handle template arguments recursively (before namespace conversion)
    result = convertTemplateArguments(result);

    // Convert dots to double colons for C++ namespace syntax
    size_t pos = 0;
    while ((pos = result.find('.', pos)) != std::string::npos)
    {
        result.replace(pos, 1, "::");
        pos += 2;
    }

    // Handle primitive types (only for non-template contexts)
    if (result.find('<') == std::string::npos)
    {
        if (result == "boolean")
            result = "sal_Bool";
        else if (result == "byte")
            result = "sal_Int8";
        else if (result == "short")
            result = "sal_Int16";
        else if (result == "unsigned short")
            result = "sal_uInt16";
        else if (result == "long")
            result = "sal_Int32";
        else if (result == "unsigned long")
            result = "sal_uInt32";
        else if (result == "hyper")
            result = "sal_Int64";
        else if (result == "unsigned hyper")
            result = "sal_uInt64";
        else if (result == "float")
            result = "float";
        else if (result == "double")
            result = "double";
        else if (result == "char")
            result = "sal_Unicode";
        else if (result == "string")
            result = "OUString";
        else if (result == "type")
            result = "Type";
        else if (result == "any")
            result = "Any";
        // else: keep as-is for UNO types like com::sun::star::...
    }

    // Apply Reference<> wrapper if needed
    if (needsReferenceWrapper)
    {
        result = "Reference<" + result + ">";
    }

    // Wrap with Sequence<> for each nesting level
    for (int i = 0; i < sequenceDepth; i++)
    {
        result = "Sequence<" + result + ">";
    }

    return OString(result.c_str());
}

std::string CppProducer::convertTemplateArguments(const std::string& unoType) const
{
    std::string result = unoType;

    // Find template arguments within < >
    size_t start = result.find('<');
    if (start == std::string::npos)
        return result; // No template arguments

    size_t end = result.rfind('>');
    if (end == std::string::npos || end <= start)
        return result; // Malformed template

    // Extract and process template arguments
    std::string prefix = result.substr(0, start + 1);
    std::string suffix = result.substr(end);
    std::string args = result.substr(start + 1, end - start - 1);

    // Split arguments by comma (simple split for now)
    std::string processedArgs = "";
    size_t argStart = 0;
    size_t comma = 0;

    while (true)
    {
        comma = args.find(',', argStart);
        std::string arg;
        if (comma == std::string::npos)
        {
            arg = args.substr(argStart);
        }
        else
        {
            arg = args.substr(argStart, comma - argStart);
        }

        // Trim whitespace
        arg.erase(0, arg.find_first_not_of(" \t"));
        arg.erase(arg.find_last_not_of(" \t") + 1);

        // Recursively process nested template arguments first
        arg = convertTemplateArguments(arg);

        // Handle sequence types first: []type -> Sequence<type>
        if (arg.starts_with("[]"))
        {
            std::string innerType = arg.substr(2);
            arg = "Sequence<" + innerType + ">";
        }

        // Convert basic types
        if (arg == "string")
            arg = "OUString";
        else if (arg == "boolean")
            arg = "sal_Bool";
        else if (arg == "byte")
            arg = "sal_Int8";
        else if (arg == "short")
            arg = "sal_Int16";
        else if (arg == "long")
            arg = "sal_Int32";
        else if (arg == "hyper")
            arg = "sal_Int64";
        else if (arg == "float")
            arg = "float";
        else if (arg == "double")
            arg = "double";
        else if (arg == "char")
            arg = "sal_Unicode";
        else if (arg == "type")
            arg = "Type";
        else if (arg == "any")
            arg = "Any";
        // For complex types, convert dots to ::
        else if (arg.find('.') != std::string::npos)
        {
            size_t pos = 0;
            while ((pos = arg.find('.', pos)) != std::string::npos)
            {
                arg.replace(pos, 1, "::");
                pos += 2;
            }
        }

        if (!processedArgs.empty())
            processedArgs += ",";
        processedArgs += arg;

        if (comma == std::string::npos)
            break;
        argStart = comma + 1;
    }

    return prefix + processedArgs + suffix;
}

void CppProducer::generateInterfaceHeader(std::string_view name,
                                          const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    if (m_dryRun || !m_combinedHeaderFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedHeaderFile;
    file.openFileAppend();

    // Add separator comment for this interface
    file.beginLine().append("").endLine();
    file.beginLine().append("// === ").append(name).append(" ===").endLine();

    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Generate opaque handle typedef
    OString functionPrefix = getCFunctionPrefix(name);
    OString handleTypeName = functionPrefix + "Handle";

    file.beginLine()
        .append("// Opaque handle for type-safe C FFI")
        .endLine()
        .beginLine()
        .append("typedef void* ")
        .append(handleTypeName)
        .append(";")
        .endLine()
        .beginLine()
        .append("")
        .endLine();

    // Generate create/destroy functions
    file.beginLine()
        .append("// Interface lifecycle")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_constructor();")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_destructor(")
        .append(handleTypeName)
        .append(" handle);")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_ptr(void* ptr);")
        .endLine();

    file.beginLine().append("").endLine();

    // Generate method wrappers for all methods
    file.beginLine().append("// Method wrappers").endLine();

    // TODO: Add interface inheritance support in the future
    // For now, only process direct methods from this interface

    // Process only this interface's direct methods (no inheritance)
    for (const auto& method : entity->getDirectMethods())
    {
        // Generate method signature
        file.beginLine();

        // Return type - use void* for all non-void returns (keep it simple)
        OString returnType = getMethodReturnType(method.returnType);
        if (returnType == "void")
        {
            file.append("SAL_DLLPUBLIC_EXPORT void ");
        }
        else
        {
            file.append("SAL_DLLPUBLIC_EXPORT void* ");
        }

        // Function name: com__sun__star__lang__XMain__methodName
        file.append(functionPrefix)
            .append("_")
            .append(method.name)
            .append("(")
            .append(handleTypeName)
            .append(" handle");

        // Add typed parameters instead of void*
        for (const auto& param : method.parameters)
        {
            file.append(", ")
                .append(getTypedParameterType(param.type, param.direction))
                .append(" ")
                .append(param.name);
        }

        file.append(");");
        file.endLine();
    }

    file.endBlock().beginLine().append("// extern \"C\"").endLine();

    file.closeFile();
}

void CppProducer::generateInterfaceSourceIncludes(CppFile& file, std::string_view name)
{
    generateCommonIncludes(file, name, true, true);
}

void CppProducer::generateInterfaceSourceNamespaces(CppFile& file, std::string_view name)
{
    generateSourceNamespaces(file, name);
}

void CppProducer::generateInterfaceSourceBasicFunctions(CppFile& file,
                                                        std::string_view functionPrefix,
                                                        std::string_view className,
                                                        std::string_view handleTypeName)
{
    // Interface creation
    file.beginLine()
        .append("// Interface creation - creates empty Reference (to be populated by Rust)")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_constructor()")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("//Debug: Interface constructor called for ")
        .append(className)
        .endLine()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"Debug: Creating interface ")
        .append(className)
        .append("\");")
        .endLine()
        .beginLine()
        .append("// Create empty Reference - actual interface will be set from Rust side")
        .endLine()
        .beginLine()
        .append("auto res = new Reference<")
        .append(className)
        .append(">();")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("if (!res)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("SAL_WARN(\"rust_uno_ffi\", \"Failed to allocate Reference<")
        .append(className)
        .append("> wrapper\");")
        .endLine()
        .beginLine()
        .append("return nullptr;")
        .endLine()
        .endBlock()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append(
            "// Note: Empty Reference is expected here - is() will be false until set from Rust")
        .endLine()
        .beginLine()
        .append("SAL_INFO(\"rust_uno_ffi\", \"✅ Successfully created empty Reference<")
        .append(className)
        .append("> wrapper\");")
        .endLine()
        .beginLine()
        .append("return res;")
        .endLine()
        .endBlock();

    file.beginLine().append("").endLine();

    // Interface destruction
    file.beginLine()
        .append("// Interface destruction")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void ")
        .append(functionPrefix)
        .append("_destructor(")
        .append(handleTypeName)
        .append(" handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("delete static_cast<Reference<")
        .append(className)
        .append(">*>(handle);")
        .endLine()
        .endBlock();
    file.beginLine().append("").endLine();

    // Interface casting from void* to typed Reference using UNO_QUERY
    file.beginLine()
        .append("// Interface casting - casts void* to typed Reference using UNO_QUERY")
        .endLine()
        .beginLine()
        .append("SAL_DLLPUBLIC_EXPORT ")
        .append(handleTypeName)
        .append(" ")
        .append(functionPrefix)
        .append("_from_ptr(void* ptr)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("if (ptr == nullptr) return nullptr;")
        .endLine()
        .beginLine()
        .append("try")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("// Convert XInterface* to ")
        .append(className)
        .append(" via UNO_QUERY")
        .endLine()
        .beginLine()
        .append("Reference<XInterface>* interfacePtr = static_cast<Reference<XInterface>*>(ptr);")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append(className)
        .append("> queryResult(interfacePtr->get(), UNO_QUERY);")
        .endLine()
        .beginLine()
        .append("if (!queryResult.is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append(className)
        .append(">* refPtr = new Reference<")
        .append(className)
        .append(">(queryResult);")
        .endLine()
        .beginLine()
        .append("if (refPtr && refPtr->is())")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("SAL_INFO(\"rust_uno_ffi\", \"Successfully created Reference<")
        .append(className)
        .append("> in from_ptr\");")
        .endLine()
        .beginLine()
        .append("return refPtr;")
        .endBlock()
        .beginLine()
        .append("SAL_WARN(\"rust_uno_ffi\", \"Reference is invalid in from_ptr for ")
        .append(className)
        .append("\");")
        .endLine()
        .beginLine()
        .append("delete refPtr;")
        .endLine()
        .beginLine()
        .append("return nullptr;")
        .endLine()
        .endBlock()
        .beginLine()
        .append("catch (const Exception& e)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"UNO exception in ")
        .append(functionPrefix)
        .append("_from_ptr: \" << e.Message);")
        .endLine()
        .beginLine()
        .append("return nullptr;")
        .endLine()
        .beginLine()
        .append("}")
        .endLine()
        .endBlock();

    file.beginLine().append("").endLine();
}

void CppProducer::generateInterfaceSourceMethodImplementations(
    CppFile& file, std::string_view functionPrefix, std::string_view className,
    std::string_view handleTypeName, const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    // Generate method implementations
    file.beginLine().append("// Method implementations").endLine();

    // TODO: Add interface inheritance support in the future
    // For now, only process direct methods from this interface (no inheritance)

    // Process only this interface's direct methods
    for (const auto& method : entity->getDirectMethods())
    {
        generateSingleInterfaceMethod(file, functionPrefix, className, handleTypeName, method);
    }
}

void CppProducer::generateSingleInterfaceMethod(CppFile& file, std::string_view functionPrefix,
                                                std::string_view className,
                                                std::string_view handleTypeName,
                                                const unoidl::InterfaceTypeEntity::Method& method)
{
    file.beginLine();

    // Use void* for all non-void returns (keep it simple)
    OString returnType = getMethodReturnType(method.returnType);
    if (returnType == "void")
    {
        file.append("SAL_DLLPUBLIC_EXPORT void ");
    }
    else
    {
        file.append("SAL_DLLPUBLIC_EXPORT void* ");
    }

    file.append(functionPrefix)
        .append("_")
        .append(method.name)
        .append("(")
        .append(handleTypeName)
        .append(" handle");

    // Add typed parameters instead of void*
    for (const auto& param : method.parameters)
    {
        file.append(", ")
            .append(getTypedParameterType(param.type, param.direction))
            .append(" ")
            .append(param.name);
    }

    file.append(")").endLine().beginBlock();

    // Implementation body
    file.beginLine()
        .append("//Debug: Method ")
        .append(method.name)
        .append(" called")
        .endLine()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"Debug: Method ")
        .append(className)
        .append("::")
        .append(method.name)
        .append(" called\");")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append(className)
        .append(">* ref = static_cast<Reference<")
        .append(className)
        .append(">*>(handle);")
        .endLine()
        .beginLine()
        .append("//Debug: Checking reference validity")
        .endLine()
        .beginLine()
        .append("if (!ref) { SAL_WARN(\"rustmaker\", \"Debug: ref is null\"); ")
        .append(method.returnType == u"void" ? "return;" : "return nullptr;")
        .append(" }")
        .endLine()
        .beginLine()
        .append("if (!ref->is()) { SAL_WARN(\"rustmaker\", \"Debug: ref->is() is false\"); ")
        .append(method.returnType == u"void" ? "return;" : "return nullptr;")
        .append(" }")
        .endLine();

    // Generate try-catch block for UNO exceptions
    file.beginLine().append("try").endLine().beginBlock();

    // Generate actual UNO method call
    generateActualMethodCall(file, method);

    // Note: Return value conversion is now handled inside generateActualMethodCall()

    // Exception handling
    file.endBlock()
        .beginLine()
        .append("catch (const Exception& ex)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"UNO exception in ")
        .append(className)
        .append("_")
        .append(method.name)
        .append(": \" << ex.Message);")
        .endLine();

    // Return appropriate error value based on return type
    if (method.returnType == u"void")
    {
        file.beginLine().append("return; // void method - no return on exception").endLine();
    }
    else
    {
        file.beginLine().append("return nullptr; // error return for non-void method").endLine();
    }

    file.endBlock().endBlock();

    file.beginLine().append("").endLine();
}

void CppProducer::generateInterfaceSource(std::string_view name,
                                          const rtl::Reference<unoidl::InterfaceTypeEntity>& entity)
{
    if (m_dryRun || !m_combinedSourceFile)
        return;

    // Use combined file instead of individual file
    CppFile& file = *m_combinedSourceFile;
    file.openFileAppend();

    // Add separator comment for this interface
    file.beginLine().append("").endLine();
    file.beginLine().append("// === ").append(name).append(" ===").endLine();

    // Generate includes
    generateInterfaceSourceIncludes(file, name);

    // Add namespaces
    generateInterfaceSourceNamespaces(file, name);

    file.beginLine().append("extern \"C\"").endLine().beginBlock();

    // Generate implementation
    OString functionPrefix = getCFunctionPrefix(name);
    OString handleTypeName = functionPrefix + "Handle";
    // Use fully qualified C++ type name to avoid namespace ambiguity
    OString className = convertUnoTypeToCpp(OUString::createFromAscii(std::string(name)));

    // Generate basic functions (creation/destruction)
    generateInterfaceSourceBasicFunctions(file, functionPrefix, className, handleTypeName);

    // Generate method implementations
    generateInterfaceSourceMethodImplementations(file, functionPrefix, className, handleTypeName,
                                                 entity);

    file.endBlock().append(" // extern \"C\"");
    file.beginLine().append("").endLine();

    file.closeFile();
}

void CppProducer::generateActualMethodCall(CppFile& file,
                                           const unoidl::InterfaceTypeEntity::Method& method)
{
    // Generate actual UNO method call based on method signature
    file.beginLine()
        .append("//Debug: About to call UNO method ")
        .append(method.name)
        .endLine()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"Debug: Calling UNO method ")
        .append(method.name)
        .append(" with ")
        .append(OString::number(static_cast<sal_Int32>(method.parameters.size())))
        .append(" parameters\");")
        .endLine();

    if (method.returnType != u"void")
    {
        // Method with return value
        file.beginLine()
            .append("// Call actual UNO method with return value")
            .endLine()
            .beginLine();

        file.append("auto result = (*ref)->").append(method.name).append("(");
    }
    else
    {
        // Void method
        file.beginLine().append("// Call actual UNO method (void return)").endLine().beginLine();

        file.append("(*ref)->").append(method.name).append("(");
    }

    // Add parameters with proper type conversion
    bool first = true;
    for (const auto& param : method.parameters)
    {
        if (!first)
            file.append(", ");
        first = false;

        // Convert void* parameters to proper UNO types based on parameter type
        std::u16string_view paramType = param.type;

        // Determine if parameter is input-only (needs const) or output/inout (needs non-const reference)
        bool isInputOnly
            = (param.direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN);

        if (paramType == u"string")
        {
            if (isInputOnly)
            {
                // Input parameter: direct rtl_uString* to OUString conversion (no casting needed)
                file.append("OUString(").append(param.name).append(")");
            }
            else
            {
                // Output parameter: rtl_uString** needs dereferencing to OUString reference
                file.append("*reinterpret_cast<OUString*>(*").append(param.name).append(")");
            }
        }
        else if (paramType == u"any")
        {
            if (isInputOnly)
            {
                // Input parameter: dereference uno_Any* to get Any& (Any inherits from uno_Any)
                file.append("*reinterpret_cast<const Any*>(").append(param.name).append(")");
            }
            else
            {
                // Output parameter: uno_Any** needs dereferencing to Any reference
                file.append("*reinterpret_cast<Any*>(*").append(param.name).append(")");
            }
        }
        // Handle all primitive types with typed parameter support
        else if (paramType == u"boolean" || paramType == u"byte" || paramType == u"short"
                 || paramType == u"unsigned short" || paramType == u"long"
                 || paramType == u"unsigned long" || paramType == u"hyper"
                 || paramType == u"unsigned hyper" || paramType == u"float"
                 || paramType == u"double")
        {
            // Check if this primitive type is using typed parameters
            OString primitiveType = mapUnoPrimitiveToSal(resolveTypedef(paramType));
            if (!primitiveType.isEmpty())
            {
                // Typed parameter approach - direct value for input, dereference pointer for input/output
                if (isInputOnly)
                    file.append(param.name); // Direct value (sal_Bool, sal_Int32, double, etc.)
                else
                    file.append("*").append(
                        param.name); // Dereference pointer (sal_Bool*, sal_Int32*, double*, etc.)
            }
            else
            {
                // Fallback to void* approach (shouldn't happen for primitives, but just in case)
                if (isInputOnly)
                    file.append("*reinterpret_cast<const ")
                        .append(primitiveType)
                        .append("*>(")
                        .append(param.name)
                        .append(")");
                else
                    file.append("*reinterpret_cast<")
                        .append(primitiveType)
                        .append("*>(")
                        .append(param.name)
                        .append(")");
            }
        }
        else if (paramType == u"type")
        {
            if (isInputOnly)
                file.append("*reinterpret_cast<const Type*>(").append(param.name).append(")");
            else
                file.append("*reinterpret_cast<Type*>(").append(param.name).append(")");
        }
        else if (paramType.starts_with(u"[]"))
        {
            // Sequence type - convert with null pointer safety
            OString cppTypeName = convertUnoTypeToCpp(paramType);

            if (isInputOnly)
            {
                // Input parameter - can use temporary empty sequence
                file.append("(")
                    .append(param.name)
                    .append(" ? *reinterpret_cast<const ")
                    .append(cppTypeName)
                    .append("*>(")
                    .append(param.name)
                    .append(") : ")
                    .append(cppTypeName)
                    .append("())");
            }
            else
            {
                // Output/InOut parameter - needs reference, must dereference non-null pointer
                file.append("*reinterpret_cast<")
                    .append(cppTypeName)
                    .append("*>(")
                    .append(param.name)
                    .append(")");
            }
        }
        else
        {
            // For interfaces and other complex types
            // Check if it's an interface type that needs Reference<> wrapper
            rtl::Reference<unoidl::Entity> entity;
            codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(paramType), &entity);

            if (sort == codemaker::UnoType::Sort::Interface)
            {
                // Interface parameters: void* from Rust points to Reference<ActualType>*
                // We need to dereference and cast via UNO_QUERY to the expected interface type
                OString cppTypeName = convertUnoTypeToCpp(paramType);
                if (isInputOnly)
                {
                    // For input interface parameters, we assume the Rust code passes Reference<SomeInterface>*
                    // We dereference it and cast via UNO_QUERY to the expected interface type
                    file.append("Reference<")
                        .append(cppTypeName)
                        .append(">(static_cast<Reference<XInterface>*>(")
                        .append(param.name)
                        .append(")->get(), UNO_QUERY)");
                }
                else
                    file.append("*reinterpret_cast<Reference<")
                        .append(cppTypeName)
                        .append(">*>(")
                        .append(param.name)
                        .append(")");
            }
            else
            {
                // For structs and other complex types, assume proper type cast
                OString cppTypeName = convertUnoTypeToCpp(paramType);
                if (isInputOnly)
                {
                    file.append("(")
                        .append(param.name)
                        .append(" == nullptr ? ")
                        .append(cppTypeName)
                        .append("() : *reinterpret_cast<const ")
                        .append(cppTypeName)
                        .append("*>(")
                        .append(param.name)
                        .append("))");
                }
                else
                {
                    file.append("*reinterpret_cast<")
                        .append(cppTypeName)
                        .append("*>(")
                        .append(param.name)
                        .append(")");
                }
            }
        }
    }

    file.append(");").endLine();

    // Handle return value conversion for non-void methods
    if (method.returnType != u"void")
    {
        // Use helper function to eliminate code duplication
        generateReturnValueConversion(file, method);
    }
}

void CppProducer::generateReturnValueConversion(CppFile& file,
                                                const unoidl::InterfaceTypeEntity::Method& method)
{
    file.beginLine().append("// Convert result to opaque void* return").endLine();

    std::u16string_view returnType = method.returnType;

    if (returnType == u"string")
    {
        file.beginLine().append("return new OUString(result);").endLine();
    }
    else if (returnType == u"any")
    {
        file.beginLine().append("return new Any(result);").endLine();
    }
    else if (returnType == u"boolean")
    {
        file.beginLine().append("return new sal_Bool(result);").endLine();
    }
    else if (returnType == u"byte")
    {
        file.beginLine().append("return new sal_Int8(result);").endLine();
    }
    else if (returnType == u"short")
    {
        file.beginLine().append("return new sal_Int16(result);").endLine();
    }
    else if (returnType == u"long")
    {
        file.beginLine().append("return new sal_Int32(result);").endLine();
    }
    else if (returnType == u"hyper")
    {
        file.beginLine().append("return new sal_Int64(result);").endLine();
    }
    else if (returnType == u"float")
    {
        file.beginLine().append("return new float(result);").endLine();
    }
    else if (returnType == u"double")
    {
        file.beginLine().append("return new double(result);").endLine();
    }
    else if (returnType == u"type")
    {
        file.beginLine().append("return new Type(result);").endLine();
    }
    else if (returnType.starts_with(u"[]"))
    {
        // Sequence return type - return void* to new sequence
        file.beginLine()
            .append("return new ")
            .append(convertUnoTypeToCpp(returnType))
            .append("(result);")
            .endLine();
    }
    else
    {
        // For interfaces - return Reference<> to avoid instantiating abstract types
        rtl::Reference<unoidl::Entity> entity;
        codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(returnType), &entity);

        if (sort == codemaker::UnoType::Sort::Interface)
        {
            // Interface return type - return new Reference<Interface>(result)
            file.beginLine()
                .append("SAL_INFO(\"rust_uno_ffi\", \"Creating Reference wrapper for return type ")
                .append(convertUnoTypeToCpp(returnType))
                .append("\");")
                .endLine()
                .beginLine()
                .append("auto res = new Reference<")
                .append(convertUnoTypeToCpp(returnType))
                .append(">(result);")
                .endLine()
                .beginLine()
                .append("")
                .endLine()
                .beginLine()
                .append("if (!res)")
                .endLine()
                .beginBlock()
                .beginLine()
                .append("SAL_WARN(\"rust_uno_ffi\", \"Failed to create Reference wrapper for ")
                .append(convertUnoTypeToCpp(returnType))
                .append("\");")
                .endLine()
                .beginLine()
                .append("return nullptr;")
                .endLine()
                .endBlock()
                .beginLine()
                .append("")
                .endLine()
                .beginLine()
                .append("if (!res->is())")
                .endLine()
                .beginBlock()
                .beginLine()
                .append(
                    "SAL_WARN(\"rust_uno_ffi\", \"Reference wrapper is invalid (is() = false) for ")
                .append(convertUnoTypeToCpp(returnType))
                .append("\");")
                .endLine()
                .beginLine()
                .append("delete res;")
                .endLine()
                .beginLine()
                .append("return nullptr;")
                .endLine()
                .endBlock()
                .beginLine()
                .append("")
                .endLine()
                .beginLine()
                .append("SAL_INFO(\"rust_uno_ffi\", \"✅ Successfully created valid Reference "
                        "wrapper for ")
                .append(convertUnoTypeToCpp(returnType))
                .append("\");")
                .endLine()
                .beginLine()
                .append("return res;")
                .endLine();
        }
        else
        {
            // For structs, enums and other types - return void* to new object
            file.beginLine()
                .append("return new ")
                .append(convertUnoTypeToCpp(returnType))
                .append("(result);")
                .endLine();
        }
    }
}

// Type mapping functions (from old FFI producer)

OUString CppProducer::resolveTypedef(std::u16string_view unoType) const
{
    // Recursively resolve typedefs to their underlying types
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;
    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(unoType), &entity, &cursor);

    if (sort == codemaker::UnoType::Sort::Typedef)
    {
        rtl::Reference<unoidl::TypedefEntity> typedefEntity(
            static_cast<unoidl::TypedefEntity*>(entity.get()));
        if (typedefEntity.is())
        {
            // Recursively resolve in case of nested typedefs
            OUString resolvedType = typedefEntity->getType();
            return resolveTypedef(resolvedType);
        }
    }

    // If not a typedef or resolution failed, return the original type
    return OUString(unoType);
}

OString CppProducer::mapUnoPrimitiveToSal(std::u16string_view unoType)
{
    // Common primitive type mappings from UNO to SAL types
    if (unoType == u"boolean")
        return "sal_Bool"_ostr;
    else if (unoType == u"byte")
        return "sal_Int8"_ostr;
    else if (unoType == u"short")
        return "sal_Int16"_ostr;
    else if (unoType == u"unsigned short")
        return "sal_uInt16"_ostr;
    else if (unoType == u"long")
        return "sal_Int32"_ostr;
    else if (unoType == u"unsigned long")
        return "sal_uInt32"_ostr;
    else if (unoType == u"hyper")
        return "sal_Int64"_ostr;
    else if (unoType == u"unsigned hyper")
        return "sal_uInt64"_ostr;
    else if (unoType == u"float")
        return "float"_ostr;
    else if (unoType == u"double")
        return "double"_ostr;
    else
        return OString(); // Not a primitive type
}

OString CppProducer::getCppTypeName(std::u16string_view unoType) const
{
    // First, resolve any typedefs to their underlying types
    OUString resolvedType = resolveTypedef(unoType);

    // Map UNO types to C++ types for extern "C" functions
    if (resolvedType == u"void")
        return "void"_ostr;
    else if (resolvedType == u"string")
        return "rtl_uString*"_ostr;
    else if (resolvedType == u"any" || resolvedType == u"com.sun.star.uno.Any")
        return "uno_Any*"_ostr;

    // Try primitive type mapping
    OString primitiveType = mapUnoPrimitiveToSal(resolvedType);
    if (!primitiveType.isEmpty())
        return primitiveType;

    // Handle complex types
    if (resolvedType.startsWith(u"[]"))
        return "uno_Sequence*"_ostr;
    else if (isUnoStruct(resolvedType))
    {
        // For structs, return the FFI struct name with underscore (value type, not pointer)
        OString type = u2b(resolvedType);
        size_t lastDot = type.lastIndexOf('.');
        if (lastDot != std::string_view::npos)
            return OString::Concat(type.subView(lastDot + 1)) + "_";
        else
            return type + "_";
    }
    else if (isUnoEnum(resolvedType))
    {
        // For enums, return the enum name with underscore to match generated FFI enums
        OString type = u2b(resolvedType);
        size_t lastDot = type.lastIndexOf('.');
        if (lastDot != std::string_view::npos)
            return OString::Concat(type.subView(lastDot + 1)) + "_";
        else
            return type + "_";
    }
    else if (isUnoConstantGroup(resolvedType))
    {
        // For constant groups, return the FFI name with underscore
        OString type = u2b(resolvedType);
        size_t lastDot = type.lastIndexOf('.');
        if (lastDot != std::string_view::npos)
            return OString::Concat(type.subView(lastDot + 1)) + "_";
        else
            return type + "_";
    }
    else if (isUnoType(resolvedType))
    {
        // For interfaces and other types, return XInterface* pointer
        return "XInterface*"_ostr;
    }
    else
        return "void*"_ostr; // Default to void* for unknown types
}

OString CppProducer::getTypedParameterType(
    std::u16string_view unoType,
    unoidl::InterfaceTypeEntity::Method::Parameter::Direction direction)
{
    // Handle string types with typed parameters
    if (unoType == u"string")
    {
        bool isInputOnly
            = (direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN);
        if (isInputOnly)
        {
            // Input string: pass as rtl_uString* (no const to avoid casting)
            return "rtl_uString*"_ostr;
        }
        else
        {
            // Input/output string: pass as rtl_uString** (modifiable)
            return "rtl_uString**"_ostr;
        }
    }

    // Handle any types with typed parameters
    if (unoType == u"any")
    {
        bool isInputOnly
            = (direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN);
        if (isInputOnly)
        {
            // Input any: pass as uno_Any* (no const to avoid casting)
            return "uno_Any*"_ostr;
        }
        else
        {
            // Input/output any: pass as uno_Any** (modifiable)
            return "uno_Any**"_ostr;
        }
    }

    // Only use typed parameters for basic primitive types (not typedefs)
    // This ensures we don't break existing null-checking logic for complex types
    if (unoType == u"boolean" || unoType == u"byte" || unoType == u"short"
        || unoType == u"unsigned short" || unoType == u"long" || unoType == u"unsigned long"
        || unoType == u"hyper" || unoType == u"unsigned hyper" || unoType == u"float"
        || unoType == u"double")
    {
        OString primitiveType = mapUnoPrimitiveToSal(unoType);
        if (!primitiveType.isEmpty())
        {
            bool isInputOnly
                = (direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN);
            if (isInputOnly)
            {
                // Input parameters: pass by value (sal_Bool, sal_Int32, etc.)
                return primitiveType;
            }
            else
            {
                // Input/output parameters: pass by pointer (sal_Bool*, sal_Int32*, etc.)
                return primitiveType + "*";
            }
        }
    }

    // For all other types (typedefs, structs, enums, interfaces, sequences), use void*
    // This maintains compatibility with existing null-checking and casting logic
    return "void*"_ostr;
}

OString CppProducer::getStructGetterReturnType(std::u16string_view unoType)
{
    // Struct getters return a pointer to the member data (like output parameters)
    // Use the same logic as getTypedParameterType with direction = OUT

    // Handle string types
    if (unoType == u"string")
    {
        return "void*"_ostr; // Return pointer to string for compatibility
    }

    // Handle any types
    if (unoType == u"any")
    {
        return "uno_Any*"_ostr; // Return pointer to Any for direct access
    }

    // Handle primitive types
    if (unoType == u"boolean" || unoType == u"byte" || unoType == u"short"
        || unoType == u"unsigned short" || unoType == u"long" || unoType == u"unsigned long"
        || unoType == u"hyper" || unoType == u"unsigned hyper" || unoType == u"float"
        || unoType == u"double")
    {
        OString primitiveType = mapUnoPrimitiveToSal(unoType);
        if (!primitiveType.isEmpty())
        {
            return primitiveType + "*"; // Return pointer to primitive type
        }
    }

    // For all other types (typedefs, structs, enums, interfaces, sequences), use void*
    return "void*"_ostr;
}

OString CppProducer::getStructSetterParameterType(std::u16string_view unoType)
{
    // Struct setters take the value to set (like input parameters)
    // Use the same logic as getTypedParameterType with direction = IN

    // Handle string types
    if (unoType == u"string")
    {
        return "rtl_uString*"_ostr; // Take string pointer for compatibility
    }

    // Handle any types
    if (unoType == u"any")
    {
        return "uno_Any*"_ostr; // Take Any pointer directly
    }

    // Handle primitive types
    if (unoType == u"boolean" || unoType == u"byte" || unoType == u"short"
        || unoType == u"unsigned short" || unoType == u"long" || unoType == u"unsigned long"
        || unoType == u"hyper" || unoType == u"unsigned hyper" || unoType == u"float"
        || unoType == u"double")
    {
        OString primitiveType = mapUnoPrimitiveToSal(unoType);
        if (!primitiveType.isEmpty())
        {
            return primitiveType; // Take primitive type by value
        }
    }

    // For all other types
    return "void*"_ostr;
}

OString CppProducer::convertBasicType(const OString& typeName)
{
    OString result = typeName;

    // Convert UNO primitive types to C++ types
    if (result == "long")
        result = "sal_Int32"_ostr;
    else if (result == "short")
        result = "sal_Int16"_ostr;
    else if (result == "byte")
        result = "sal_Int8"_ostr;
    else if (result == "boolean")
        result = "sal_Bool"_ostr;
    else if (result == "double")
        result = "double"_ostr;
    else if (result == "float")
        result = "float"_ostr;
    else if (result == "string")
        result = "OUString"_ostr;
    else if (result == "any")
        result = "Any"_ostr;
    else if (result.indexOf('.') != -1)
    {
        // For UNO types with namespace, convert dots to double colons
        result = result.replaceAll("."_ostr, "::"_ostr);
    }

    return result;
}

// Type classification helper methods

bool CppProducer::isUnoType(std::u16string_view typeName) const
{
    // Check if this is a valid UNO type using TypeManager
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;

    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);

    // Return true for any valid UNO type (not just interfaces/structs/enums)
    return sort != codemaker::UnoType::Sort::Void && sort != codemaker::UnoType::Sort::Boolean
           && sort != codemaker::UnoType::Sort::Byte && sort != codemaker::UnoType::Sort::Short
           && sort != codemaker::UnoType::Sort::UnsignedShort
           && sort != codemaker::UnoType::Sort::Long
           && sort != codemaker::UnoType::Sort::UnsignedLong
           && sort != codemaker::UnoType::Sort::Hyper
           && sort != codemaker::UnoType::Sort::UnsignedHyper
           && sort != codemaker::UnoType::Sort::Float && sort != codemaker::UnoType::Sort::Double
           && sort != codemaker::UnoType::Sort::Char && sort != codemaker::UnoType::Sort::String
           && sort != codemaker::UnoType::Sort::Type && sort != codemaker::UnoType::Sort::Any;
}

bool CppProducer::isUnoStruct(std::u16string_view typeName) const
{
    // Check the type sort using TypeManager
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;

    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);

    // Return true if it's a plain struct or polymorphic struct template
    return (sort == codemaker::UnoType::Sort::PlainStruct);
}

bool CppProducer::isUnoEnum(std::u16string_view typeName) const
{
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;
    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);
    return sort == codemaker::UnoType::Sort::Enum;
}

bool CppProducer::isUnoPolymorphicStruct(std::u16string_view typeName) const
{
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;
    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);
    return sort == codemaker::UnoType::Sort::PolymorphicStructTemplate;
}

bool CppProducer::isUnoConstantGroup(std::u16string_view typeName) const
{
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;
    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);
    return sort == codemaker::UnoType::Sort::ConstantGroup;
}

bool CppProducer::isUnoInterface(std::u16string_view typeName) const
{
    rtl::Reference<unoidl::Entity> entity;
    rtl::Reference<unoidl::MapCursor> cursor;
    codemaker::UnoType::Sort sort = m_typeManager->getSort(OUString(typeName), &entity, &cursor);
    return sort == codemaker::UnoType::Sort::Interface;
}

OString CppProducer::convertUnoTypeToHandle(std::u16string_view unoType)
{
    // Convert UNO type name to typedef handle name
    // com.sun.star.lang.XMain -> com__sun__star__lang__XMainHandle
    OString functionPrefix = getCFunctionPrefix(std::string(unoType.begin(), unoType.end()));
    return functionPrefix + "Handle";
}

void CppProducer::generateServiceHeader(
    std::string_view name, const rtl::Reference<unoidl::SingleInterfaceBasedServiceEntity>& entity)
{
    if (m_dryRun || !m_combinedHeaderFile)
        return;

    CppFile& file = *m_combinedHeaderFile;
    file.openFileAppend();

    // Add pragma once for header guard
    file.beginLine().append("#pragma once").endLine().endLine();

    // Include the service's interface
    OUString interfaceType = entity->getBase();
    std::string includePath(u2b(interfaceType));
    std::replace(includePath.begin(), includePath.end(), '.', '/');
    file.beginLine().append("#include <").append(includePath).append(".hpp>").endLine();
    file.beginLine().append("#include <com/sun/star/uno/XComponentContext.hpp>").endLine();
    file.beginLine().append("#include <com/sun/star/uno/Reference.hxx>").endLine();
    file.endLine();

    // Generate extern "C" declarations for service creation
    OString functionPrefix = getCFunctionPrefix(name); // Use consistent double-underscore naming
    file.beginLine().append("extern \"C\"").endLine().beginBlock();
    file.beginLine().append("    // Service creation functions for ").append(name).endLine();
    file.beginLine()
        .append("    SAL_DLLPUBLIC_EXPORT void* ")
        .append(functionPrefix)
        .append("_create(void* context_handle);")
        .endLine();
    file.beginLine().append("}").endLine();

    file.closeFile();
}

void CppProducer::generateServiceSource(
    std::string_view name, const rtl::Reference<unoidl::SingleInterfaceBasedServiceEntity>& entity)
{
    if (m_dryRun || !m_combinedSourceFile)
        return;

    CppFile& file = *m_combinedSourceFile;
    file.openFileAppend();

    // Include the header
    std::string headerPath(name);
    std::replace(headerPath.begin(), headerPath.end(), '.', '/');
    file.beginLine().append("#include <com/sun/star/lang/XMultiComponentFactory.hpp>").endLine();
    file.beginLine().append("#include <sal/log.hxx>").endLine();
    file.endLine();

    // Services don't need namespace declarations - use fully qualified names instead

    // Generate service creation function
    OString functionPrefix = getCFunctionPrefix(name); // Use consistent double-underscore naming
    OUString interfaceType = entity->getBase();
    std::string interfaceCppType(u2b(interfaceType));
    std::replace(interfaceCppType.begin(), interfaceCppType.end(), '.', ':');
    // Fix single colons to double colons for C++ namespace syntax
    size_t colonPos = 0;
    while ((colonPos = interfaceCppType.find(":", colonPos)) != std::string::npos)
    {
        if (colonPos == 0 || interfaceCppType[colonPos - 1] != ':')
        {
            interfaceCppType.insert(colonPos, ":");
            colonPos += 2;
        }
        else
        {
            colonPos++;
        }
    }
    if (!interfaceCppType.empty() && interfaceCppType.substr(0, 2) != "::")
    {
        interfaceCppType = "::" + interfaceCppType;
    }

    file.beginLine().append("extern \"C\"").endLine().beginBlock();
    file.beginLine()
        .append("SAL_DLLPUBLIC_EXPORT void* ")
        .append(functionPrefix)
        .append("_create(void* context_handle)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("try")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("Reference<com::sun::star::uno::XComponentContext>* ctx = "
                "static_cast<Reference<com::sun::star::uno::XComponentContext>*>(context_handle);")
        .endLine()
        .beginLine()
        .append("if (!ctx || !ctx->is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("Reference<com::sun::star::lang::XMultiComponentFactory> factory = "
                "(*ctx)->getServiceManager();")
        .endLine()
        .beginLine()
        .append("if (!factory.is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("Reference<")
        .append("com::sun::star::uno::XInterface")
        .append("> service = Reference<")
        .append("com::sun::star::uno::XInterface")
        .append(">(")
        .endLine()
        .extraIndent()
        .beginLine()
        .append("factory->createInstanceWithContext(\"")
        .append(name)
        .append("\", *ctx), UNO_QUERY);")
        .endLine()
        .beginLine()
        .append("")
        .endLine()
        .beginLine()
        .append("if (!service.is()) return nullptr;")
        .endLine()
        .beginLine()
        .append("return new Reference<")
        .append("com::sun::star::uno::XInterface")
        .append(">(service);")
        .endLine()
        .endBlock()
        .beginLine()
        .append("catch (const Exception& ex)")
        .endLine()
        .beginBlock()
        .beginLine()
        .append("SAL_WARN(\"rustmaker\", \"Service creation failed for ")
        .append(name)
        .append(": \" << ex.Message);")
        .endLine()
        .beginLine()
        .append("return nullptr;")
        .endLine()
        .endBlock()
        .endBlock();
    file.beginLine().append("}").endLine();

    file.closeFile();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */