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

#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>

class GO:public Language {
  static const char *const usage;

  // Go package name.
  String *package;
  // SWIG module name.
  String *module;
  // Flag for generating gccgo output.
  bool gccgo_flag;
  // Prefix to use with gccgo.
  String *go_prefix;
  // -fgo-prefix option.
  String *prefix_option;
  // -fgo-pkgpath option.
  String *pkgpath_option;
  // Whether to use a shared library.
  bool use_shlib;
  // Name of shared library to import.
  String *soname;
  // Size in bits of the Go type "int".  0 if not specified.
  int intgo_type_size;

  /* Output files */
  File *f_c_begin;
  File *f_go_begin;
  File *f_gc_begin;

  /* Output fragments */
  File *f_c_runtime;
  File *f_c_header;
  File *f_c_wrappers;
  File *f_c_init;
  File *f_c_directors;
  File *f_c_directors_h;
  File *f_go_imports;
  File *f_go_runtime;
  File *f_go_header;
  File *f_go_wrappers;
  File *f_gc_runtime;
  File *f_gc_header;
  File *f_gc_wrappers;

  // True if we imported a module.
  bool saw_import;
  // If not NULL, name of import package being processed.
  String *imported_package;
  // Build interface methods while handling a class.  This is only
  // non-NULL when we are handling methods.
  String *interfaces;
  // The class node while handling a class.  This is only non-NULL
  // when we are handling methods.
  Node *class_node;
  // The class name while handling a class.  This is only non-NULL
  // when we are handling methods.  This is the name of the class as
  // SWIG sees it.
  String *class_name;
  // The receiver name while handling a class.  This is only non-NULL
  // when we are handling methods.  This is the name of the class
  // as run through goCPointerType.
  String *class_receiver;
  // A hash table of method names that we have seen when processing a
  // class.  This lets us detect base class methods that we don't want
  // to use.
  Hash *class_methods;
  // True when we are generating the wrapper functions for a variable.
  bool making_variable_wrappers;
  // True when working with a static member function.
  bool is_static_member_function;
  // A hash table of enum types that we have seen but which may not have
  // been defined.  The index is a SwigType.
  Hash *undefined_enum_types;
  // A hash table of types that we have seen but which may not have
  // been defined.  The index is a SwigType.
  Hash *undefined_types;
  // A hash table of classes which were defined.  The index is a Go
  // type name.
  Hash *defined_types;
  // A hash table of all the go_imports already imported. The index is a full
  // import name e.g. '"runtime"' or '_ "runtime/cgo"' or 'sc "syscall"'.
  Hash *go_imports;

public:
  GO():package(NULL),
     module(NULL),
     gccgo_flag(false),
     go_prefix(NULL),
     prefix_option(NULL),
     pkgpath_option(NULL),
     use_shlib(false),
     soname(NULL),
     intgo_type_size(0),
     f_c_begin(NULL),
     f_go_begin(NULL),
     f_gc_begin(NULL),
     f_c_runtime(NULL),
     f_c_header(NULL),
     f_c_wrappers(NULL),
     f_c_init(NULL),
     f_c_directors(NULL),
     f_c_directors_h(NULL),
     f_go_imports(NULL),
     f_go_runtime(NULL),
     f_go_header(NULL),
     f_go_wrappers(NULL),
     f_gc_runtime(NULL),
     f_gc_header(NULL),
     f_gc_wrappers(NULL),
     saw_import(false),
     imported_package(NULL),
     interfaces(NULL),
     class_node(NULL),
     class_name(NULL),
     class_receiver(NULL),
     class_methods(NULL),
     making_variable_wrappers(false),
     is_static_member_function(false),
     undefined_enum_types(NULL),
     undefined_types(NULL),
     defined_types(NULL),
     go_imports(NULL) {
    director_multiple_inheritance = 1;
    director_language = 1;
    director_prot_ctor_code = NewString("_swig_gopanic(\"accessing abstract class or protected constructor\");");
  }

private:
  /* ------------------------------------------------------------
   * main()
   * ------------------------------------------------------------ */
  virtual void main(int argc, char *argv[]) {

    SWIG_library_directory("go");
    bool display_help = false;

    // Process command line options.
    for (int i = 1; i < argc; i++) {
      if (argv[i]) {
	if (strcmp(argv[i], "-package") == 0) {
	  if (argv[i + 1]) {
	    package = NewString(argv[i + 1]);
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    i++;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-gccgo") == 0) {
	  Swig_mark_arg(i);
	  gccgo_flag = true;
	} else if (strcmp(argv[i], "-go-prefix") == 0) {
	  if (argv[i + 1]) {
	    prefix_option = NewString(argv[i + 1]);
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    i++;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-go-pkgpath") == 0) {
	  if (argv[i + 1]) {
	    pkgpath_option = NewString(argv[i + 1]);
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    i++;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-use-shlib") == 0) {
	  Swig_mark_arg(i);
	  use_shlib = true;
	} else if (strcmp(argv[i], "-soname") == 0) {
	  if (argv[i + 1]) {
	    soname = NewString(argv[i + 1]);
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    i++;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-longsize") == 0) {
	  // Ignore for backward compatibility.
	  if (argv[i + 1]) {
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    ++i;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-intgosize") == 0) {
	  if (argv[i + 1]) {
	    intgo_type_size = atoi(argv[i + 1]);
	    if (intgo_type_size != 32 && intgo_type_size != 64) {
	      Printf(stderr, "-intgosize not 32 or 64\n");
	      Swig_arg_error();
	    }
	    Swig_mark_arg(i);
	    Swig_mark_arg(i + 1);
	    ++i;
	  } else {
	    Swig_arg_error();
	  }
	} else if (strcmp(argv[i], "-help") == 0) {
	  display_help = true;
	  Printf(stdout, "%s\n", usage);
	}
      }
    }

    if (gccgo_flag && !pkgpath_option && !prefix_option) {
      prefix_option = NewString("go");
    }

    // Add preprocessor symbol to parser.
    Preprocessor_define("SWIGGO 1", 0);

    if (gccgo_flag) {
      Preprocessor_define("SWIGGO_GCCGO 1", 0);
    }

    // This test may be removed in the future, when we can assume that
    // everybody has upgraded to Go 1.1.  The code below is prepared
    // for this test to simply be taken out.
    if (intgo_type_size == 0 && !display_help) {
      Printf(stderr, "SWIG -go: -intgosize option required but not specified\n");
      SWIG_exit(EXIT_FAILURE);
    }

    if (intgo_type_size == 32) {
      Preprocessor_define("SWIGGO_INTGO_SIZE 32", 0);
    } else if (intgo_type_size == 64) {
      Preprocessor_define("SWIGGO_INTGO_SIZE 64", 0);
    } else {
      Preprocessor_define("SWIGGO_INTGO_SIZE 0", 0);
    }

    // Add typemap definitions.
    SWIG_typemap_lang("go");
    SWIG_config_file("go.swg");

    allow_overloading();
  }

  /* ---------------------------------------------------------------------
   * top()
   *
   * For 6g/8g, we are going to create the following files:
   *
   * 1) A .c or .cxx file compiled with gcc.  This file will contain
   *    function wrappers.  Each wrapper will take a pointer to a
   *    struct holding the arguments, unpack them, and call the real
   *    function.
   *
   * 2) A .go file which defines the Go form of all types, and which
   *    defines Go function wrappers.  Each wrapper will call the C
   *    function wrapper in the second file.
   *
   * 3) A .c file compiled with 6c/8c.  This file will define
   *    Go-callable C function wrappers.  Each wrapper will use
   *    cgocall to call the function wrappers in the first file.
   *
   * When generating code for gccgo, we don't need the third file, and
   * the function wrappers in the first file have a different form.
   *
   * --------------------------------------------------------------------- */

  virtual int top(Node *n) {
    Node *optionsnode = Getattr(Getattr(n, "module"), "options");
    if (optionsnode) {
      if (Getattr(optionsnode, "directors")) {
	allow_directors();
      }
      if (Getattr(optionsnode, "dirprot")) {
	allow_dirprot();
      }
      allow_allprotected(GetFlag(optionsnode, "allprotected"));
    }

    module = Getattr(n, "name");
    if (!package) {
      package = Copy(module);
    }
    if (!soname && use_shlib) {
      soname = Copy(package);
      Append(soname, ".so");
    }

    if (gccgo_flag) {
      String *pref;
      if (pkgpath_option) {
	pref = pkgpath_option;
      } else {
	pref = prefix_option;
      }
      go_prefix = NewString("");
      for (char *p = Char(pref); *p != '\0'; p++) {
	if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') || (*p >= '0' && *p <= '9') || *p == '.' || *p == '$') {
	  Putc(*p, go_prefix);
	} else {
	  Putc('_', go_prefix);
	}
      }
      if (!pkgpath_option) {
	Append(go_prefix, ".");
	Append(go_prefix, package);
      }
    }

    // Get filenames.

    String *swig_filename = Getattr(n, "infile");
    String *c_filename = Getattr(n, "outfile");
    String *c_filename_h = Getattr(n, "outfile_h");

    String *go_filename = NewString("");
    Printf(go_filename, "%s%s.go", SWIG_output_directory(), module);

    String *gc_filename = NULL;
    if (!gccgo_flag) {
      gc_filename = NewString("");
      Printf(gc_filename, "%s%s_gc.c", SWIG_output_directory(), module);
    }

    // Open files.

    f_c_begin = NewFile(c_filename, "w", SWIG_output_files());
    if (!f_c_begin) {
      FileErrorDisplay(c_filename);
      SWIG_exit(EXIT_FAILURE);
    }

    if (directorsEnabled()) {
      if (!c_filename_h) {
	Printf(stderr, "Unable to determine outfile_h\n");
	SWIG_exit(EXIT_FAILURE);
      }
      f_c_directors_h = NewFile(c_filename_h, "w", SWIG_output_files());
      if (!f_c_directors_h) {
	FileErrorDisplay(c_filename_h);
	SWIG_exit(EXIT_FAILURE);
      }
    }

    f_go_begin = NewFile(go_filename, "w", SWIG_output_files());
    if (!f_go_begin) {
      FileErrorDisplay(go_filename);
      SWIG_exit(EXIT_FAILURE);
    }

    if (!gccgo_flag) {
      f_gc_begin = NewFile(gc_filename, "w", SWIG_output_files());
      if (!f_gc_begin) {
	FileErrorDisplay(gc_filename);
	SWIG_exit(EXIT_FAILURE);
      }
    }

    f_c_runtime = NewString("");
    f_c_header = NewString("");
    f_c_wrappers = NewString("");
    f_c_init = NewString("");
    f_c_directors = NewString("");
    f_go_imports = NewString("");
    f_go_runtime = NewString("");
    f_go_header = NewString("");
    f_go_wrappers = NewString("");
    if (!gccgo_flag) {
      f_gc_runtime = NewString("");
      f_gc_header = NewString("");
      f_gc_wrappers = NewString("");
    }

    Swig_register_filebyname("begin", f_c_begin);
    Swig_register_filebyname("runtime", f_c_runtime);
    Swig_register_filebyname("header", f_c_header);
    Swig_register_filebyname("wrapper", f_c_wrappers);
    Swig_register_filebyname("init", f_c_init);
    Swig_register_filebyname("director", f_c_directors);
    Swig_register_filebyname("director_h", f_c_directors_h);
    Swig_register_filebyname("go_begin", f_go_begin);
    Swig_register_filebyname("go_imports", f_go_imports);
    Swig_register_filebyname("go_runtime", f_go_runtime);
    Swig_register_filebyname("go_header", f_go_header);
    Swig_register_filebyname("go_wrapper", f_go_wrappers);
    if (!gccgo_flag) {
      Swig_register_filebyname("gc_begin", f_gc_begin);
      Swig_register_filebyname("gc_runtime", f_gc_runtime);
      Swig_register_filebyname("gc_header", f_gc_header);
      Swig_register_filebyname("gc_wrapper", f_gc_wrappers);
    }

    Swig_banner(f_c_begin);
    if (CPlusPlus) {
      Printf(f_c_begin, "\n// source: %s\n\n", swig_filename);
    } else {
      Printf(f_c_begin, "\n/* source: %s */\n\n", swig_filename);
    }

    Printf(f_c_runtime, "#define SWIGMODULE %s\n", module);
    if (gccgo_flag) {
      Printf(f_c_runtime, "#define SWIGGO_PREFIX %s\n", go_prefix);
    }

    if (directorsEnabled()) {
      Printf(f_c_runtime, "#define SWIG_DIRECTORS\n");

      Swig_banner(f_c_directors_h);
      Printf(f_c_directors_h, "\n// source: %s\n\n", swig_filename);

      Printf(f_c_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module);
      Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module);

      Printf(f_c_directors, "\n// C++ director class methods.\n");
      String *filename = Swig_file_filename(c_filename_h);
      Printf(f_c_directors, "#include \"%s\"\n\n", filename);
      Delete(filename);
    }

    Swig_banner(f_go_begin);
    Printf(f_go_begin, "\n// source: %s\n", swig_filename);

    if (!gccgo_flag && soname) {
      Swig_banner(f_gc_begin);
      Printf(f_gc_begin, "\n/* source: %s */\n\n", swig_filename);
      Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c.  */\n");
      Printf(f_gc_begin, "#pragma dynimport _ _ \"%s\"\n", soname);
    }

    // Output module initialization code.

    Printf(f_go_begin, "\npackage %s\n\n", package);

    if (gccgo_flag) {
      Printf(f_go_runtime, "func SwigCgocall()\n");
      Printf(f_go_runtime, "func SwigCgocallDone()\n");
      Printf(f_go_runtime, "func SwigCgocallBack()\n");
      Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n");
    }

    // All the C++ wrappers should be extern "C".

    Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL);

    // Set up the hash table for types not defined by SWIG.

    undefined_enum_types = NewHash();
    undefined_types = NewHash();
    defined_types = NewHash();
    go_imports = NewHash();

    // Emit code.

    Language::top(n);

    Delete(go_imports);

    // Write out definitions for the types not defined by SWIG.

    if (Len(undefined_enum_types) > 0)
      Printv(f_go_wrappers, "\n", NULL);
    for (Iterator p = First(undefined_enum_types); p.key; p = Next(p)) {
      String *name = p.item;
      Printv(f_go_wrappers, "type ", name, " int\n", NULL);
    }

    Printv(f_go_wrappers, "\n", NULL);
    for (Iterator p = First(undefined_types); p.key; p = Next(p)) {
      String *ty = goType(NULL, p.key);
      if (!Getattr(defined_types, ty)) {
	String *cp = goCPointerType(p.key, false);
	if (!Getattr(defined_types, cp)) {
	  Printv(f_go_wrappers, "type ", cp, " uintptr\n", NULL);
	  Printv(f_go_wrappers, "type ", ty, " interface {\n", NULL);
	  Printv(f_go_wrappers, "\tSwigcptr() uintptr;\n", NULL);
	  Printv(f_go_wrappers, "}\n", NULL);
	  Printv(f_go_wrappers, "func (p ", cp, ") Swigcptr() uintptr {\n", NULL);
	  Printv(f_go_wrappers, "\treturn uintptr(p)\n", NULL);
	  Printv(f_go_wrappers, "}\n\n", NULL);
	}
	Delete(cp);
      }
      Delete(ty);
    }
    Delete(undefined_enum_types);
    Delete(undefined_types);
    Delete(defined_types);

    /* Write and cleanup */

    Dump(f_c_header, f_c_runtime);

    if (directorsEnabled()) {
      Printf(f_c_directors_h, "#endif\n");
      Delete(f_c_directors_h);
      f_c_directors_h = NULL;

      Dump(f_c_directors, f_c_runtime);
      Delete(f_c_directors);
      f_c_directors = NULL;
    }

    // End the extern "C".
    Printv(f_c_wrappers, "#ifdef __cplusplus\n", "}\n", "#endif\n\n", NULL);

    Dump(f_c_runtime, f_c_begin);
    Dump(f_c_wrappers, f_c_begin);
    Dump(f_c_init, f_c_begin);
    Dump(f_go_imports, f_go_begin);
    Dump(f_go_header, f_go_begin);
    Dump(f_go_runtime, f_go_begin);
    Dump(f_go_wrappers, f_go_begin);
    if (!gccgo_flag) {
      Dump(f_gc_header, f_gc_begin);
      Dump(f_gc_runtime, f_gc_begin);
      Dump(f_gc_wrappers, f_gc_begin);
    }

    Delete(f_c_runtime);
    Delete(f_c_header);
    Delete(f_c_wrappers);
    Delete(f_c_init);
    Delete(f_go_imports);
    Delete(f_go_runtime);
    Delete(f_go_header);
    Delete(f_go_wrappers);
    if (!gccgo_flag) {
      Delete(f_gc_runtime);
      Delete(f_gc_header);
      Delete(f_gc_wrappers);
    }

    Delete(f_c_begin);
    Delete(f_go_begin);
    if (!gccgo_flag) {
      Delete(f_gc_begin);
    }

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * importDirective()
   *
   * Handle a SWIG import statement by generating a Go import
   * statement.
   * ------------------------------------------------------------ */

  virtual int importDirective(Node *n) {
    String *hold_import = imported_package;
    String *modname = Getattr(n, "module");
    if (modname) {
      if (!Getattr(go_imports, modname)) {
        Setattr(go_imports, modname, modname);
        Printv(f_go_imports, "import \"", modname, "\"\n", NULL);
      }
      imported_package = modname;
      saw_import = true;
    }
    int r = Language::importDirective(n);
    imported_package = hold_import;
    return r;
  }

  /* ----------------------------------------------------------------------
   * Language::insertDirective()
   *
   * If the section is go_imports, store them for later.
   * ---------------------------------------------------------------------- */
  virtual int insertDirective(Node *n) {
    char *section = Char(Getattr(n, "section"));
    if ((ImportMode && !Getattr(n, "generated")) ||
        !section || (strcmp(section, "go_imports") != 0)) {
      return Language::insertDirective(n);
    }

    char *code = Char(Getattr(n, "code"));
    char *pch = strtok(code, ",");
    while (pch != NULL) {
      // Do not import same thing more than once.
      if (!Getattr(go_imports, pch)) {
        Setattr(go_imports, pch, pch);
        Printv(f_go_imports, "import ", pch, "\n", NULL);
      }
      pch = strtok(NULL, ",");
    }
    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * functionWrapper()
   *
   * Implement a function.
   * ---------------------------------------------------------------------- */

  virtual int functionWrapper(Node *n) {
    if (GetFlag(n, "feature:ignore")) {
      return SWIG_OK;
    }

    // We don't need explicit calls.
    if (GetFlag(n, "explicitcall")) {
      return SWIG_OK;
    }

    String *name = Getattr(n, "sym:name");
    String *nodetype = Getattr(n, "nodeType");
    bool is_static = is_static_member_function || isStatic(n);
    bool is_friend = isFriend(n);
    bool is_ctor_dtor = false;

    SwigType *result = Getattr(n, "type");

    // For some reason SWIG changs the "type" value during the call to
    // functionWrapper.  We need to remember the type for possible
    // overload processing.
    Setattr(n, "go:type", Copy(result));

    String *go_name;

    String *r1 = NULL;
    if (making_variable_wrappers) {
      // Change the name of the variable setter and getter functions
      // to be more Go like.

      bool is_set = Strcmp(Char(name) + Len(name) - 4, "_set") == 0;
      assert(is_set || Strcmp(Char(name) + Len(name) - 4, "_get") == 0);

      // Start with Set or Get.
      go_name = NewString(is_set ? "Set" : "Get");

      // If this is a static variable, put in the class name,
      // capitalized.
      if (is_static && class_name) {
	String *ccn = exportedName(class_name);
	Append(go_name, ccn);
	Delete(ccn);
      }

      // Add the rest of the name, capitalized, dropping the _set or
      // _get.
      String *c1 = removeClassname(name);
      String *c2 = exportedName(c1);
      char *p = Char(c2);
      int len = Len(p);
      for (int i = 0; i < len - 4; ++i) {
	Putc(p[i], go_name);
      }
      Delete(c2);
      Delete(c1);

      if (!checkIgnoredParameters(n, go_name)) {
	Delete(go_name);
	return SWIG_NOWRAP;
      }
    } else if (Cmp(nodetype, "constructor") == 0) {
      is_ctor_dtor = true;

      // Change the name of a constructor to be more Go like.  Change
      // new_ to New, and capitalize the class name.
      assert(Strncmp(name, "new_", 4) == 0);
      String *c1 = NewString(Char(name) + 4);
      String *c2 = exportedName(c1);
      go_name = NewString("New");
      Append(go_name, c2);
      Delete(c2);
      Delete(c1);

      if (Swig_methodclass(n) && Swig_directorclass(n)
	  && Strcmp(Char(Getattr(n, "wrap:action")), director_prot_ctor_code) != 0) {
	// The core SWIG code skips the first parameter when
	// generating the $nondirector_new string.  Recreate the
	// action in this case.  But don't it if we are using the
	// special code for an abstract class.
	String *call = Swig_cppconstructor_call(getClassType(),
						Getattr(n, "parms"));
	SwigType *type = Copy(getClassType());
	SwigType_add_pointer(type);
	String *cres = Swig_cresult(type, Swig_cresult_name(), call);
	Setattr(n, "wrap:action", cres);
      }
    } else if (Cmp(nodetype, "destructor") == 0) {
      // No need to emit protected destructors.
      if (!is_public(n)) {
	return SWIG_OK;
      }

      is_ctor_dtor = true;

      // Change the name of a destructor to be more Go like.  Change
      // delete_ to Delete and capitalize the class name.
      assert(Strncmp(name, "delete_", 7) == 0);
      String *c1 = NewString(Char(name) + 7);
      String *c2 = exportedName(c1);
      go_name = NewString("Delete");
      Append(go_name, c2);
      Delete(c2);
      Delete(c1);

      result = NewString("void");
      r1 = result;
    } else {
      if (!checkFunctionVisibility(n, NULL)) {
	return SWIG_OK;
      }

      go_name = buildGoName(name, is_static, is_friend);

      if (!checkIgnoredParameters(n, go_name)) {
	Delete(go_name);
	return SWIG_NOWRAP;
      }
    }

    String *overname = NULL;
    if (Getattr(n, "sym:overloaded")) {
      overname = Getattr(n, "sym:overname");
    } else {
      String *scope;
      if (!class_name || is_static || is_ctor_dtor) {
	scope = NULL;
      } else {
	scope = NewString("swiggoscope.");
	Append(scope, class_name);
      }
      if (!checkNameConflict(go_name, n, scope)) {
	Delete(go_name);
	return SWIG_NOWRAP;
      }
    }

    String *wname = Swig_name_wrapper(name);
    if (overname) {
      Append(wname, overname);
    }
    Setattr(n, "wrap:name", wname);

    ParmList *parms = Getattr(n, "parms");
    Setattr(n, "wrap:parms", parms);

    int r = makeWrappers(n, name, go_name, overname, wname, NULL, parms, result, is_static);
    if (r != SWIG_OK) {
      return r;
    }

    if (Getattr(n, "sym:overloaded") && !Getattr(n, "sym:nextSibling")) {
      String *scope ;
      if (!class_name || is_static || is_ctor_dtor) {
	scope = NULL;
      } else {
	scope = NewString("swiggoscope.");
	Append(scope, class_name);
      }
      if (!checkNameConflict(go_name, n, scope)) {
	Delete(go_name);
	return SWIG_NOWRAP;
      }

      String *receiver = class_receiver;
      if (is_static || is_ctor_dtor) {
	receiver = NULL;
      }
      r = makeDispatchFunction(n, go_name, receiver, is_static, NULL, false);
      if (r != SWIG_OK) {
	return r;
      }
    }

    Delete(wname);
    Delete(go_name);
    Delete(r1);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * staticmemberfunctionHandler()
   *
   * For some reason the language code removes the "storage" attribute
   * for a static function before calling functionWrapper, which means
   * that we have no way of knowing whether a function is static or
   * not.  That makes no sense in the Go context.  Here we note that a
   * function is static.
   * ---------------------------------------------------------------------- */

  int staticmemberfunctionHandler(Node *n) {
    assert(!is_static_member_function);
    is_static_member_function = true;
    int r = Language::staticmemberfunctionHandler(n);
    is_static_member_function = false;
    return r;
  }

  /* ----------------------------------------------------------------------
   * makeWrappers()
   *
   * Write out the various function wrappers.
   * n: The function we are emitting.
   * name: The function name.
   * go_name: The name of the function in Go.
   * overname: The overload string for overloaded function.
   * wname: The SWIG wrapped name--the name of the C function.
   * base: A list of the names of base classes, in the case where this
   *       is is a vritual method not defined in the current class.
   * parms: The parameters.
   * result: The result type.
   * is_static: Whether this is a static method or member.
   * ---------------------------------------------------------------------- */

  int makeWrappers(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) {

    assert(result);

    bool needs_wrapper;
    int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static, &needs_wrapper);
    if (r != SWIG_OK) {
      return r;
    }

    if (!gccgo_flag) {
      r = gcFunctionWrapper(n, name, go_name, overname, wname, parms, result, is_static, needs_wrapper);
      if (r != SWIG_OK) {
	return r;
      }
      r = gccFunctionWrapper(n, base, wname, parms, result);
      if (r != SWIG_OK) {
	return r;
      }
    } else {
      r = gccgoFunctionWrapper(n, base, wname, parms, result);
      if (r != SWIG_OK) {
	return r;
      }
    }

    if (class_methods) {
      Setattr(class_methods, Getattr(n, "name"), NewString(""));
    }

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * goFunctionWrapper()
   *
   * Write out a function wrapper in Go.  When not implementing a
   * method, the actual code is all in C; here we just declare the C
   * function.  When implementing a method, we have to call the C
   * function, because it will have a different name.  If base is not
   * NULL, then we are being called to forward a virtual method to a
   * base class.
   * ---------------------------------------------------------------------- */

  int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static, bool *p_needs_wrapper) {
    Wrapper *dummy = NewWrapper();
    emit_attach_parmmaps(parms, dummy);
    Swig_typemap_attach_parms("default", parms, dummy);
    Swig_typemap_attach_parms("gotype", parms, dummy);
    int parm_count = emit_num_arguments(parms);
    int required_count = emit_num_required(parms);

    String *receiver = class_receiver;
    if (receiver && is_static) {
      receiver = NULL;
    }

    String *nodetype = Getattr(n, "nodeType");
    bool is_constructor = Cmp(nodetype, "constructor") == 0;
    bool is_destructor = Cmp(nodetype, "destructor") == 0;
    if (is_constructor || is_destructor) {
      assert(class_receiver);
      assert(!base);
      receiver = NULL;
    }

    bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && checkFunctionVisibility(n, NULL));

    bool needs_wrapper = (gccgo_flag || receiver || is_constructor || is_destructor || parm_count > required_count);

    // See whether any of the function parameters are represented by
    // interface values When calling the C++ code, we need to convert
    // back to a uintptr.
    if (!needs_wrapper) {
      Parm *p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	String *ty = Getattr(p, "type");
	if (goTypeIsInterface(p, ty)) {
	  needs_wrapper = true;
	  break;
	}
	p = nextParm(p);
      }
    }
    if (goTypeIsInterface(n, result)) {
      needs_wrapper = true;
    }

    *p_needs_wrapper = needs_wrapper;

    // If this is a method, first declare the C function we will call.
    // If we do not need a wrapper, then we will only be writing a
    // declaration.
    String *wrapper_name = NULL;
    if (needs_wrapper) {
      wrapper_name = buildGoWrapperName(name, overname);

      if (gccgo_flag) {
	Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
      }

      Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL);
      if (parm_count > required_count) {
	Printv(f_go_wrappers, "int", NULL);
      }
      Parm *p = getParm(parms);
      Swig_cparm_name(p, 0);
      int i = 0;
      if (is_destructor) {
	if (parm_count > required_count) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, "uintptr", NULL);
	++i;
	p = nextParm(p);
      } else if (receiver && (base || !is_constructor)) {
	if (parm_count > required_count) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, receiver, NULL);
	if (!base) {
	  ++i;
	  p = nextParm(p);
	}
      }
      for (; i < parm_count; ++i) {
	p = getParm(p);
	// Give the parameter a name we will use below.
	Swig_cparm_name(p, i);
	if (i > 0 || (base && receiver) || parm_count > required_count) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	String *tm = goWrapperType(p, Getattr(p, "type"), false);
	Printv(f_go_wrappers, tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }
      Printv(f_go_wrappers, ")", NULL);
      if (is_constructor) {
	Printv(f_go_wrappers, " ", class_receiver, NULL);
      } else {
	if (SwigType_type(result) != T_VOID) {
	  String *tm = goWrapperType(n, result, true);
	  Printv(f_go_wrappers, " ", tm, NULL);
	  Delete(tm);
	}
      }

      Printv(f_go_wrappers, "\n\n", NULL);
    }

    // Start defining the Go function.

    if (!needs_wrapper && gccgo_flag) {
      Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
    }

    Printv(f_go_wrappers, "func ", NULL);

    Parm *p = parms;
    int pi = 0;

    // Add the receiver if this is a method.
    if (receiver) {
      Printv(f_go_wrappers, "(", NULL);
      if (base && receiver) {
	Printv(f_go_wrappers, "_swig_base", NULL);
      } else {
	Printv(f_go_wrappers, Getattr(p, "lname"), NULL);
	p = nextParm(p);
	++pi;
      }
      Printv(f_go_wrappers, " ", receiver, ") ", NULL);
    }

    Printv(f_go_wrappers, go_name, NULL);
    if (overname) {
      Printv(f_go_wrappers, overname, NULL);
    }
    Printv(f_go_wrappers, "(", NULL);

    // If we are doing methods, add this function to the interface.
    if (add_to_interface) {
      Printv(interfaces, "\t", go_name, "(", NULL);
    }

    // Write out the parameters to both the function definition and
    // the interface.

    String *parm_print = NewString("");

    for (; pi < parm_count; ++pi) {
      p = getParm(p);
      if (pi == 0 && is_destructor) {
	String *cl = exportedName(class_name);
	Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL);
	Delete(cl);
      } else {
	if (pi > (receiver && !base ? 1 : 0)) {
	  Printv(parm_print, ", ", NULL);
	}
	if (pi >= required_count) {
	  Printv(parm_print, "_swig_args ...interface{}", NULL);
	  break;
	}
	if (needs_wrapper) {
	  Printv(parm_print, Getattr(p, "lname"), " ", NULL);
	}
	String *tm = goType(p, Getattr(p, "type"));
	Printv(parm_print, tm, NULL);
	Delete(tm);
      }
      p = nextParm(p);
    }

    Printv(parm_print, ")", NULL);

    // Write out the result type.
    if (is_constructor) {
      String *cl = exportedName(class_name);
      Printv(parm_print, " ", cl, NULL);
      Delete(cl);
    } else {
      if (SwigType_type(result) != T_VOID) {
	String *tm = goType(n, result);
	Printv(parm_print, " ", tm, NULL);
	Delete(tm);
      }
    }

    Printv(f_go_wrappers, parm_print, NULL);
    if (add_to_interface) {
      Printv(interfaces, parm_print, "\n", NULL);
    }

    // If this is a wrapper, we need to actually call the C function.
    if (needs_wrapper) {
      Printv(f_go_wrappers, " {\n", NULL);

      if (parm_count > required_count) {
	Parm *p = parms;
	int i;
	for (i = 0; i < required_count; ++i) {
	  p = getParm(p);
	  p = nextParm(p);
	}
	for (; i < parm_count; ++i) {
	  p = getParm(p);
	  String *tm = goType(p, Getattr(p, "type"));
	  Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", NULL);
	  Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", i - required_count);
	  Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", Getattr(p, "lname"), i - required_count, tm);
	  Printv(f_go_wrappers, "\t}\n", NULL);
	  Delete(tm);
	  p = nextParm(p);
	}
      }

      if (gccgo_flag) {
	if (!is_constructor) {
	  Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
	  Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
	} else {
	  // For a constructor the wrapper function will return a
	  // uintptr but we will return an interface.  We want to
	  // convert the uintptr to the interface after calling
	  // SwigCgocallDone, so that we don't try to allocate memory
	  // while the Go scheduler can't see us.
	  Printv(f_go_wrappers, "\tvar done bool\n", NULL);
	  Printv(f_go_wrappers, "\tdefer func() {\n", NULL);
	  Printv(f_go_wrappers, "\t\tif !done {\n", NULL);
	  Printv(f_go_wrappers, "\t\t\tSwigCgocallDone()\n", NULL);
	  Printv(f_go_wrappers, "\t\t}\n", NULL);
	  Printv(f_go_wrappers, "\t}()\n", NULL);
	  Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
	}
      }

      Printv(f_go_wrappers, "\t", NULL);
      if (SwigType_type(result) != T_VOID) {
	if (gccgo_flag && is_constructor) {
	  Printv(f_go_wrappers, "swig_r := ", NULL);
	} else {
	  Printv(f_go_wrappers, "return ", NULL);
	}
      }

      Printv(f_go_wrappers, wrapper_name, "(", NULL);

      if (parm_count > required_count) {
	Printv(f_go_wrappers, "len(_swig_args)", NULL);
      }

      if (base && receiver) {
	if (parm_count > required_count) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, "_swig_base", NULL);
      }

      Parm *p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	if (i > 0 || (base && receiver)
	    || parm_count > required_count) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, Getattr(p, "lname"), NULL);

	// If this is a destructor, then the C function expects the
	// C++ value, and we have the interface.  We need to get the
	// C++ value.  The same is true for a type represented as an
	// interface.
	if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, Getattr(p, "type")))) {
	  Printv(f_go_wrappers, ".Swigcptr()", NULL);
	}

	p = nextParm(p);
      }
      Printv(f_go_wrappers, ")\n", NULL);

      if (gccgo_flag && is_constructor) {
	Printv(f_go_wrappers, "\tSwigCgocallDone()\n", NULL);
	Printv(f_go_wrappers, "\tdone = true\n", NULL);
	Printv(f_go_wrappers, "\treturn swig_r\n", NULL);
      }

      Printv(f_go_wrappers, "}\n", NULL);
    }

    Printv(f_go_wrappers, "\n", NULL);

    Delete(wrapper_name);
    DelWrapper(dummy);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * gcFunctionWrapper()
   *
   * This is used for 6g/8g, not for gccgo.  Write out the function
   * wrapper which will be compiled with 6c/8c.
   * ---------------------------------------------------------------------- */

  int gcFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, ParmList *parms, SwigType *result, bool is_static, bool needs_wrapper) {
    Wrapper *f = NewWrapper();

    Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"\"\n", NULL);
    Printv(f->def, "#pragma cgo_import_static ", wname, "\n", NULL);
    Printv(f->def, "extern void (*", wname, ")(void*);\n", NULL);
    Printv(f->def, "static void (*x", wname, ")(void*) = ", wname, ";\n", NULL);
    Printv(f->def, "\n", NULL);
    Printv(f->def, "void\n", NULL);

    Wrapper *dummy = NewWrapper();
    emit_attach_parmmaps(parms, dummy);
    Swig_typemap_attach_parms("default", parms, dummy);
    Swig_typemap_attach_parms("gosize", parms, dummy);
    int parm_count = emit_num_arguments(parms);
    int required_count = emit_num_required(parms);

    String *parm_size = NewString("");

    if (parm_count > required_count) {
      Append(parm_size, "SWIG_PARM_SIZE");
    }

    if (class_receiver && !is_static) {
      if (Len(parm_size) > 0) {
	Append(parm_size, " + ");
      }
      Append(parm_size, "SWIG_PARM_SIZE");
    }

    Parm *p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);
      addGcTypeSize(p, Getattr(p, "type"), parm_size);
      p = nextParm(p);
    }

    if (SwigType_type(result) != T_VOID) {
      addGcTypeSize(n, result, parm_size);
    }

    if (Len(parm_size) == 0) {
      Append(parm_size, "1");
    }

    String *fn_name;
    if (!needs_wrapper) {
      fn_name = Copy(go_name);
      if (overname) {
	Append(fn_name, overname);
      }
    } else {
      fn_name = buildGoWrapperName(name, overname);
    }

    // \xc2\xb7 is UTF-8 for U+00B7 which is Unicode 'Middle Dot'
    Printv(f->def, "\xc2\xb7", fn_name, "(struct { uint8 x[", parm_size, "];} p)", NULL);

    Delete(fn_name);
    Delete(parm_size);

    Printv(f->code, "{\n", NULL);
    Printv(f->code, "\truntime\xc2\xb7" "cgocall(x", wname, ", &p);\n", NULL);
    Printv(f->code, "}\n", NULL);
    Printv(f->code, "\n", NULL);

    Wrapper_print(f, f_gc_wrappers);

    DelWrapper(f);
    DelWrapper(dummy);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * getGcTypeSize()
   *
   * Return the size to use when passing a type from 6g/8g to 6c/8c.
   * ---------------------------------------------------------------------- */

  String *addGcTypeSize(Node *n, SwigType *type, String *orig) {
    if (Len(orig) > 0) {
      Append(orig, " + ");
    }

    String *go = goType(n, type);
    if (Cmp(go, "string") == 0) {
      // A string has a pointer and a length.
      Append(orig, "(2 * SWIG_PARM_SIZE)");
    } else if (Strncmp(go, "[]", 2) == 0) {
      // A slice has a pointer, a length, and a capacity.
      Append(orig, "(3 * SWIG_PARM_SIZE)");
    } else if (Strcmp(go, "float64") == 0) {
      Append(orig, "8");
    } else if (Strcmp(go, "complex64") == 0) {
      Append(orig, "8");
    } else if (Strcmp(go, "complex128") == 0) {
      Append(orig, "16");
    } else {
      Append(orig, "SWIG_PARM_SIZE");
    }

    return orig;
  }

  /* ----------------------------------------------------------------------
   * gccFunctionWrapper()
   *
   * This is used for 6g/8g, not for gccgo.  Write out the function
   * wrapper which will be compiled with gcc.  If the base parameter
   * is not NULL, this is calls the base class method rather than
   * executing the SWIG wrapper code.
   * ---------------------------------------------------------------------- */

  int gccFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) {
    Wrapper *f = NewWrapper();

    Swig_save("gccFunctionWrapper", n, "parms", NULL);

    Parm *base_parm = NULL;
    if (base && !isStatic(n)) {
      SwigType *base_type = Copy(getClassType());
      SwigType_add_pointer(base_type);
      base_parm = NewParm(base_type, NewString("arg1"), n);
      set_nextSibling(base_parm, parms);
      parms = base_parm;
    }

    emit_parameter_variables(parms, f);
    emit_attach_parmmaps(parms, f);
    int parm_count = emit_num_arguments(parms);
    int required_count = emit_num_required(parms);

    emit_return_variable(n, result, f);

    // Start the function definition.

    Printv(f->def, "void\n", wname, "(void *swig_v)\n", "{\n", NULL);

    // The single function parameter is a pointer to the real argument
    // values.  Define the structure that it points to.

    Printv(f->code, "\tstruct swigargs {\n", NULL);

    if (parm_count > required_count) {
      Printv(f->code, "\t\tintgo _swig_optargc;\n", NULL);
    }

    Parm *p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);
      String *ln = Getattr(p, "lname");
      SwigType *pt = Getattr(p, "type");
      String *ct = gcCTypeForGoValue(p, pt, ln);
      Printv(f->code, "\t\t\t", ct, ";\n", NULL);
      Delete(ct);
      p = nextParm(p);
    }
    if (SwigType_type(result) != T_VOID) {
      Printv(f->code, "\t\tlong : 0;\n", NULL);
      String *ln = NewString(Swig_cresult_name());
      String *ct = gcCTypeForGoValue(n, result, ln);
      Delete(ln);
      Printv(f->code, "\t\t", ct, ";\n", NULL);
      Delete(ct);
    }
    Printv(f->code, "\t} *swig_a = (struct swigargs *) swig_v;\n", NULL);

    Printv(f->code, "\n", NULL);

    // Copy the input arguments out of the structure into the
    // parameter variables.

    p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);

      String *tm = Getattr(p, "tmap:in");
      if (!tm) {
	Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0));
      } else {
	String *ln = Getattr(p, "lname");
	String *input = NewString("");
	Printv(input, "swig_a->", ln, NULL);
	Replaceall(tm, "$input", input);
	Setattr(p, "emit:input", input);
	if (i < required_count) {
	  Printv(f->code, "\t", tm, "\n", NULL);
	} else {
	  Printf(f->code, "\tif (swig_a->_swig_optargc > %d) {\n", i - required_count);
	  Printv(f->code, "\t\t", tm, "\n", NULL);
	  Printv(f->code, "\t}\n", NULL);
	}
      }
      p = nextParm(p);
    }

    Printv(f->code, "\n", NULL);

    // Do the real work of the function.

    checkConstraints(parms, f);

    emitGoAction(n, base, parms, result, f);

    argout(parms, f);

    cleanupFunction(n, f, parms);

    Printv(f->code, "}\n", NULL);

    Wrapper_print(f, f_c_wrappers);

    Swig_restore(n);

    DelWrapper(f);
    Delete(base_parm);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * gccgoFunctionWrapper()
   *
   * This is used for gccgo, not 6g/8g.  Write out the function
   * wrapper which will be compiled with gcc.  If the base parameter
   * is not NULL, this is calls the base class method rather than
   * executing the SWIG wrapper code.
   * ---------------------------------------------------------------------- */

  int gccgoFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) {
    Wrapper *f = NewWrapper();

    Swig_save("gccgoFunctionWrapper", n, "parms", NULL);

    Parm *base_parm = NULL;
    if (base && !isStatic(n)) {
      SwigType *base_type = Copy(getClassType());
      SwigType_add_pointer(base_type);
      base_parm = NewParm(base_type, NewString("arg1"), n);
      set_nextSibling(base_parm, parms);
      parms = base_parm;
    }

    emit_parameter_variables(parms, f);
    emit_attach_parmmaps(parms, f);
    int parm_count = emit_num_arguments(parms);
    int required_count = emit_num_required(parms);

    emit_return_variable(n, result, f);

    // Start the function definition.

    String *fnname = NewString("");
    Printv(fnname, "go_", wname, "(", NULL);

    if (parm_count > required_count) {
      Printv(fnname, "intgo _swig_optargc", NULL);
    }

    Parm *p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);
      SwigType *pt = Copy(Getattr(p, "type"));
      if (SwigType_isarray(pt)) {
	SwigType_del_array(pt);
	SwigType_add_pointer(pt);
      }
      String *pn = NewString("g");
      Append(pn, Getattr(p, "lname"));
      String *ct = gccgoCTypeForGoValue(p, pt, pn);
      if (i > 0 || parm_count > required_count) {
	Printv(fnname, ", ", NULL);
      }
      Printv(fnname, ct, NULL);
      Delete(ct);
      Delete(pn);
      Delete(pt);
      p = nextParm(p);
    }

    Printv(fnname, ")", NULL);

    String *fndef = NewString("");
    if (SwigType_type(result) == T_VOID) {
      Printv(fndef, "void ", fnname, NULL);
    } else {
      String *ct = gccgoCTypeForGoValue(n, result, fnname);
      Printv(fndef, ct, NULL);
      Delete(ct);
    }

    Printv(f->def, fndef, " __asm__(\"", go_prefix, "_", wname, "\");\n", NULL);

    Printv(f->def, fndef, " {\n", NULL);

    Delete(fnname);
    Delete(fndef);

    if (SwigType_type(result) != T_VOID) {
      String *ln = NewString("go_result");
      String *ct = gccgoCTypeForGoValue(n, result, ln);
      Wrapper_add_local(f, "go_result", ct);
      Delete(ct);
      Delete(ln);
    }

    // Copy the parameters into the variables which hold their values,
    // applying appropriate transformations.

    p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);

      String *tm = Getattr(p, "tmap:in");
      if (!tm) {
	Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
		     "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0));
      } else {
	String *ln = Getattr(p, "lname");
	String *pn = NewString("g");
	Append(pn, ln);
	Replaceall(tm, "$input", pn);
	Setattr(p, "emit:input", pn);
	if (i < required_count) {
	  Printv(f->code, "  ", tm, "\n", NULL);
	} else {
	  Printf(f->code, "  if (_swig_optargc > %d) {\n", i - required_count);
	  Printv(f->code, "    ", tm, "\n", NULL);
	  Printv(f->code, "  }\n", NULL);
	}
      }

      p = nextParm(p);
    }

    Printv(f->code, "\n", NULL);

    // Do the real work of the function.

    checkConstraints(parms, f);

    emitGoAction(n, base, parms, result, f);

    argout(parms, f);

    cleanupFunction(n, f, parms);

    if (SwigType_type(result) != T_VOID) {
      Printv(f->code, "  return go_result;\n", NULL);
    }

    Printv(f->code, "}\n", NULL);

    Wrapper_print(f, f_c_wrappers);

    Swig_restore(n);

    DelWrapper(f);
    Delete(base_parm);

    return SWIG_OK;
  }

  /* -----------------------------------------------------------------------
   * checkConstraints()
   *
   * Check parameter constraints if any.  This is used for the C/C++
   * function.  This assumes that each parameter has an "emit:input"
   * property with the name to use to refer to that parameter.
   * ----------------------------------------------------------------------- */

  void checkConstraints(ParmList *parms, Wrapper *f) {
    Parm *p = parms;
    while (p) {
      String *tm = Getattr(p, "tmap:check");
      if (!tm) {
	p = nextSibling(p);
      } else {
	Replaceall(tm, "$input", Getattr(p, "emit:input"));
	Printv(f->code, tm, "\n\n", NULL);
	p = Getattr(p, "tmap:check:next");
      }
    }
  }

  /* -----------------------------------------------------------------------
   * getGoAction()
   *
   * Get the action of the function.  This is used for C/C++ function.
   * ----------------------------------------------------------------------- */

  void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) {
    String *actioncode;
    if (!base || isStatic(n)) {
      Swig_director_emit_dynamic_cast(n, f);
      actioncode = emit_action(n);
    } else {
      // Call the base class method.
      actioncode = NewString("");

      String *current = NewString("");
      if (!gccgo_flag) {
	Printv(current, "swig_a->", NULL);
      }
      Printv(current, Getattr(parms, "lname"), NULL);

      int vc = 0;
      for (Iterator bi = First(base); bi.item; bi = Next(bi)) {
	Printf(actioncode, "  %s *swig_b%d = (%s *)%s;\n", bi.item, vc, bi.item, current);
	Delete(current);
	current = NewString("");
	Printf(current, "swig_b%d", vc);
	++vc;
      }

      String *code = Copy(Getattr(n, "wrap:action"));
      Replaceall(code, Getattr(parms, "lname"), current);
      Printv(actioncode, code, "\n", NULL);
    }

    Swig_save("emitGoAction", n, "type", "tmap:out", NULL);

    Setattr(n, "type", result);

    String *tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
    if (!tm) {
      Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s\n", SwigType_str(result, 0));
    } else {
      if (!gccgo_flag) {
	static const String *swig_a_result = NewStringf("swig_a->%s", Swig_cresult_name());
	Replaceall(tm, "$result", swig_a_result);
      } else {
	Replaceall(tm, "$result", "go_result");
      }
      if (GetFlag(n, "feature:new")) {
	Replaceall(tm, "$owner", "1");
      } else {
	Replaceall(tm, "$owner", "0");
      }
      Printv(f->code, tm, "\n", NULL);
      Delete(tm);
    }

    Swig_restore(n);
  }

  /* -----------------------------------------------------------------------
   * argout()
   *
   * Handle argument output code if any.  This is used for the C/C++
   * function.  This assumes that each parameter has an "emit:input"
   * property with the name to use to refer to that parameter.
   * ----------------------------------------------------------------------- */

  void argout(ParmList *parms, Wrapper *f) {
    Parm *p = parms;
    while (p) {
      String *tm = Getattr(p, "tmap:argout");
      if (!tm) {
	p = nextSibling(p);
      } else {
	Replaceall(tm, "$result", Swig_cresult_name());
	Replaceall(tm, "$input", Getattr(p, "emit:input"));
	Printv(f->code, tm, "\n", NULL);
	p = Getattr(p, "tmap:argout:next");
      }
    }
  }

  /* -----------------------------------------------------------------------
   * freearg()
   *
   * Handle argument cleanup code if any.  This is used for the C/C++
   * function.  This assumes that each parameter has an "emit:input"
   * property with the name to use to refer to that parameter.
   * ----------------------------------------------------------------------- */

  String *freearg(ParmList *parms) {
    String *ret = NewString("");
    Parm *p = parms;
    while (p) {
      String *tm = Getattr(p, "tmap:freearg");
      if (!tm) {
	p = nextSibling(p);
      } else {
	Replaceall(tm, "$input", Getattr(p, "emit:input"));
	Printv(ret, tm, "\n", NULL);
	p = Getattr(p, "tmap:freearg:next");
      }
    }
    return ret;
  }

  /* -----------------------------------------------------------------------
   * cleanupFunction()
   *
   * Final function cleanup code.
   * ----------------------------------------------------------------------- */

  void cleanupFunction(Node *n, Wrapper *f, ParmList *parms) {
    String *cleanup = freearg(parms);
    Printv(f->code, cleanup, NULL);

    if (GetFlag(n, "feature:new")) {
      String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
      if (tm) {
	Replaceall(tm, "$source", Swig_cresult_name());
	Printv(f->code, tm, "\n", NULL);
	Delete(tm);
      }
    }

    Replaceall(f->code, "$cleanup", cleanup);
    Delete(cleanup);

    Replaceall(f->code, "$symname", Getattr(n, "sym:name"));
  }

  /* -----------------------------------------------------------------------
   * variableHandler()
   *
   * This exists just to set the making_variable_wrappers flag.
   * ----------------------------------------------------------------------- */

  virtual int variableHandler(Node *n) {
    assert(!making_variable_wrappers);
    making_variable_wrappers = true;
    int r = Language::variableHandler(n);
    making_variable_wrappers = false;
    return r;
  }

  /* -----------------------------------------------------------------------
   * constantWrapper()
   *
   * Product a const declaration.
   * ------------------------------------------------------------------------ */

  virtual int constantWrapper(Node *n) {
    SwigType *type = Getattr(n, "type");

    if (!SwigType_issimple(type) && SwigType_type(type) != T_STRING) {
      return goComplexConstant(n, type);
    }

    if (Swig_storage_isstatic(n)) {
      return goComplexConstant(n, type);
    }

    String *go_name = buildGoName(Getattr(n, "sym:name"), false, false);

    String *tm = goType(n, type);
    String *value = Getattr(n, "value");

    String *copy = NULL;
    if (SwigType_type(type) == T_BOOL) {
      if (Cmp(value, "true") != 0 && Cmp(value, "false") != 0) {
	return goComplexConstant(n, type);
      }
    } else if (SwigType_type(type) == T_STRING || SwigType_type(type) == T_CHAR) {
      // Backslash sequences are somewhat different in Go and C/C++.
      if (Strchr(value, '\\') != 0) {
	return goComplexConstant(n, type);
      }
    } else {
      // Accept a 0x prefix, and strip combinations of u and l
      // suffixes.  Otherwise accept digits, decimal point, and
      // exponentiation.  Treat anything else as too complicated to
      // handle as a Go constant.
      char *p = Char(value);
      int len = strlen(p);
      bool need_copy = false;
      while (len > 0) {
	char c = p[len - 1];
	if (c != 'l' && c != 'L' && c != 'u' && c != 'U') {
	  break;
	}
	--len;
	need_copy = true;
      }
      bool is_hex = false;
      int i = 0;
      if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
	i = 2;
	is_hex = true;
      }
      for (; i < len; ++i) {
	switch (p[i]) {
	case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
	  break;
	case 'a': case 'b': case 'c': case 'd': case 'f': case 'A': case 'B': case 'C': case 'D': case 'F':
	  if (!is_hex) {
	    return goComplexConstant(n, type);
	  }
	  break;
	case '.': case 'e': case 'E': case '+': case '-':
	  break;
	default:
	  return goComplexConstant(n, type);
	}
      }
      if (need_copy) {
	copy = Copy(value);
	Replaceall(copy, p + len, "");
	value = copy;
      }
    }

    if (!checkNameConflict(go_name, n, NULL)) {
      Delete(tm);
      Delete(go_name);
      Delete(copy);
      return SWIG_NOWRAP;
    }

    Printv(f_go_wrappers, "const ", go_name, " ", tm, " = ", NULL);
    if (SwigType_type(type) == T_STRING) {
      Printv(f_go_wrappers, "\"", value, "\"", NULL);
    } else if (SwigType_type(type) == T_CHAR) {
      Printv(f_go_wrappers, "'", value, "'", NULL);
    } else {
      Printv(f_go_wrappers, value, NULL);
    }

    Printv(f_go_wrappers, "\n", NULL);

    Delete(tm);
    Delete(go_name);
    Delete(copy);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * enumDeclaration()
   *
   * A C++ enum type turns into a Named go int type.
   * ---------------------------------------------------------------------- */

  virtual int enumDeclaration(Node *n) {
    String *name = goEnumName(n);
    if (Strcmp(name, "int") != 0) {
      if (!ImportMode || !imported_package) {
	if (!checkNameConflict(name, n, NULL)) {
	  Delete(name);
	  return SWIG_NOWRAP;
	}
	Printv(f_go_wrappers, "type ", name, " int\n", NULL);
      } else {
	String *nw = NewString("");
	Printv(nw, imported_package, ".", name, NULL);
	Setattr(n, "go:enumname", nw);
      }
    }
    Delete(name);

    return Language::enumDeclaration(n);
  }

  /* -----------------------------------------------------------------------
   * enumvalueDeclaration()
   *
   * Declare a single value of an enum type.  We fetch the value by
   * calling a C/C++ function.
   * ------------------------------------------------------------------------ */

  virtual int enumvalueDeclaration(Node *n) {
    if (!is_public(n)) {
      return SWIG_OK;
    }
    if (Getattr(parentNode(n), "unnamed")) {
      Setattr(n, "type", NewString("int"));
    } else {
      Setattr(n, "type", Getattr(parentNode(n), "enumtype"));
    }
    return goComplexConstant(n, Getattr(n, "type"));
  }

  /* -----------------------------------------------------------------------
   * goComplexConstant()
   *
   * Handle a const declaration for something which is not a Go constant.
   * ------------------------------------------------------------------------ */

  int goComplexConstant(Node *n, SwigType *type) {
    String *symname = Getattr(n, "sym:name");
    if (!symname) {
      symname = Getattr(n, "name");
    }

    String *varname = buildGoName(symname, true, false);

    if (!checkNameConflict(varname, n, NULL)) {
      Delete(varname);
      return SWIG_NOWRAP;
    }

    String *get = NewString("");
    Printv(get, Swig_cresult_name(), " = ", NULL);

    char quote;
    if (Getattr(n, "wrappedasconstant")) {
      quote = '\0';
    } else if (SwigType_type(type) == T_CHAR) {
      quote = '\'';
    } else if (SwigType_type(type) == T_STRING) {
      quote = '"';
    } else {
      quote = '\0';
    }

    if (quote != '\0') {
      Printf(get, "%c", quote);
    }

    Printv(get, Getattr(n, "value"), NULL);

    if (quote != '\0') {
      Printf(get, "%c", quote);
    }

    Printv(get, ";\n", NULL);
    Setattr(n, "wrap:action", get);

    String *sname = Copy(symname);
    if (class_name) {
      Append(sname, "_");
      Append(sname, class_name);
    }

    String *go_name = NewString("_swig_get");
    if (class_name) {
      Append(go_name, class_name);
      Append(go_name, "_");
    }
    Append(go_name, sname);

    String *wname = Swig_name_wrapper(sname);
    Setattr(n, "wrap:name", wname);

    int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, true);

    if (r != SWIG_OK) {
      return r;
    }

    String *t = goType(n, type);
    Printv(f_go_wrappers, "var ", varname, " ", t, " = ", go_name, "()\n", NULL);

    Delete(varname);
    Delete(t);
    Delete(go_name);
    Delete(sname);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classHandler()
   *
   * For a C++ class, in Go we generate both a struct and an
   * interface.  The interface will declare all the class public
   * methods.  We will define all the methods on the struct, so that
   * the struct meets the interface.  We then expect users of the
   * class to use the interface.
   * ------------------------------------------------------------ */

  virtual int classHandler(Node *n) {
    class_node = n;

    List *baselist = Getattr(n, "bases");
    bool has_base_classes = baselist && Len(baselist) > 0;

    String *name = Getattr(n, "sym:name");

    String *go_name = exportedName(name);

    if (!checkNameConflict(go_name, n, NULL)) {
      Delete(go_name);
      SetFlag(n, "go:conflict");
      return SWIG_NOWRAP;
    }

    String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true);

    class_name = name;
    class_receiver = go_type_name;
    class_methods = NewHash();

    int isdir = GetFlag(n, "feature:director");
    int isnodir = GetFlag(n, "feature:nodirector");
    bool is_director = isdir && !isnodir;

    Printv(f_go_wrappers, "type ", go_type_name, " uintptr\n\n", NULL);

    // A method to return the pointer to the C++ class.  This is used
    // by generated code to convert between the interface and the C++
    // value.
    Printv(f_go_wrappers, "func (p ", go_type_name, ") Swigcptr() uintptr {\n", NULL);
    Printv(f_go_wrappers, "\treturn (uintptr)(p)\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    // A method used as a marker for the class, to avoid invalid
    // interface conversions when using multiple inheritance.
    Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_name, "() {\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    if (is_director) {
      // Return the interface passed to the NewDirector function.
      Printv(f_go_wrappers, "func (p ", go_type_name, ") DirectorInterface() interface{} {\n", NULL);
      Printv(f_go_wrappers, "\treturn nil\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);
    }

    // We have seen a definition for this type.
    Setattr(defined_types, go_name, go_name);
    Setattr(defined_types, go_type_name, go_type_name);

    interfaces = NewString("");

    int r = Language::classHandler(n);
    if (r != SWIG_OK) {
      return r;
    }

    if (has_base_classes) {
      // For each method defined in a base class but not defined in
      // this class, we need to define the method in this class.  We
      // can't use anonymous field inheritance because it works
      // differently in Go and in C++.

      Hash *local = NewHash();
      for (Node *ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {

	if (!is_public(ni)) {
	  continue;
	}

	String *type = Getattr(ni, "nodeType");
	if (Cmp(type, "constructor") == 0 || Cmp(type, "destructor") == 0) {
	  continue;
	}

	String *cname = Getattr(ni, "sym:name");
	if (!cname) {
	  cname = Getattr(ni, "name");
	}
	if (cname) {
	  Setattr(local, cname, NewString(""));
	}
      }

      for (Iterator b = First(baselist); b.item; b = Next(b)) {
	List *bases = NewList();
	Append(bases, Getattr(b.item, "classtype"));
	int r = addBase(n, b.item, bases, local);
	if (r != SWIG_OK) {
	  return r;
	}
	Delete(bases);
      }

      Delete(local);

      Hash *parents = NewHash();
      addFirstBaseInterface(n, parents, baselist);
      int r = addExtraBaseInterfaces(n, parents, baselist);
      Delete(parents);
      if (r != SWIG_OK) {
	return r;
      }
    }

    Printv(f_go_wrappers, "type ", go_name, " interface {\n", NULL);
    Printv(f_go_wrappers, "\tSwigcptr() uintptr\n", NULL);
    Printv(f_go_wrappers, "\tSwigIs", go_name, "()\n", NULL);

    if (is_director) {
      Printv(f_go_wrappers, "\tDirectorInterface() interface{}\n", NULL);
    }

    Append(f_go_wrappers, interfaces);
    Printf(f_go_wrappers, "}\n\n", NULL);
    Delete(interfaces);

    interfaces = NULL;
    class_name = NULL;
    class_receiver = NULL;
    class_node = NULL;
    Delete(class_methods);
    class_methods = NULL;

    Delete(go_type_name);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * addBase()
   *
   * Implement methods and members defined in a parent class for a
   * child class.
   * ------------------------------------------------------------ */

  int addBase(Node *n, Node *base, List *bases, Hash *local) {
    if (GetFlag(base, "feature:ignore")) {
      return SWIG_OK;
    }

    for (Node *ni = Getattr(base, "firstChild"); ni; ni = nextSibling(ni)) {

      if (GetFlag(ni, "feature:ignore")) {
	continue;
      }

      if (!is_public(ni)) {
	continue;
      }

      String *type = Getattr(ni, "nodeType");
      if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0 || Strcmp(type, "template") == 0) {
	continue;
      }
      String *storage = Getattr(ni, "storage");
      if (storage && (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0)) {
	continue;
      }

      String *mname = Getattr(ni, "sym:name");
      if (!mname) {
	continue;
      }

      String *lname = Getattr(ni, "name");
      if (Getattr(class_methods, lname)) {
	continue;
      }
      if (Getattr(local, lname)) {
	continue;
      }
      Setattr(local, lname, NewString(""));

      String *ty = NewString(Getattr(ni, "type"));
      SwigType_push(ty, Getattr(ni, "decl"));
      String *fullty = SwigType_typedef_resolve_all(ty);
      bool is_function = SwigType_isfunction(fullty) ? true : false;
      Delete(ty);
      Delete(fullty);

      if (is_function) {
	int r = goBaseMethod(n, bases, ni);
	if (r != SWIG_OK) {
	  return r;
	}

	if (Getattr(ni, "sym:overloaded")) {
	  for (Node *on = Getattr(ni, "sym:nextSibling"); on; on = Getattr(on, "sym:nextSibling")) {
	    r = goBaseMethod(n, bases, on);
	    if (r != SWIG_OK) {
	      return r;
	    }
	  }

	  String *receiver = class_receiver;
	  bool is_static = isStatic(ni);
	  if (is_static) {
	    receiver = NULL;
	  }
	  String *go_name = buildGoName(Getattr(ni, "sym:name"), is_static, false);
	  r = makeDispatchFunction(ni, go_name, receiver, is_static, NULL, false);
	  Delete(go_name);
	  if (r != SWIG_OK) {
	    return r;
	  }
	}
      } else {
	int r = goBaseVariable(n, bases, ni);
	if (r != SWIG_OK) {
	  return r;
	}
      }
    }

    List *baselist = Getattr(base, "bases");
    if (baselist && Len(baselist) > 0) {
      for (Iterator b = First(baselist); b.item; b = Next(b)) {
	List *nb = Copy(bases);
	Append(nb, Getattr(b.item, "classtype"));
	int r = addBase(n, b.item, nb, local);
	Delete(nb);
	if (r != SWIG_OK) {
	  return r;
	}
      }
    }

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * goBaseMethod()
   *
   * Implement a method defined in a parent class for a child class.
   * ------------------------------------------------------------ */

  int goBaseMethod(Node *method_class, List *bases, Node *method) {
    String *symname = Getattr(method, "sym:name");
    if (!validIdentifier(symname)) {
      return SWIG_OK;
    }

    String *name = NewString("");
    Printv(name, Getattr(method_class, "sym:name"), "_", symname, NULL);

    bool is_static = isStatic(method);

    String *go_name = buildGoName(name, is_static, false);

    String *overname = NULL;
    if (Getattr(method, "sym:overloaded")) {
      overname = Getattr(method, "sym:overname");
    }
    String *wname = Swig_name_wrapper(name);
    if (overname) {
      Append(wname, overname);
    }

    String *result = NewString(Getattr(method, "type"));
    SwigType_push(result, Getattr(method, "decl"));
    if (SwigType_isqualifier(result)) {
      Delete(SwigType_pop(result));
    }
    Delete(SwigType_pop_function(result));

    // If the base method is imported, wrap:action may not be set.
    Swig_save("goBaseMethod", method, "wrap:name", "wrap:action", "parms", NULL);
    Setattr(method, "wrap:name", wname);
    if (!Getattr(method, "wrap:action")) {
      if (!is_static) {
	Swig_MethodToFunction(method, getNSpace(), getClassType(), (Getattr(method, "template") ? SmartPointer : Extend | SmartPointer), NULL, false);
	// Remove any self parameter that was just added.
	ParmList *parms = Getattr(method, "parms");
	if (parms && Getattr(parms, "self")) {
	  parms = CopyParmList(nextSibling(parms));
	  Setattr(method, "parms", parms);
	}
      } else {
	String *call = Swig_cfunction_call(Getattr(method, "name"), Getattr(method, "parms"));
	Setattr(method, "wrap:action", Swig_cresult(Getattr(method, "type"), Swig_cresult_name(), call));
      }
    }

    int r = makeWrappers(method, name, go_name, overname, wname, bases, Getattr(method, "parms"), result, is_static);

    Swig_restore(method);

    Delete(result);
    Delete(go_name);
    Delete(name);

    return r;
  }

  /* ------------------------------------------------------------
   * goBaseVariable()
   *
   * Add accessors for a member variable defined in a parent class for
   * a child class.
   * ------------------------------------------------------------ */

  int goBaseVariable(Node *var_class, List *bases, Node *var) {
    if (isStatic(var)) {
      return SWIG_OK;
    }

    String *var_name = buildGoName(Getattr(var, "sym:name"), false, false);

    Swig_save("goBaseVariable", var, "type", "wrap:action", NULL);

    // For a pointer type we apparently have to wrap in the decl.
    SwigType *var_type = NewString(Getattr(var, "type"));
    SwigType_push(var_type, Getattr(var, "decl"));
    Setattr(var, "type", var_type);

    SwigType *vt = Copy(var_type);
    if (SwigType_isclass(vt)) {
      SwigType_add_pointer(vt);
    }

    int flags = Extend | SmartPointer | use_naturalvar_mode(var);
    if (isNonVirtualProtectedAccess(var)) {
      flags |= CWRAP_ALL_PROTECTED_ACCESS;
    }

    String *mname = Swig_name_member(getNSpace(), Getattr(var_class, "sym:name"), var_name);

    if (is_assignable(var)) {
      for (Iterator ki = First(var); ki.key; ki = Next(ki)) {
	if (Strncmp(ki.key, "tmap:", 5) == 0) {
	  Delattr(var, ki.key);
	}
      }
      Swig_save("goBaseVariableSet", var, "name", "sym:name", "type", NULL);

      String *mname_set = NewString("Set");
      Append(mname_set, mname);

      String *go_name = NewString("Set");
      Append(go_name, var_name);

      Swig_MembersetToFunction(var, class_name, flags);

      String *wname = Swig_name_wrapper(mname_set);
      ParmList *parms = NewParm(vt, var_name, var);
      String *result = NewString("void");
      int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, result, false);
      if (r != SWIG_OK) {
	return r;
      }
      Delete(wname);
      Delete(parms);
      Delete(result);
      Delete(go_name);
      Delete(mname_set);

      Swig_restore(var);
      for (Iterator ki = First(var); ki.key; ki = Next(ki)) {
	if (Strncmp(ki.key, "tmap:", 5) == 0) {
	  Delattr(var, ki.key);
	}
      }
    }

    Swig_MembergetToFunction(var, class_name, flags);

    String *mname_get = NewString("Get");
    Append(mname_get, mname);

    String *go_name = NewString("Get");
    Append(go_name, var_name);

    String *wname = Swig_name_wrapper(mname_get);

    int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, vt, false);
    if (r != SWIG_OK) {
      return r;
    }

    Delete(wname);
    Delete(mname_get);
    Delete(go_name);
    Delete(mname);
    Delete(var_name);
    Delete(var_type);
    Delete(vt);

    Swig_restore(var);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * addFirstBaseInterface()
   *
   * When a C++ class uses multiple inheritance, we can use the C++
   * pointer for the first base class but not for any subsequent base
   * classes.  However, the Go interface will match the interface for
   * all the base classes.  To avoid accidentally treating a class as
   * a pointer to a base class other than the first one, we use an
   * isClassname method.  This function adds those methods as
   * required.
   *
   * For convenience when using multiple inheritance, we also add
   * functions to retrieve the base class pointers.
   * ------------------------------------------------------------ */

  void addFirstBaseInterface(Node *n, Hash *parents, List *bases) {
    if (!bases || Len(bases) == 0) {
      return;
    }
    Iterator b = First(bases);
    if (!GetFlag(b.item, "feature:ignore")) {
      String *go_name = buildGoName(Getattr(n, "sym:name"), false, false);
      String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true);
      String *go_base_name = exportedName(Getattr(b.item, "sym:name"));
      String *go_base_type = goType(n, Getattr(b.item, "classtypeobj"));
      String *go_base_type_name = goCPointerType(Getattr(b.item, "classtypeobj"), true);

      Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_base_name, "() {\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);

      Printv(interfaces, "\tSwigIs", go_base_name, "()\n", NULL);

      Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, "() ", go_base_type, " {\n", NULL);
      Printv(f_go_wrappers, "\treturn ", go_base_type_name, "(p.Swigcptr())\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);

      Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_type, "\n", NULL);

      Setattr(parents, go_base_name, NewString(""));

      Delete(go_name);
      Delete(go_type_name);
      Delete(go_base_type);
      Delete(go_base_type_name);
    }

    addFirstBaseInterface(n, parents, Getattr(b.item, "bases"));
  }

  /* ------------------------------------------------------------
   * addExtraBaseInterfaces()
   *
   * Add functions to retrieve the base class pointers for all base
   * classes other than the first.
   * ------------------------------------------------------------ */

  int addExtraBaseInterfaces(Node *n, Hash *parents, List *bases) {
    Iterator b = First(bases);

    Node *fb = b.item;

    for (b = Next(b); b.item; b = Next(b)) {
      if (GetFlag(b.item, "feature:ignore")) {
	continue;
      }

      String *go_base_name = exportedName(Getattr(b.item, "sym:name"));

      Swig_save("addExtraBaseInterface", n, "wrap:action", "wrap:name", "wrap:parms", NULL);

      SwigType *type = Copy(Getattr(n, "classtypeobj"));
      SwigType_add_pointer(type);
      Parm *parm = NewParm(type, "self", n);
      Setattr(n, "wrap:parms", parm);

      String *pn = Swig_cparm_name(parm, 0);
      String *action = NewString("");
      Printv(action, Swig_cresult_name(), " = (", Getattr(b.item, "classtype"), "*)", pn, ";", NULL);
      Delete(pn);

      Setattr(n, "wrap:action", action);

      String *name = Copy(class_name);
      Append(name, "_SwigGet");
      Append(name, go_base_name);

      String *go_name = NewString("SwigGet");
      String *c1 = exportedName(go_base_name);
      Append(go_name, c1);
      Delete(c1);

      String *wname = Swig_name_wrapper(name);
      Setattr(n, "wrap:name", wname);

      SwigType *result = Copy(Getattr(b.item, "classtypeobj"));
      SwigType_add_pointer(result);

      int r = makeWrappers(n, name, go_name, NULL, wname, NULL, parm, result,
			   false);
      if (r != SWIG_OK) {
	return r;
      }

      Swig_restore(n);

      Setattr(parents, go_base_name, NewString(""));

      Delete(go_name);
      Delete(type);
      Delete(parm);
      Delete(action);
      Delete(result);

      String *ns = NewString("");
      addParentExtraBaseInterfaces(n, parents, b.item, false, ns);
      Delete(ns);
    }

    if (!GetFlag(fb, "feature:ignore")) {
      String *ns = NewString("");
      addParentExtraBaseInterfaces(n, parents, fb, true, ns);
      Delete(ns);
    }

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * addParentExtraBaseInterfaces()
   *
   * Add functions to retrieve the base class pointers for all base
   * classes of parents other than the first base class at each level.
   * ------------------------------------------------------------ */

  void addParentExtraBaseInterfaces(Node *n, Hash *parents, Node *base, bool is_base_first, String *sofar) {
    List *baselist = Getattr(base, "bases");
    if (!baselist || Len(baselist) == 0) {
      return;
    }

    String *go_this_base_name = exportedName(Getattr(base, "sym:name"));

    String *sf = NewString("");
    Printv(sf, sofar, ".SwigGet", go_this_base_name, "()", NULL);

    Iterator b = First(baselist);

    if (is_base_first) {
      if (!b.item) {
	return;
      }
      if (!GetFlag(b.item, "feature:ignore")) {
	addParentExtraBaseInterfaces(n, parents, b.item, true, sf);
      }

      b = Next(b);
    }

    String *go_name = buildGoName(Getattr(n, "sym:name"), false, false);
    String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true);

    for (; b.item; b = Next(b)) {
      if (GetFlag(b.item, "feature:ignore")) {
	continue;
      }

      String *go_base_name = exportedName(Getattr(b.item, "sym:name"));

      if (!Getattr(parents, go_base_name)) {
	Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, "() ", go_base_name, " {\n", NULL);
	Printv(f_go_wrappers, "\treturn p", sf, ".SwigGet", go_base_name, "()\n", NULL);
	Printv(f_go_wrappers, "}\n\n", NULL);

	Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_name, "\n", NULL);

	addParentExtraBaseInterfaces(n, parents, b.item, false, sf);

	Setattr(parents, go_base_name, NewString(""));
      }
    }

    Delete(go_name);
    Delete(go_type_name);
    Delete(go_this_base_name);
    Delete(sf);
  }

  /* ------------------------------------------------------------
   * classDirectorInit
   *
   * Add support for a director class.
   *
   * Virtual inheritance is different in Go and C++.  We implement
   * director classes by defining a new function in Go,
   * NewDirectorClassname, which takes a empty interface value and
   * creates an instance of a new child class.  The new child class
   * refers all methods back to Go.  The Go code checks whether the
   * value passed to NewDirectorClassname implements that method; if
   * it does, it calls it, otherwise it calls back into C++.
   * ------------------------------------------------------------ */

  int classDirectorInit(Node *n) {
    // Because we use a different function to handle inheritance in
    // Go, ordinary creations of the object should not create a
    // director object.
    Delete(director_ctor_code);
    director_ctor_code = NewString("$nondirector_new");

    class_node = n;

    String *name = Getattr(n, "sym:name");

    assert(!class_name);
    class_name = name;

    String *go_name = exportedName(name);

    String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true);

    assert(!class_receiver);
    class_receiver = go_type_name;

    String *director_struct_name = NewString("_swig_Director");
    Append(director_struct_name, go_name);

    String *cxx_director_name = NewString("SwigDirector_");
    Append(cxx_director_name, name);

    // The Go type of the director class.
    Printv(f_go_wrappers, "type ", director_struct_name, " struct {\n", NULL);
    Printv(f_go_wrappers, "\t", go_type_name, "\n", NULL);
    Printv(f_go_wrappers, "\tv interface{}\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    Printv(f_go_wrappers, "func (p *", director_struct_name, ") Swigcptr() uintptr {\n", NULL);
    Printv(f_go_wrappers, "\treturn p.", go_type_name, ".Swigcptr()\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    Printv(f_go_wrappers, "func (p *", director_struct_name, ") SwigIs", go_name, "() {\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    Printv(f_go_wrappers, "func (p *", director_struct_name, ") DirectorInterface() interface{} {\n", NULL);
    Printv(f_go_wrappers, "\treturn p.v\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    // Start defining the director class.
    Printv(f_c_directors_h, "class ", cxx_director_name, " : public ", Getattr(n, "classtype"), "\n", NULL);
    Printv(f_c_directors_h, "{\n", NULL);
    Printv(f_c_directors_h, " public:\n", NULL);

    Delete(director_struct_name);
    Delete(cxx_director_name);

    class_methods = NewHash();

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classDirectorConstructor
   *
   * Emit a constructor for a director class.
   * ------------------------------------------------------------ */

  int classDirectorConstructor(Node *n) {
    bool is_ignored = GetFlag(n, "feature:ignore") ? true : false;

    String *name = Getattr(n, "sym:name");
    if (!name) {
      assert(is_ignored);
      name = Getattr(n, "name");
    }

    String *overname = NULL;
    if (Getattr(n, "sym:overloaded")) {
      overname = Getattr(n, "sym:overname");
    }

    String *go_name = exportedName(name);

    ParmList *parms = Getattr(n, "parms");
    Setattr(n, "wrap:parms", parms);

    String *cn = exportedName(Getattr(parentNode(n), "sym:name"));

    String *go_type_name = goCPointerType(Getattr(parentNode(n), "classtypeobj"), true);

    String *director_struct_name = NewString("_swig_Director");
    Append(director_struct_name, cn);

    String *fn_name = NewString("_swig_NewDirector");
    Append(fn_name, cn);
    Append(fn_name, go_name);

    if (!overname && !is_ignored) {
      if (!checkNameConflict(fn_name, n, NULL)) {
	return SWIG_NOWRAP;
      }
    }

    String *wname = Swig_name_wrapper(fn_name);

    if (overname) {
      Append(wname, overname);
    }
    Setattr(n, "wrap:name", wname);

    bool is_static = isStatic(n);

    Wrapper *dummy = NewWrapper();
    emit_attach_parmmaps(parms, dummy);
    DelWrapper(dummy);

    Swig_typemap_attach_parms("gotype", parms, NULL);
    int parm_count = emit_num_arguments(parms);

    String *func_name = NewString("NewDirector");
    Append(func_name, go_name);

    String *func_with_over_name = Copy(func_name);
    if (overname) {
      Append(func_with_over_name, overname);
    }

    SwigType *first_type = NewString("void");
    SwigType_add_pointer(first_type);
    Parm *first_parm = NewParm(first_type, "swig_p", n);
    set_nextSibling(first_parm, parms);
    Setattr(first_parm, "lname", "p");

    Parm *p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);
      Swig_cparm_name(p, i);
      p = nextParm(p);
    }

    if (!is_ignored) {
      // Declare the C++ wrapper.

      if (gccgo_flag) {
	Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL);
      }

      Printv(f_go_wrappers, "func ", fn_name, NULL);
      if (overname) {
	Printv(f_go_wrappers, overname, NULL);
      }
      Printv(f_go_wrappers, "(*", director_struct_name, NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	String *tm = goType(p, Getattr(p, "type"));
	Printv(f_go_wrappers, ", ", tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ") ", go_type_name, "\n\n", NULL);

      Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	// Set the lname parameter.
	Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", NULL);
	String *tm = goType(p, Getattr(p, "type"));
	Printv(f_go_wrappers, tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ") ", cn, " {\n", NULL);

      Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL);

      if (gccgo_flag) {
	Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
	Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
      }

      Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL);
      if (overname) {
	Printv(f_go_wrappers, overname, NULL);
      }
      Printv(f_go_wrappers, "(p", NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ")\n", NULL);
      Printv(f_go_wrappers, "\treturn p\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);

      SwigType *result = Copy(Getattr(parentNode(n), "classtypeobj"));
      SwigType_add_pointer(result);

      Swig_save("classDirectorConstructor", n, "wrap:name", "wrap:action", NULL);

      Setattr(n, "wrap:name", Swig_name_wrapper(name));

      String *action = NewString("");
      Printv(action, Swig_cresult_name(), " = new SwigDirector_", class_name, "(", NULL);
      String *pname = Swig_cparm_name(NULL, 0);
      Printv(action, pname, NULL);
      Delete(pname);
      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	String *pname = Swig_cparm_name(NULL, i + 1);
	Printv(action, ", ", NULL);
	if (SwigType_isreference(Getattr(p, "type"))) {
	  Printv(action, "*", NULL);
	}
	Printv(action, pname, NULL);
	Delete(pname);
	p = nextParm(p);
      }
      Printv(action, ");", NULL);
      Setattr(n, "wrap:action", action);

      if (!gccgo_flag) {
	int r = gcFunctionWrapper(n, fn_name, fn_name, overname, wname,
				  first_parm, result, is_static, false);
	if (r != SWIG_OK) {
	  return r;
	}
	r = gccFunctionWrapper(n, NULL, wname, first_parm, result);
	if (r != SWIG_OK) {
	  return r;
	}
      } else {
	int r = gccgoFunctionWrapper(n, NULL, wname, first_parm, result);
	if (r != SWIG_OK) {
	  return r;
	}
      }

      Swig_restore(n);

      Delete(result);
    }

    String *cxx_director_name = NewString("SwigDirector_");
    Append(cxx_director_name, class_name);

    String *decl = Swig_method_decl(NULL, Getattr(n, "decl"),
				    cxx_director_name, first_parm, 0, 0);
    Printv(f_c_directors_h, "  ", decl, ";\n", NULL);
    Delete(decl);

    decl = Swig_method_decl(NULL, Getattr(n, "decl"), cxx_director_name, first_parm, 0, 0);
    Printv(f_c_directors, cxx_director_name, "::", decl, "\n", NULL);
    Delete(decl);

    Printv(f_c_directors, "    : ", Getattr(parentNode(n), "classtype"), "(", NULL);

    p = parms;
    for (int i = 0; i < parm_count; ++i) {
      p = getParm(p);
      if (i > 0) {
	Printv(f_c_directors, ", ", NULL);
      }
      String *pn = Getattr(p, "name");
      assert(pn);
      Printv(f_c_directors, pn, NULL);
      p = nextParm(p);
    }
    Printv(f_c_directors, "),\n", NULL);
    Printv(f_c_directors, "      go_val(swig_p)\n", NULL);
    Printv(f_c_directors, "{ }\n\n", NULL);

    if (Getattr(n, "sym:overloaded") && !Getattr(n, "sym:nextSibling")) {
      int r = makeDispatchFunction(n, func_name, cn, is_static, Getattr(parentNode(n), "classtypeobj"), false);
      if (r != SWIG_OK) {
	return r;
      }
    }

    Delete(cxx_director_name);
    Delete(go_name);
    Delete(cn);
    Delete(go_type_name);
    Delete(director_struct_name);
    Delete(fn_name);
    Delete(func_name);
    Delete(func_with_over_name);
    Delete(wname);
    Delete(first_type);
    Delete(first_parm);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classDirectorDestructor
   *
   * Emit a destructor for a director class.
   * ------------------------------------------------------------ */

  int classDirectorDestructor(Node *n) {
    if (!is_public(n)) {
      return SWIG_OK;
    }

    bool is_ignored = GetFlag(n, "feature:ignore") ? true : false;

    if (!is_ignored) {
      String *fnname = NewString("DeleteDirector");
      String *c1 = exportedName(class_name);
      Append(fnname, c1);
      Delete(c1);

      String *wname = Swig_name_wrapper(fnname);

      Setattr(n, "wrap:name", fnname);

      Swig_DestructorToFunction(n, getNSpace(), getClassType(), CPlusPlus, Extend);

      ParmList *parms = Getattr(n, "parms");
      Setattr(n, "wrap:parms", parms);

      String *result = NewString("void");
      int r = makeWrappers(n, fnname, fnname, NULL, wname, NULL, parms, result, isStatic(n));
      if (r != SWIG_OK) {
	return r;
      }

      Delete(result);
      Delete(fnname);
      Delete(wname);
    }

    // Generate the destructor for the C++ director class.  Since the
    // Go code is keeping a pointer to the C++ object, we need to call
    // back to the Go code to let it know that the C++ object is gone.

    String *wname = NewString("_swiggo_wrap_DeleteDirector_");
    Append(wname, class_name);

    String *go_name = NewString("Swiggo_DeleteDirector_");
    Append(go_name, class_name);

    String *cn = exportedName(class_name);

    String *director_struct_name = NewString("_swig_Director");
    Append(director_struct_name, cn);

    Printv(f_c_directors_h, "  virtual ~SwigDirector_", class_name, "()", NULL);

    String *throws = buildThrow(n);
    if (throws) {
      Printv(f_c_directors_h, " ", throws, NULL);
    }

    Printv(f_c_directors_h, ";\n", NULL);

    if (!is_ignored) {
      if (!gccgo_flag) {
	Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", NULL);
      } else {
	Printv(f_c_directors, "extern \"C\" void ", wname, "(void*) __asm__(\"", go_prefix, ".", go_name, "\");\n", NULL);
      }
    }

    Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", class_name, "()", NULL);

    if (throws) {
      Printv(f_c_directors, " ", throws, NULL);
      Delete(throws);
    }

    Printv(f_c_directors, "\n", NULL);
    Printv(f_c_directors, "{\n", NULL);

    if (!is_ignored) {
      if (!gccgo_flag) {
	Printv(f_c_directors, "  struct { void *p; } a;\n", NULL);
	Printv(f_c_directors, "  a.p = go_val;\n", NULL);
	Printv(f_c_directors, "  crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL);

	Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL);
	Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL);
	Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL);
	Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL);
	Printv(f_gc_wrappers, "void\n", NULL);
	Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL);
	Printv(f_gc_wrappers, "{\n", NULL);
	Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL);
	Printv(f_gc_wrappers, "}\n\n", NULL);
      } else {
	Printv(f_c_directors, "  ", wname, "(go_val);\n", NULL);
      }
    }

    Printv(f_c_directors, "}\n\n", NULL);

    if (!is_ignored) {
      Printv(f_go_wrappers, "func ", go_name, "(p *", director_struct_name, ") {\n", NULL);
      Printv(f_go_wrappers, "\tp.", class_receiver, " = 0\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);
    }

    Delete(wname);
    Delete(go_name);
    Delete(cn);
    Delete(director_struct_name);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classDirectorMethod
   *
   * Emit a method for a director class, plus its overloads.
   * ------------------------------------------------------------ */

  int classDirectorMethod(Node *n, Node *parent, String *super) {
    bool is_ignored = GetFlag(n, "feature:ignore") ? true : false;

    // We don't need explicit calls.
    if (GetFlag(n, "explicitcall")) {
      return SWIG_OK;
    }

    String *name = Getattr(n, "sym:name");
    if (!name) {
      assert(is_ignored);
      name = Getattr(n, "name");
    }

    bool overloaded = Getattr(n, "sym:overloaded") && !Getattr(n, "explicitcallnode");
    if (!overloaded) {
      int r = oneClassDirectorMethod(n, parent, super);
      if (r != SWIG_OK) {
	return r;
      }
    } else {
      // Handle overloaded methods here, because otherwise we will
      // reject them in the class_methods hash table.  We need to use
      // class_methods so that we correctly handle cases where a
      // function in one class hides a function of the same name in a
      // parent class.
      if (!Getattr(class_methods, name)) {
	for (Node *on = Getattr(n, "sym:overloaded"); on; on = Getattr(on, "sym:nextSibling")) {
	  // Swig_overload_rank expects wrap:name and wrap:parms to be
	  // set.
	  String *wn = Swig_name_wrapper(Getattr(on, "sym:name"));
	  Append(wn, Getattr(on, "sym:overname"));
	  Setattr(on, "wrap:name", wn);
	  Delete(wn);
	  Setattr(on, "wrap:parms", Getattr(on, "parms"));
	}
      }

      int r = oneClassDirectorMethod(n, parent, super);
      if (r != SWIG_OK) {
	return r;
      }

      if (!Getattr(n, "sym:nextSibling"))
      {
	// Last overloaded function
	Node *on = Getattr(n, "sym:overloaded");
	bool is_static = isStatic(on);

	String *cn = exportedName(Getattr(parent, "sym:name"));
	String *go_name = buildGoName(name, is_static, false);

	String *director_struct_name = NewString("_swig_Director");
	Append(director_struct_name, cn);

	int r = makeDispatchFunction(on, go_name, director_struct_name, is_static, director_struct_name, false);
	if (r != SWIG_OK) {
	  return r;
	}

	if (!GetFlag(n, "abstract")) {
	  String *go_upcall = NewString("Director");
	  Append(go_upcall, cn);
	  Append(go_upcall, go_name);
	  r = makeDispatchFunction(on, go_upcall, director_struct_name, is_static, director_struct_name, true);
	  if (r != SWIG_OK) {
	    return r;
	  }
	  Delete(go_upcall);
	}

	Delete(director_struct_name);
	Delete(go_name);
	Delete(cn);
      }
    }
    Setattr(class_methods, name, NewString(""));

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * oneClassDirectorMethod
   *
   * Emit a method for a director class.
   * ------------------------------------------------------------ */

  int oneClassDirectorMethod(Node *n, Node *parent, String *super) {
    String *symname = Getattr(n, "sym:name");
    if (!checkFunctionVisibility(n, parent)) {
      return SWIG_OK;
    }

    bool is_ignored = GetFlag(n, "feature:ignore") ? true : false;
    bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0);

    String *name = Getattr(n, "sym:name");
    if (!name) {
      assert(is_ignored);
      name = Getattr(n, "name");
    }

    String *overname = NULL;
    if (Getattr(n, "sym:overloaded")) {
      overname = Getattr(n, "sym:overname");
    }

    String *cn = exportedName(Getattr(parent, "sym:name"));

    String *go_type_name = goCPointerType(Getattr(parent, "classtypeobj"), true);

    String *director_struct_name = NewString("_swig_Director");
    Append(director_struct_name, cn);

    bool is_static = isStatic(n);

    String *go_name = buildGoName(name, is_static, false);

    ParmList *parms = Getattr(n, "parms");
    Setattr(n, "wrap:parms", parms);

    Wrapper *dummy = NewWrapper();
    emit_attach_parmmaps(parms, dummy);
    DelWrapper(dummy);

    Swig_typemap_attach_parms("gotype", parms, NULL);
    int parm_count = emit_num_arguments(parms);

    SwigType *result = Getattr(n, "type");

    // Save the type for overload processing.
    Setattr(n, "go:type", result);

    String *interface_name = NewString("_swig_DirectorInterface");
    Append(interface_name, cn);
    Append(interface_name, go_name);
    if (overname) {
      Append(interface_name, overname);
    }

    String *callback_name = Copy(director_struct_name);
    Append(callback_name, "_callback_");
    Append(callback_name, name);
    Replace(callback_name, "_swig", "Swig", DOH_REPLACE_FIRST);
    if (overname) {
      Append(callback_name, overname);
    }

    String *callback_wname = Swig_name_wrapper(callback_name);

    String *upcall_name = Copy(director_struct_name);
    Append(upcall_name, "_upcall_");
    Append(upcall_name, go_name);

    String *upcall_wname = Swig_name_wrapper(upcall_name);
    if (overname) {
      Append(upcall_wname, overname);
    }

    String *upcall_gc_name = buildGoWrapperName(upcall_name, overname);

    String *go_with_over_name = Copy(go_name);
    if (overname) {
      Append(go_with_over_name, overname);
    }

    Parm *p = 0;
    Wrapper *w = NewWrapper();

    Swig_director_parms_fixup(parms);

    Swig_typemap_attach_parms("directorin", parms, w);
    Swig_typemap_attach_parms("directorargout", parms, w);

    if (!is_ignored) {
      // We use an interface to see if this method is defined in Go.
      Printv(f_go_wrappers, "type ", interface_name, " interface {\n", NULL);
      Printv(f_go_wrappers, "\t", go_with_over_name, "(", NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	if (i > 0) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	String *tm = goType(p, Getattr(p, "type"));
	Printv(f_go_wrappers, tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ")", NULL);

      if (SwigType_type(result) != T_VOID) {
	String *tm = goType(n, result);
	Printv(f_go_wrappers, " ", tm, NULL);
	Delete(tm);
      }

      Printv(f_go_wrappers, "\n", NULL);
      Printv(f_go_wrappers, "}\n\n", NULL);

      if (!GetFlag(n, "abstract")) {
	// Declare the upcall function, which calls the method on the
	// parent class.

	if (gccgo_flag) {
	  Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL);
	}

	Printv(f_go_wrappers, "func ", upcall_gc_name, "(", go_type_name, NULL);

	p = parms;
	for (int i = 0; i < parm_count; ++i) {
	  p = getParm(p);
	  String *tm = goWrapperType(p, Getattr(p, "type"), false);
	  Printv(f_go_wrappers, ", ", tm, NULL);
	  Delete(tm);
	  p = nextParm(p);
	}

	Printv(f_go_wrappers, ")", NULL);

	if (SwigType_type(result) != T_VOID) {
	  String *tm = goWrapperType(n, result, true);
	  Printv(f_go_wrappers, " ", tm, NULL);
	  Delete(tm);
	}

	Printv(f_go_wrappers, "\n", NULL);
      }

      // Define the method on the director class in Go.

      Printv(f_go_wrappers, "func (swig_p *", director_struct_name, ") ", go_with_over_name, "(", NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	if (i > 0) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, Getattr(p, "lname"), " ", NULL);
	String *tm = goType(p, Getattr(p, "type"));
	Printv(f_go_wrappers, tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ")", NULL);

      if (SwigType_type(result) != T_VOID) {
	String *tm = goType(n, result);
	Printv(f_go_wrappers, " ", tm, NULL);
	Delete(tm);
      }

      Printv(f_go_wrappers, " {\n", NULL);

      Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", interface_name, "); swig_ok {\n", NULL);
      Printv(f_go_wrappers, "\t\t", NULL);
      if (SwigType_type(result) != T_VOID) {
	Printv(f_go_wrappers, "return ", NULL);
      }
      Printv(f_go_wrappers, "swig_g.", go_with_over_name, "(", NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	if (i > 0) {
	  Printv(f_go_wrappers, ", ", NULL);
	}
	Printv(f_go_wrappers, Getattr(p, "lname"), NULL);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ")\n", NULL);
      if (SwigType_type(result) == T_VOID) {
	Printv(f_go_wrappers, "\t\treturn\n", NULL);
      }
      Printv(f_go_wrappers, "\t}\n", NULL);

      if (GetFlag(n, "abstract")) {
	Printv(f_go_wrappers, "\tpanic(\"call to pure virtual method\")\n", NULL);
      } else {
	if (gccgo_flag) {
	  Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
	  Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
	}

	Printv(f_go_wrappers, "\t", NULL);
	if (SwigType_type(result) != T_VOID) {
	  Printv(f_go_wrappers, "return ", NULL);
	}
	Printv(f_go_wrappers, upcall_gc_name, "(swig_p.", go_type_name, NULL);

	p = parms;
	for (int i = 0; i < parm_count; ++i) {
	  p = getParm(p);
	  SwigType *pt = Getattr(p, "type");
	  Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL);
	  if (goTypeIsInterface(p, pt)) {
	    Printv(f_go_wrappers, ".Swigcptr()", NULL);
	  }
	  p = nextParm(p);
	}

	Printv(f_go_wrappers, ")\n", NULL);
      }

      Printv(f_go_wrappers, "}\n\n", NULL);

      // Define a method in the C++ director class that the C++ upcall
      // function can call.  This permits an upcall to a protected
      // method.

      if (!GetFlag(n, "abstract")) {
	String *upcall_method_name = NewString("_swig_upcall_");
	Append(upcall_method_name, name);
	if (overname) {
	  Append(upcall_method_name, overname);
	}
	SwigType *rtype = Getattr(n, "classDirectorMethods:type");
	String *upcall_decl = Swig_method_decl(rtype, Getattr(n, "decl"), upcall_method_name, parms, 0, 0);
	Printv(f_c_directors_h, "  ", upcall_decl, " {\n", NULL);
	Delete(upcall_decl);

	Printv(f_c_directors_h, "    ", NULL);
	if (SwigType_type(result) != T_VOID) {
	  Printv(f_c_directors_h, "return ", NULL);
	}

	String *super_call = Swig_method_call(super, parms);
	Printv(f_c_directors_h, super_call, ";\n", NULL);
	Delete(super_call);

	Printv(f_c_directors_h, "  }\n", NULL);

	// Define the C++ function that the Go function calls.

	SwigType *first_type = NULL;
	Parm *first_parm = parms;
	if (!is_static) {
	  first_type = NewString("SwigDirector_");
	  Append(first_type, class_name);
	  SwigType_add_pointer(first_type);
	  first_parm = NewParm(first_type, "p", n);
	  set_nextSibling(first_parm, parms);
	}

	Swig_save("classDirectorMethod", n, "wrap:name", "wrap:action", NULL);

	Setattr(n, "wrap:name", upcall_wname);

	String *action = NewString("");
	if (SwigType_type(result) != T_VOID) {
	  Printv(action, Swig_cresult_name(), " = (", SwigType_lstr(result, 0), ")", NULL);
	  if (SwigType_isreference(result)) {
	    Printv(action, "&", NULL);
	  }
	}
	Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", NULL);

	p = parms;
	int i = 0;
	while (p != NULL) {
	  if (SwigType_type(Getattr(p, "type")) != T_VOID) {
	    String *pname = Swig_cparm_name(NULL, i + 1);
	    if (i > 0) {
	      Printv(action, ", ", NULL);
	    }

	    // A parameter whose type is a reference is converted into a
	    // pointer type by gcCTypeForGoValue.  We are calling a
	    // function which expects a reference so we need to convert
	    // back.
	    if (SwigType_isreference(Getattr(p, "type"))) {
	      Printv(action, "*", NULL);
	    }

	    Printv(action, pname, NULL);
	    Delete(pname);
	    i++;
	  }
	  p = nextSibling(p);
	}
	Printv(action, ");", NULL);
	Setattr(n, "wrap:action", action);

	if (!gccgo_flag) {
	  // Write the upcall wrapper function.  This is compiled by gc
	  // and calls the C++ function.
	  int r = gcFunctionWrapper(n, upcall_name, upcall_name, overname, upcall_wname, first_parm, result, is_static, true);
	  if (r != SWIG_OK) {
	    return r;
	  }
	  r = gccFunctionWrapper(n, NULL, upcall_wname, first_parm, result);
	  if (r != SWIG_OK) {
	    return r;
	  }
	} else {
	  int r = gccgoFunctionWrapper(n, NULL, upcall_wname, first_parm, result);
	  if (r != SWIG_OK) {
	    return r;
	  }
	}

	Delete(first_type);
	if (first_parm != parms) {
	  Delete(first_parm);
	}

	Swig_restore(n);
	Delete(upcall_method_name);

	// Define a function that uses the Go director type that other
	// methods in the Go type can call to get parent methods.

	Printv(f_go_wrappers, "func Director", cn, go_with_over_name, "(p ", cn, NULL);

	p = parms;
	for (int i = 0; i < parm_count; ++i) {
	  p = getParm(p);
	  Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", NULL);
	  String *tm = goType(p, Getattr(p, "type"));
	  Printv(f_go_wrappers, tm, NULL);
	  Delete(tm);
	  p = nextParm(p);
	}

	Printv(f_go_wrappers, ")", NULL);

	if (SwigType_type(result) != T_VOID) {
	  String *tm = goType(n, result);
	  Printv(f_go_wrappers, " ", tm, NULL);
	  Delete(tm);
	}

	Printv(f_go_wrappers, " {\n", NULL);

	if (gccgo_flag) {
	  Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL);
	  Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL);
	}

	Printv(f_go_wrappers, "\t", NULL);
	if (SwigType_type(result) != T_VOID) {
	  Printv(f_go_wrappers, "return ", NULL);
	}
	Printv(f_go_wrappers, upcall_gc_name, "(p.(*", director_struct_name, ").", go_type_name, NULL);

	p = parms;
	for (int i = 0; i < parm_count; ++i) {
	  p = getParm(p);
	  SwigType *pt = Getattr(p, "type");
	  Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL);
	  if (goTypeIsInterface(p, pt)) {
	    Printv(f_go_wrappers, ".Swigcptr()", NULL);
	  }
	  p = nextParm(p);
	}

	Printv(f_go_wrappers, ")\n", NULL);
	Printv(f_go_wrappers, "}\n\n", NULL);
      }

      // The Go function which invokes the method.  This is called
      // from by the C++ method on the director class.

      Printv(f_go_wrappers, "func ", callback_name, "(p *", director_struct_name, NULL);

      p = parms;
      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	String *tm = goWrapperType(p, Getattr(p, "type"), false);
	Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", tm, NULL);
	Delete(tm);
	p = nextParm(p);
      }

      Printv(f_go_wrappers, ") ", NULL);
      String *result_wrapper = NULL;
      if (SwigType_type(result) != T_VOID) {
	result_wrapper = goWrapperType(n, result, true);
	Printv(f_go_wrappers, "(swig_result ", result_wrapper, ") ", NULL);
      }
      Printv(f_go_wrappers, "{\n", NULL);

      if (gccgo_flag) {
	Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL);
	Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL);
      }

      Printv(f_go_wrappers, "\t", NULL);

      if (is_ignored) {
	Printv(f_go_wrappers, "return\n", NULL);
      } else {
	bool result_is_interface = false;
	if (SwigType_type(result) != T_VOID) {
	  Printv(f_go_wrappers, "return ", NULL);
	  result_is_interface = goTypeIsInterface(NULL, result);
	  if (result_is_interface) {
	    Printv(f_go_wrappers, result_wrapper, "(", NULL);
	  }
	}
	Printv(f_go_wrappers, "p.", go_with_over_name, "(", NULL);

	p = parms;
	for (int i = 0; i < parm_count; ++i) {
	  p = getParm(p);
	  if (i > 0) {
	    Printv(f_go_wrappers, ", ", NULL);
	  }
	  SwigType *pt = Getattr(p, "type");

	  // If the Go representation is an interface type class, then
	  // we are receiving a uintptr, and must convert to the
	  // interface.
	  bool is_interface = goTypeIsInterface(p, pt);
	  if (is_interface) {
	    // Passing is_result as true to goWrapperType gives us the
	    // name of the Go type we need to convert to an interface.
	    String *wt = goWrapperType(p, pt, true);
	    Printv(f_go_wrappers, wt, "(", NULL);
	    Delete(wt);
	  }

	  Printv(f_go_wrappers, Getattr(p, "lname"), NULL);

	  if (is_interface) {
	    Printv(f_go_wrappers, ")", NULL);
	  }

	  p = nextParm(p);
	}

	Printv(f_go_wrappers, ")", NULL);

	if (result_is_interface) {
	  Printv(f_go_wrappers, ".Swigcptr())", NULL);
	}

	Printv(f_go_wrappers, "\n", NULL);
      }

      Printv(f_go_wrappers, "}\n\n", NULL);

      Delete(result_wrapper);

      Delete(upcall_wname);
      Delete(upcall_gc_name);

      // Build the C++ functions.

      if (!gccgo_flag) {
	Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL);
      } else {
	Printv(f_c_directors, "extern \"C\" ", NULL);

	String *fnname = NewString("");
	Printv(fnname, callback_wname, "(void*", NULL);

	p = parms;
	while (p) {
	  while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
	    p = Getattr(p, "tmap:directorin:next");
	  }
	  String *cg = gccgoCTypeForGoValue(p, Getattr(p, "type"),
					    Getattr(p, "lname"));
	  Printv(fnname, ", ", cg, NULL);
	  Delete(cg);
	  p = Getattr(p, "tmap:directorin:next");
	}

	Printv(fnname, ")", NULL);

	if (SwigType_type(result) == T_VOID) {
	  Printv(f_c_directors, "void ", fnname, NULL);
	} else {
	  String *tm = gccgoCTypeForGoValue(n, result, fnname);
	  Printv(f_c_directors, tm, NULL);
	  Delete(tm);
	}

	Delete(fnname);

	Printv(f_c_directors, " __asm__(\"", go_prefix, ".", callback_name, "\");\n", NULL);
      }

      Delete(go_with_over_name);
    }

    if (!is_ignored || is_pure_virtual) {
      // Declare the method for the director class.

      SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
      String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0);
      Printv(f_c_directors_h, "  virtual ", decl, NULL);
      Delete(decl);

      String *qname = NewString("");
      Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), NULL);
      decl = Swig_method_decl(rtype, Getattr(n, "decl"), qname, parms, 0, 0);
      Printv(w->def, decl, NULL);
      Delete(decl);
      Delete(qname);

      String *throws = buildThrow(n);
      if (throws) {
	Printv(f_c_directors_h, " ", throws, NULL);
	Printv(w->def, " ", throws, NULL);
	Delete(throws);
      }

      Printv(f_c_directors_h, ";\n", NULL);

      Printv(w->def, " {\n", NULL);

      if (SwigType_type(result) != T_VOID) {
	Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result"));
      }

      if (!is_ignored) {
	if (!gccgo_flag) {
	  Printv(w->code, "  struct {\n", NULL);
	  Printv(w->code, "    void *go_val;\n", NULL);

	  p = parms;
	  while (p) {
	    while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
	      p = Getattr(p, "tmap:directorin:next");
	    }
	    String *ln = Getattr(p, "lname");
	    String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), ln);
	    Printv(w->code, "      ", cg, ";\n", NULL);
	    Delete(cg);
	    p = Getattr(p, "tmap:directorin:next");
	  }
	  if (SwigType_type(result) != T_VOID) {
	    Printv(w->code, "    long : 0;\n", NULL);
	    String *rname = NewString(Swig_cresult_name());
	    String *cg = gcCTypeForGoValue(n, result, rname);
	    Printv(w->code, "    ", cg, ";\n", NULL);
	    Delete(cg);
	    Delete(rname);
	  }

	  Printv(w->code, "  } swig_a;\n", NULL);
	  Printv(w->code, "  swig_a.go_val = go_val;\n", NULL);

	  p = parms;
	  while (p) {
	    while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
	      p = Getattr(p, "tmap:directorin:next");
	    }
	    String *tm = Getattr(p, "tmap:directorin");
	    if (!tm) {
	      Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file,
			   line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0));
	    } else {
	      String *ln = Getattr(p, "lname");
	      String *input = NewString("");
	      Printv(input, "swig_a.", ln, NULL);
	      Setattr(p, "emit:directorinput", input);
	      Replaceall(tm, "$input", input);
	      Replaceall(tm, "$owner", "0");
	      Delete(input);
	      Printv(w->code, "\t", tm, "\n", NULL);
	    }
	    p = Getattr(p, "tmap:directorin:next");
	  }

	  Printv(w->code, "  crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL);

	  if (SwigType_type(result) != T_VOID) {
	    String *result_str = NewString("c_result");
	    String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL);
	    if (!tm) {
	      Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
			   "Unable to use type %s as director method result\n", SwigType_str(result, 0));
	    } else {
	      static const String *swig_a_result = NewStringf("swig_a.%s", Swig_cresult_name());
	      Replaceall(tm, "$input", swig_a_result);
	      Replaceall(tm, "$result", "c_result");
	      Printv(w->code, "  ", tm, "\n", NULL);
	      String *retstr = SwigType_rcaststr(result, "c_result");
	      Printv(w->code, "  return ", retstr, ";\n", NULL);
	      Delete(retstr);
	      Delete(tm);
	    }
	    Delete(result_str);
	  }

	  // The C wrapper code which calls the Go function.
	  Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", callback_wname, "\n", NULL);
	  Printv(f_gc_wrappers, "#pragma cgo_export_static ", callback_wname, " ", callback_wname, "\n", NULL);
	  Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL);
	  Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL);
	  Printv(f_gc_wrappers, "void\n", NULL);
	  Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL);
	  Printv(f_gc_wrappers, "{\n", NULL);
	  Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL);
	  Printv(f_gc_wrappers, "}\n\n", NULL);
	} else {
	  if (SwigType_type(result) != T_VOID) {
	    String *r = NewString(Swig_cresult_name());
	    String *tm = gccgoCTypeForGoValue(n, result, r);
	    Wrapper_add_local(w, r, tm);
	    Delete(tm);
	    Delete(r);
	  }

	  String *args = NewString("");

	  p = parms;
	  while (p) {
	    while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
	      p = Getattr(p, "tmap:directorin:next");
	    }

	    String *pn = NewString("g");
	    Append(pn, Getattr(p, "lname"));
	    Setattr(p, "emit:input", pn);

	    String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn);
	    Wrapper_add_local(w, pn, tm);
	    Delete(tm);

	    tm = Getattr(p, "tmap:directorin");
	    if (!tm) {
	      Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file,
			   line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0));
	    } else {
	      Replaceall(tm, "$input", pn);
	      Replaceall(tm, "$owner", 0);
	      Printv(w->code, "  ", tm, "\n", NULL);

	      Printv(args, ", ", pn, NULL);
	    }

	    p = Getattr(p, "tmap:directorin:next");
	  }

	  Printv(w->code, "  ", NULL);
	  if (SwigType_type(result) != T_VOID) {
	    Printv(w->code, Swig_cresult_name(), " = ", NULL);
	  }
	  Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL);

	  if (SwigType_type(result) != T_VOID) {
	    String *result_str = NewString("c_result");
	    String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL);
	    if (!tm) {
	      Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
			   "Unable to use type %s as director method result\n", SwigType_str(result, 0));
	    } else {
	      Replaceall(tm, "$input", Swig_cresult_name());
	      Replaceall(tm, "$result", "c_result");
	      Printv(w->code, "  ", tm, "\n", NULL);
	      String *retstr = SwigType_rcaststr(result, "c_result");
	      Printv(w->code, "  return ", retstr, ";\n", NULL);
	      Delete(retstr);
	      Delete(tm);
	    }
	    Delete(result_str);
	  }
	}

	/* Marshal outputs */
	for (p = parms; p;) {
	  String *tm;
	  if ((tm = Getattr(p, "tmap:directorargout"))) {
	    Replaceall(tm, "$result", "jresult");
	    Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
	    Printv(w->code, tm, "\n", NIL);
	    p = Getattr(p, "tmap:directorargout:next");
	  } else {
	    p = nextSibling(p);
	  }
	}
      } else {
	assert(is_pure_virtual);
	Printv(w->code, "  _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL);
	if (SwigType_type(result) != T_VOID) {
	  String *retstr = SwigType_rcaststr(result, "c_result");
	  Printv(w->code, "  return ", retstr, ";\n", NULL);
	  Delete(retstr);
	}
      }

      Printv(w->code, "}", NULL);

      Replaceall(w->code, "$symname", symname);
      Wrapper_print(w, f_c_directors);
    }

    Delete(cn);
    Delete(go_type_name);
    Delete(director_struct_name);
    Delete(interface_name);
    Delete(upcall_name);
    Delete(callback_wname);
    Delete(go_name);
    DelWrapper(w);

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classDirectorEnd
   *
   * Complete support for a director class.
   * ------------------------------------------------------------ */

  int classDirectorEnd(Node *n) {
    (void) n;

    Printv(f_c_directors_h, " private:\n", NULL);
    Printv(f_c_directors_h, "  void *go_val;\n", NULL);
    Printv(f_c_directors_h, "};\n\n", NULL);

    class_name = NULL;
    class_node = NULL;

    Delete(class_receiver);
    class_receiver = NULL;

    Delete(class_methods);
    class_methods = NULL;

    return SWIG_OK;
  }

  /* ------------------------------------------------------------
   * classDirectorDisown
   *
   * I think Go does not require a disown method.
   * ------------------------------------------------------------ */

  int classDirectorDisown(Node *n) {
    (void) n;
    return SWIG_OK;
  }

  /*----------------------------------------------------------------------
   * buildThrow()
   *
   * Build and return a throw clause if needed.
   *--------------------------------------------------------------------*/

  String *buildThrow(Node *n) {
    ParmList *throw_parm_list = Getattr(n, "throws");
    if (!throw_parm_list && !Getattr(n, "throw"))
      return NULL;
    String *ret = NewString("throw(");
    if (throw_parm_list) {
      Swig_typemap_attach_parms("throws", throw_parm_list, NULL);
    }
    bool first = true;
    for (Parm *p = throw_parm_list; p; p = nextSibling(p)) {
      if (Getattr(p, "tmap:throws")) {
	if (first) {
	  first = false;
	} else {
	  Printv(ret, ", ", NULL);
	}
	String *s = SwigType_str(Getattr(p, "type"), 0);
	Printv(ret, s, NULL);
	Delete(s);
      }
    }
    Printv(ret, ")", NULL);
    return ret;
  }

  /*----------------------------------------------------------------------
   * extraDirectorProtectedCPPMethodsRequired()
   *
   * We don't need to check upcall when calling methods.
   *--------------------------------------------------------------------*/

  bool extraDirectorProtectedCPPMethodsRequired() const {
    return false;
  }

  /*----------------------------------------------------------------------
   * makeDispatchFunction
   *
   * Make a dispatch function for an overloaded C++ function.  The
   * receiver parameter is the receiver for a method, unless is_upcall
   * is true.  If is_upcall is true, then the receiver parameter is
   * the type of the first argument to the function.
   *--------------------------------------------------------------------*/

  int makeDispatchFunction(Node *n, String *go_name, String *receiver, bool is_static, SwigType *director_struct, bool is_upcall) {
    bool is_director = director_struct ? true : false;

    String *nodetype = Getattr(n, "nodeType");
    bool is_constructor = Cmp(nodetype, "constructor") == 0;
    bool is_destructor = Cmp(nodetype, "destructor") == 0;

    bool can_use_receiver = (!is_constructor && !is_destructor && !is_upcall);

    bool use_receiver = (!is_static && can_use_receiver);

    bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !is_upcall);

    List *dispatch = Swig_overload_rank(n, false);
    int nfunc = Len(dispatch);

    SwigType *all_result;
    bool mismatch;
    if (is_constructor) {
      assert(!is_upcall);
      if (!is_director) {
	all_result = Copy(Getattr(class_node, "classtypeobj"));
      } else {
	all_result = Copy(director_struct);
      }
      mismatch = false;
    } else {
      all_result = NULL;
      mismatch = false;
      bool any_void = false;
      for (int i = 0; i < nfunc; ++i) {
	Node *nn = Getitem(dispatch, i);
	Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn;
	SwigType *result = Getattr(ni, "go:type");
	assert(result);

	if (SwigType_type(result) == T_VOID) {
	  if (all_result) {
	    mismatch = true;
	  }
	  any_void = true;
	} else {
	  if (any_void) {
	    mismatch = true;
	  } else if (!all_result) {
	    all_result = Copy(result);
	  } else if (Cmp(result, all_result) != 0) {
	    mismatch = true;
	  }
	}
      }
      if (mismatch) {
	Delete(all_result);
	all_result = NULL;
      } else if (all_result) {
	;
      } else {
	all_result = NewString("void");
      }
    }

    Printv(f_go_wrappers, "func ", NULL);

    if (receiver && use_receiver) {
      Printv(f_go_wrappers, "(p ", receiver, ") ", NULL);
    }

    Printv(f_go_wrappers, go_name, "(", NULL);
    if (is_director && is_constructor) {
      Printv(f_go_wrappers, "abi interface{}, ", NULL);
      assert(!add_to_interface);
    }
    if (is_upcall) {
      Printv(f_go_wrappers, "p *", receiver, ", ", NULL);
      assert(!add_to_interface);
    }
    Printv(f_go_wrappers, "a ...interface{})", NULL);

    if (add_to_interface) {
      Printv(interfaces, "\t", go_name, "(a ...interface{})", NULL);
    }

    if (mismatch) {
      Printv(f_go_wrappers, " interface{}", NULL);
      if (add_to_interface) {
	Printv(interfaces, " interface{}", NULL);
      }
    } else if (all_result && SwigType_type(all_result) != T_VOID) {
      if (is_director && is_constructor) {
	Printv(f_go_wrappers, " ", receiver, NULL);
	if (add_to_interface) {
	  Printv(interfaces, " ", receiver, NULL);
	}
      } else {
	String *tm = goType(n, all_result);
	Printv(f_go_wrappers, " ", tm, NULL);
	if (add_to_interface) {
	  Printv(interfaces, " ", tm, NULL);
	}
	Delete(tm);
      }
    }
    Printv(f_go_wrappers, " {\n", NULL);
    if (add_to_interface) {
      Printv(interfaces, "\n", NULL);
    }

    Printv(f_go_wrappers, "\targc := len(a)\n", NULL);

    for (int i = 0; i < nfunc; ++i) {
      int fn = 0;
      Node *nn = Getitem(dispatch, i);
      Node *ni = Getattr(nn, "directorNode") ? Getattr(nn, "directorNode") : nn;
      Parm *pi = Getattr(ni, "wrap:parms");

      // If we are using a receiver, we want to ignore a leading self
      // parameter.  Because of the way this is called, there may or
      // may not be a self parameter at this point.
      if (use_receiver && pi && Getattr(pi, "self")) {
	pi = getParm(pi);
	if (pi) {
	  pi = nextParm(pi);
	}
      }

      int num_required = emit_num_required(pi);
      int num_arguments = emit_num_arguments(pi);
      bool varargs = emit_isvarargs(pi) ? true : false;

      if (varargs) {
	Printf(f_go_wrappers, "\tif argc >= %d {\n", num_required);
      } else {
	if (num_required == num_arguments) {
	  Printf(f_go_wrappers, "\tif argc == %d {\n", num_required);
	} else {
	  Printf(f_go_wrappers, "\tif argc >= %d && argc <= %d {\n", num_required, num_arguments);
	}
      }

      // Build list of collisions with the same number of arguments.
      List *coll = NewList();
      for (int k = i + 1; k < nfunc; ++k) {
	Node *nnk = Getitem(dispatch, k);
	Node *nk = Getattr(nnk, "directorNode") ? Getattr(nnk, "directorNode") : nnk;
	Parm *pk = Getattr(nk, "wrap:parms");
	if (use_receiver && pk && Getattr(pk, "self")) {
	  pk = getParm(pk);
	  if (pk) {
	    pk = nextParm(pk);
	  }
	}
	int nrk = emit_num_required(pk);
	int nak = emit_num_arguments(pk);
	if ((nrk >= num_required && nrk <= num_arguments)
	    || (nak >= num_required && nak <= num_arguments)
	    || (nrk <= num_required && nak >= num_arguments)
	    || (varargs && nrk >= num_required)) {
	  Append(coll, nk);
	}
      }

      int num_braces = 0;
      if (Len(coll) > 0 && num_arguments > 0) {
	int j = 0;
	Parm *pj = pi;
	while (pj) {
	  pj = getParm(pj);
	  if (!pj) {
	    break;
	  }

	  // If all the wrappers have the same type in this position,
	  // we can omit the check.
	  SwigType *tm = goWrapperType(pj, Getattr(pj, "type"), true);
	  bool emitcheck = false;
	  for (int k = 0; k < Len(coll) && !emitcheck; ++k) {
	    Node *nk = Getitem(coll, k);
	    Parm *pk = Getattr(nk, "wrap:parms");
	    if (use_receiver && pk && Getattr(pk, "self")) {
	      pk = getParm(pk);
	      if (pk) {
		pk = nextParm(pk);
	      }
	    }
	    int nak = emit_num_arguments(pk);
	    if (nak <= j)
	      continue;
	    int l = 0;
	    Parm *pl = pk;
	    while (pl && l <= j) {
	      pl = getParm(pl);
	      if (!pl) {
		break;
	      }
	      if (l == j) {
		SwigType *tml = goWrapperType(pl, Getattr(pl, "type"), true);
		if (Cmp(tm, tml) != 0) {
		  emitcheck = true;
		}
		Delete(tml);
	      }
	      pl = nextParm(pl);
	      ++l;
	    }
	  }

	  if (emitcheck) {
	    if (j >= num_required) {
	      Printf(f_go_wrappers, "\t\tif argc > %d {\n", j);
	      ++num_braces;
	    }

	    fn = i + 1;
	    Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, tm);
	    Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn);
	    Printv(f_go_wrappers, "\t\t}\n", NULL);
	  }

	  Delete(tm);

	  pj = nextParm(pj);

	  ++j;
	}
      }

      for (; num_braces > 0; --num_braces) {
	Printv(f_go_wrappers, "\t\t}\n", NULL);
      }

      // We may need to generate multiple calls if there are variable
      // argument lists involved.  Build the start of the call.

      String *start = NewString("");

      SwigType *result = Getattr(ni, "go:type");

      if (is_constructor) {
	result = all_result;
      } else if (is_destructor) {
	result = NULL;
      }

      if (result && SwigType_type(result) != T_VOID && (!all_result || SwigType_type(all_result) != T_VOID)) {
	Printv(start, "return ", NULL);
      }

      bool advance_parm = false;

      if (receiver && use_receiver) {
	Printv(start, "p.", go_name, NULL);
      } else if (can_use_receiver && !isStatic(ni) && pi && Getattr(pi, "self")) {
	// This is an overload of a static function and a non-static
	// function.
	assert(num_required > 0);
	SwigType *tm = goWrapperType(pi, Getattr(pi, "type"), true);
	String *nm = buildGoName(Getattr(ni, "sym:name"), false, isFriend(ni));
	Printv(start, "a[0].(", tm, ").", nm, NULL);
	Delete(nm);
	Delete(tm);
	advance_parm = true;
      } else {
	Printv(start, go_name, NULL);
      }

      Printv(start, Getattr(ni, "sym:overname"), "(", NULL);

      bool need_comma = false;

      if (is_director && is_constructor) {
	Printv(start, "abi", NULL);
	need_comma = true;
      }
      if (is_upcall) {
	Printv(start, "p", NULL);
	need_comma = true;
      }
      Parm *p = pi;
      int pn = 0;
      if (advance_parm) {
	p = getParm(p);
	if (p) {
	  p = nextParm(p);
	}
	++pn;
      }
      while (pn < num_required) {
	p = getParm(p);

	if (need_comma) {
	  Printv(start, ", ", NULL);
	}

	SwigType *tm = goType(p, Getattr(p, "type"));
	Printf(start, "a[%d].(%s)", pn, tm);
	Delete(tm);

	need_comma = true;
	++pn;
	p = nextParm(p);
      }

      String *end = NULL;
      if (!result || SwigType_type(result) == T_VOID || (all_result && SwigType_type(all_result) == T_VOID)) {
	end = NewString("");
	Printv(end, "return", NULL);
	if (!all_result || SwigType_type(all_result) != T_VOID) {
	  Printv(end, " 0", NULL);
	}
      }

      if (num_required == num_arguments) {
	Printv(f_go_wrappers, "\t\t", start, ")\n", NULL);
	if (end) {
	  Printv(f_go_wrappers, "\t\t", end, "\n", NULL);
	}
      } else {
	Printv(f_go_wrappers, "\t\tswitch argc {\n", NULL);
	for (int j = num_required; j <= num_arguments; ++j) {
	  Printf(f_go_wrappers, "\t\tcase %d:\n", j);
	  Printv(f_go_wrappers, "\t\t\t", start, NULL);
	  bool nc = need_comma;
	  for (int k = num_required; k < j; ++k) {
	    if (nc) {
	      Printv(f_go_wrappers, ", ", NULL);
	    }
	    Printf(f_go_wrappers, "a[%d]", k);
	    nc = true;
	  }
	  Printv(f_go_wrappers, ")\n", NULL);
	  if (end) {
	    Printv(f_go_wrappers, "\t\t\t", end, "\n", NULL);
	  }
	}
	Printv(f_go_wrappers, "\t\t}\n", NULL);
      }

      Printv(f_go_wrappers, "\t}\n", NULL);

      if (fn != 0) {
	Printf(f_go_wrappers, "check_%d:\n", fn);
      }

      Delete(coll);
    }

    Printv(f_go_wrappers, "\tpanic(\"No match for overloaded function call\")\n", NULL);
    Printv(f_go_wrappers, "}\n\n", NULL);

    Delete(all_result);
    Delete(dispatch);

    return SWIG_OK;
  }

  /* ----------------------------------------------------------------------
   * checkFunctionVisibility()
   *
   * Return true if we should write out a function based on its
   * visibility, false otherwise.
   * ---------------------------------------------------------------------- */

  bool checkFunctionVisibility(Node *n, Node *parent) {
    // Write out a public function.
    if (is_public(n))
      return true;
    // Don't write out a private function.
    if (is_private(n))
      return false;
    // Write a protected function for a director class in
    // dirprot_mode.
    if (parent == NULL) {
      return false;
    }
    if (dirprot_mode() && Swig_directorclass(parent))
      return true;
    // Otherwise don't write out a protected function.
    return false;
  }


  /* ----------------------------------------------------------------------
   * exportedName()
   *
   * Given a C/C++ name, return a name in Go which will be exported.
   * If the first character is an upper case letter, this returns a
   * copy of its argment.  If the first character is a lower case
   * letter, this forces it to upper case.  Otherwise, this prepends
   * 'X'.
   * ---------------------------------------------------------------------- */

  String *exportedName(String *name) {
    String *copy = Copy(name);
    char c = *Char(copy);
    if (islower(c)) {
      char l[2];
      char u[2];
      l[0] = c;
      l[1] = '\0';
      u[0] = toupper(c);
      u[1] = '\0';
      Replace(copy, l, u, DOH_REPLACE_FIRST);
    } else if (!isalpha(c)) {
      char l[2];
      char u[3];
      l[0] = c;
      l[1] = '\0';
      u[0] = 'X';
      u[1] = c;
      u[2] = '\0';
      Replace(copy, l, u, DOH_REPLACE_FIRST);
    }
    String *ret = Swig_name_mangle(copy);
    Delete(copy);
    return ret;
  }

  /* ----------------------------------------------------------------------
   * removeClassname()
   *
   * If the name starts with the current class name, followed by an
   * underscore, remove it.  If there is no current class name, this
   * simply returns a copy of the name.  This undoes Swig's way of
   * recording the class name in a member name.
   * ---------------------------------------------------------------------- */

  String *removeClassname(String *name) {
    String *copy = Copy(name);
    if (class_name) {
      char *p = Char(name);
      if (Strncmp(name, class_name, Len(class_name)) == 0 && p[Len(class_name)] == '_') {
	Replace(copy, class_name, "", DOH_REPLACE_FIRST);
	Replace(copy, "_", "", DOH_REPLACE_FIRST);
      }
    }
    return copy;
  }

  /* ----------------------------------------------------------------------
   * buildGoName()
   *
   * Build the name to use for an ordinary function, variable, or
   * whatever in Go.  The name argument is something like the sym:name
   * attribute of the node.  If is_static is false, this could be a
   * method, and the returned name will be the name of the
   * method--i.e., it will not include the class name.
   * ---------------------------------------------------------------------- */

  String *buildGoName(String *name, bool is_static, bool is_friend) {
    String *nw = NewString("");
    if (is_static && !is_friend && class_name) {
      String *c1 = exportedName(class_name);
      Append(nw, c1);
      Delete(c1);
    }
    String *c2 = removeClassname(name);
    String *c3 = exportedName(c2);
    Append(nw, c3);
    Delete(c2);
    Delete(c3);
    String *ret = Swig_name_mangle(nw);
    Delete(nw);
    return ret;
  }

  /* ----------------------------------------------------------------------
   * buildGoWrapperName()
   *
   * Build the name to use for a Go wrapper function.  This is a
   * function called by the real Go function in order to convert C++
   * classes from interfaces to pointers, and other such conversions
   * between the Go type and the C++ type.
   * ---------------------------------------------------------------------- */

  String *buildGoWrapperName(String *name, String *overname) {
    String *s1 = NewString("_swig_wrap_");
    Append(s1, name);
    String *s2 = Swig_name_mangle(s1);
    Delete(s1);
    if (overname) {
      Append(s2, overname);
    }
    return s2;
  }

  /* ----------------------------------------------------------------------
   * checkNameConflict()
   *
   * Check for a name conflict on the name we are going to use in Go.
   * These conflicts are likely because of the enforced
   * capitalization.  When we find one, issue a warning and return
   * false.  If the name is OK, return true.
   * ---------------------------------------------------------------------- */

  bool checkNameConflict(String* name, Node* n, const_String_or_char_ptr scope) {
    Node *lk = symbolLookup(name, scope);
    if (lk) {
      String *n1 = Getattr(n, "sym:name");
      if (!n1) {
	n1 = Getattr(n, "name");
      }
      String *n2 = Getattr(lk, "sym:name");
      if (!n2) {
	n2 = Getattr(lk, "name");
      }
      Swig_warning(WARN_GO_NAME_CONFLICT, input_file, line_number,
		   "Ignoring '%s' due to Go name ('%s') conflict with '%s'\n",
		   n1, name, n2);
      return false;
    }
    bool r = addSymbol(name, n, scope) ? true : false;
    assert(r);
    return true;
  }

  /* ----------------------------------------------------------------------
   * checkIgnoredParameters()
   *
   * If any of the parameters of this function, or the return type,
   * are ignored due to a name conflict, give a warning and return
   * false.
   * ---------------------------------------------------------------------- */

  bool checkIgnoredParameters(Node *n, String *go_name) {
    ParmList *parms = Getattr(n, "parms");
    if (parms) {
      Wrapper *dummy = NewWrapper();
      emit_attach_parmmaps(parms, dummy);
      int parm_count = emit_num_arguments(parms);
      Parm *p = parms;

      for (int i = 0; i < parm_count; ++i) {
	p = getParm(p);
	if (!checkIgnoredType(n, go_name, Getattr(p, "type"))) {
	  DelWrapper(dummy);
	  return false;
	}
	p = nextParm(p);
      }

      DelWrapper(dummy);
    }

    if (!checkIgnoredType(n, go_name, Getattr(n, "type"))) {
      return false;
    }

    return true;
  }

  /* ----------------------------------------------------------------------
   * checkIgnoredType()
   *
   * If this type is being ignored due to a name conflict, give a
   * warning and return false.
   * ---------------------------------------------------------------------- */

  bool checkIgnoredType(Node *n, String *go_name, SwigType *type) {
    if (hasGoTypemap(n, type)) {
      return true;
    }

    SwigType *t = SwigType_typedef_resolve_all(type);

    bool ret = true;
    bool is_conflict = false;
    Node *e = Language::enumLookup(t);
    if (e) {
      if (GetFlag(e, "go:conflict")) {
	is_conflict = true;
      }
    } else if (SwigType_issimple(t)) {
      Node *cn = classLookup(t);
      if (cn) {
	if (GetFlag(cn, "go:conflict")) {
	  is_conflict = true;
	}
      }
    } else if (SwigType_ispointer(t) || SwigType_isarray(t) || SwigType_isqualifier(t) || SwigType_isreference(t)) {
      SwigType *r = Copy(t);
      if (SwigType_ispointer(r)) {
	SwigType_del_pointer(r);
      } else if (SwigType_isarray(r)) {
	SwigType_del_array(r);
      } else if (SwigType_isqualifier(r)) {
	SwigType_del_qualifier(r);
      } else {
	SwigType_del_reference(r);
      }

      if (!checkIgnoredType(n, go_name, r)) {
	ret = false;
      }

      Delete(r);
    }

    if (is_conflict) {
      String *s = SwigType_str(t, NULL);
      Swig_warning(WARN_GO_NAME_CONFLICT, input_file, line_number,
		   "Ignoring '%s' (Go name '%s') due to Go name conflict for parameter or result type '%s'\n",
		   Getattr(n, "name"), go_name, s);
      Delete(s);
      ret = false;
    }

    Delete(t);

    return ret;
  }

  /* ----------------------------------------------------------------------
   * goType()
   *
   * Given a SWIG type, return a string for the type in Go.
   * ---------------------------------------------------------------------- */

  String *goType(Node *n, SwigType *type) {
    return goTypeWithInfo(n, type, NULL);
  }

  /* ----------------------------------------------------------------------
   * goTypeWithInfo()
   *
   * Like goType, but return some more information.
   *
   * If the p_is_interface parameter is not NULL, this sets
   * *p_is_interface to indicate whether this type is going to be
   * represented by a Go interface type.  These are cases where the Go
   * code needs to make some adjustments when passing values back and
   * forth with C/C++.
   * ---------------------------------------------------------------------- */

  String *goTypeWithInfo(Node *n, SwigType *type, bool *p_is_interface) {
    if (p_is_interface) {
      *p_is_interface = false;
    }

    String *ret;
    if (n && Cmp(type, Getattr(n, "type")) == 0) {
      ret = NULL;
      if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) {
	ret = Getattr(n, "tmap:gotype");
      }
      if (!ret) {
	ret = Swig_typemap_lookup("gotype", n, "", NULL);
      }
    } else {
      Parm *p = NewParm(type, "goType", n);
      ret = Swig_typemap_lookup("gotype", p, "", NULL);
      Delete(p);
    }

    if (ret && Strstr(ret, "$gotypename") != 0) {
      ret = NULL;
    }

    if (ret) {
      return Copy(ret);
    }

    SwigType *t = SwigType_typedef_resolve_all(type);

    if (SwigType_isenum(t)) {
      Node *e = Language::enumLookup(t);
      if (e) {
	ret = goEnumName(e);
      } else if (Strcmp(t, "enum ") == 0) {
	ret = NewString("int");
      } else {
	// An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition) or an ignored enum
	String *tt = Copy(t);
	Replace(tt, "enum ", "", DOH_REPLACE_ANY);
	ret = exportedName(tt);
	Setattr(undefined_enum_types, t, ret);
	Delete(tt);
      }
    } else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) {
      ret = NewString("_swig_fnptr");
    } else if (SwigType_ismemberpointer(type)) {
      ret = NewString("_swig_memberptr");
    } else if (SwigType_issimple(t)) {
      Node *cn = classLookup(t);
      if (cn) {
	ret = Getattr(cn, "sym:name");
	if (!ret) {
	  ret = Getattr(cn, "name");
	}
	ret = exportedName(ret);

	Node *cnmod = Getattr(cn, "module");
	if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) {
	  Setattr(undefined_types, t, t);
	} else {
	  String *nw = NewString("");
	  Printv(nw, Getattr(cnmod, "name"), ".", ret, NULL);
	  Delete(ret);
	  ret = nw;
	}
      } else {
	// SWIG does not know about this type.
	ret = exportedName(t);
	Setattr(undefined_types, t, t);
      }
      if (p_is_interface) {
	*p_is_interface = true;
      }
    } else if (SwigType_ispointer(t) || SwigType_isarray(t)) {
      SwigType *r = Copy(t);
      if (SwigType_ispointer(r)) {
	SwigType_del_pointer(r);
      } else {
	SwigType_del_array(r);
      }

      if (SwigType_type(r) == T_VOID) {
	ret = NewString("uintptr");
      } else {
	bool is_interface;
	String *base = goTypeWithInfo(n, r, &is_interface);

	// At the Go level, an unknown or class type is handled as an
	// interface wrapping a pointer.  This means that if a
	// function returns the C type X, we will be wrapping the C
	// type X*.  In Go we will call that type X.  That means that
	// if a C function expects X*, we can pass the Go type X.  And
	// that means that when we see the C type X*, we should use
	// the Go type X.

	// The is_interface variable tells us this.  However, it will
	// be true both for the case of X and for the case of X*.  If
	// r is a pointer here, then we are looking at X**.  There is
	// really no good way for us to handle that.
	bool is_pointer_to_pointer = false;
	if (is_interface) {
	  SwigType *c = Copy(r);
	  if (SwigType_isqualifier(c)) {
	    SwigType_del_qualifier(c);
	    if (SwigType_ispointer(c) || SwigType_isarray(c)) {
	      is_pointer_to_pointer = true;
	    }
	  }
	  Delete(c);
	}

	if (is_interface) {
	  if (!is_pointer_to_pointer) {
	    ret = base;
	    if (p_is_interface) {
	      *p_is_interface = true;
	    }
	  } else {
	    ret = NewString("uintptr");
	  }
	} else {
	  ret = NewString("*");
	  Append(ret, base);
	  Delete(base);
	}
      }

      Delete(r);
    } else if (SwigType_isreference(t)) {
      SwigType *r = Copy(t);
      SwigType_del_reference(r);

      // If this is a const reference, and we are looking at a pointer
      // to it, then we just use the pointer we already have.
      bool add_pointer = true;
      if (SwigType_isqualifier(r)) {
	String *q = SwigType_parm(r);
	if (Strcmp(q, "const") == 0) {
	  SwigType *c = Copy(r);
	  SwigType_del_qualifier(c);
	  if (SwigType_ispointer(c)) {
	    add_pointer = false;
	  }
	  Delete(c);
	}
      }
      if (add_pointer) {
	SwigType_add_pointer(r);
      }
      ret = goTypeWithInfo(n, r, p_is_interface);
      Delete(r);
    } else if (SwigType_isqualifier(t)) {
      SwigType *r = Copy(t);
      SwigType_del_qualifier(r);
      ret = goTypeWithInfo(n, r, p_is_interface);
      Delete(r);
    } else if (SwigType_isvarargs(t)) {
      ret = NewString("[]interface{}");
    }

    Delete(t);

    if (!ret) {
      Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, "No Go typemap defined for %s\n", SwigType_str(type, 0));
      ret = NewString("uintptr");
    }

    return ret;
  }

  /* ----------------------------------------------------------------------
   * goWrapperType()
   *
   * Given a type, return a string for the type to use for the wrapped
   * Go function.  This function exists because for a C++ class we
   * need to convert interface and reference types.
   * ---------------------------------------------------------------------- */

  String *goWrapperType(Node *n, SwigType *type, bool is_result) {
    bool is_interface;
    String *ret = goTypeWithInfo(n, type, &is_interface);

    // If this is an interface, we want to pass the real type.
    if (is_interface) {
      Delete(ret);
      if (!is_result) {
	ret = NewString("uintptr");
      } else {
	SwigType *ty = SwigType_typedef_resolve_all(type);
	while (true) {
	  if (SwigType_ispointer(ty)) {
	    SwigType_del_pointer(ty);
	  } else if (SwigType_isarray(ty)) {
	    SwigType_del_array(ty);
	  } else if (SwigType_isreference(ty)) {
	    SwigType_del_reference(ty);
	  } else if (SwigType_isqualifier(ty)) {
	    SwigType_del_qualifier(ty);
	  } else {
	    break;
	  }
	}
	assert(SwigType_issimple(ty));
	String *p = goCPointerType(ty, true);
	Delete(ty);
	ret = p;
      }
    }

    return ret;
  }

  /* ----------------------------------------------------------------------
   * goCPointerType()
   *
   * Return the name of the Go type to use for the C pointer value.
   * The regular C type is the name of an interface type which wraps a
   * pointer whose name is returned by this function.
   * ---------------------------------------------------------------------- */

  String *goCPointerType(SwigType *type, bool add_to_hash) {
    SwigType *ty = SwigType_typedef_resolve_all(type);
    Node *cn = classLookup(ty);
    String *ex;
    String *ret;
    if (!cn) {
      if (add_to_hash) {
	Setattr(undefined_types, ty, ty);
      }
      ret = NewString("Swigcptr");
      ex = exportedName(ty);
      Append(ret, ex);
    } else {
      String *cname = Getattr(cn, "sym:name");
      if (!cname) {
	cname = Getattr(cn, "name");
      }
      ex = exportedName(cname);
      Node *cnmod = Getattr(cn, "module");
      if (!cnmod || Strcmp(Getattr(cnmod, "name"), module) == 0) {
	if (add_to_hash) {
	  Setattr(undefined_types, ty, ty);
	}
	ret = NewString("Swigcptr");
	Append(ret, ex);
      } else {
	ret = NewString("");
	Printv(ret, Getattr(cnmod, "name"), ".Swigcptr", ex, NULL);
      }
    }
    Delete(ty);
    Delete(ex);
    return ret;
  }

  /* ----------------------------------------------------------------------
   * gcCTypeForGoValue()
   *
   * Given a type, return the C/C++ type which will be used to catch
   * the value in Go.  This is the 6g/8g version.
   * ---------------------------------------------------------------------- */

  String *gcCTypeForGoValue(Node *n, SwigType *type, String *name) {
    bool is_interface;
    String *gt = goTypeWithInfo(n, type, &is_interface);
    bool is_string = Strcmp(gt, "string") == 0;
    bool is_slice = Strncmp(gt, "[]", 2) == 0;
    bool is_function = Strcmp(gt, "_swig_fnptr") == 0;
    bool is_member = Strcmp(gt, "_swig_memberptr") == 0;
    bool is_complex64 = Strcmp(gt, "complex64") == 0;
    bool is_complex128 = Strcmp(gt, "complex128") == 0;
    bool is_int8 = false;
    bool is_int16 = false;
    bool is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "uint") == 0;
    bool is_int32 = false;
    bool is_int64 = false;
    bool is_float32 = false;
    bool is_float64 = false;
    if ((n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(n, type)) {
      is_int8 = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0;
      is_int16 = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0;
      is_int32 = Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0;
      is_int64 = Strcmp(gt, "int64") == 0 || Strcmp(gt, "uint64") == 0;
      is_float32 = Strcmp(gt, "float32") == 0;
      is_float64 = Strcmp(gt, "float64") == 0;
    }
    Delete(gt);

    String *ret;
    if (is_string) {
      // Note that we don't turn a reference to a string into a
      // pointer to a string.  Strings are immutable anyhow.
      ret = NewString("_gostring_ ");
      Append(ret, name);
      return ret;
    } else if (is_slice) {
      // Slices are always passed as a _goslice_, whether or not references
      // are involved.
      ret = NewString("_goslice_ ");
      Append(ret, name);
      return ret;
    } else if (is_function || is_member) {
      ret = NewString("void *");
      Append(ret, name);
      return ret;
    } else if (is_complex64) {
      ret = NewString("_Complex float ");
    } else if (is_complex128) {
      ret = NewString("_Complex double ");
    } else if (is_interface) {
      SwigType *t = SwigType_typedef_resolve_all(type);
      if (SwigType_ispointer(t)) {
	SwigType_del_pointer(t);
      }
      if (SwigType_isreference(t)) {
	SwigType_del_reference(t);
      }
      SwigType_add_pointer(t);
      ret = SwigType_lstr(t, name);
      Delete(t);
      return ret;
    } else {
      SwigType *t = SwigType_typedef_resolve_all(type);
      if (SwigType_isreference(t)) {
	// A const reference to a known type, or to a pointer, is not
	// mapped to a pointer.
	SwigType_del_reference(t);
	if (SwigType_isqualifier(t)) {
	  String *q = SwigType_parm(t);
	  if (Strcmp(q, "const") == 0) {
	    SwigType_del_qualifier(t);
	    if (hasGoTypemap(n, t) || SwigType_ispointer(t)) {
	      if (is_int) {
		ret = NewString("intgo ");
		Append(ret, name);
	      } else if (is_int64) {
		ret = NewString("long long ");
		Append(ret, name);
	      } else {
		ret = SwigType_lstr(t, name);
	      }
	      Delete(q);
	      Delete(t);
	      return ret;
	    }
	  }
	  Delete(q);
	}
      }

      if (Language::enumLookup(t) != NULL) {
	is_int = true;
      } else {
	SwigType *tstripped = SwigType_strip_qualifiers(t);
	if (SwigType_isenum(tstripped))
	  is_int = true;
	Delete(tstripped);
      }

      Delete(t);
      if (is_int8) {
	ret = NewString("char ");
      } else if (is_int16) {
	ret = NewString("short ");
      } else if (is_int) {
	ret = NewString("intgo ");
      } else if (is_int32) {
	ret = NewString("int ");
      } else if (is_int64) {
	ret = NewString("long long ");
      } else if (is_float32) {
	ret = NewString("float ");
      } else if (is_float64) {
	ret = NewString("double ");
      } else {
	return SwigType_lstr(type, name);
      }
    }

    if (SwigType_isreference(type)) {
      Append(ret, "* ");
    }
    Append(ret, name);
    return ret;
  }

  /* ----------------------------------------------------------------------
   * gccgoCTypeForGoValue()
   *
   * Given a type, return the C/C++ type which will be used to catch
   * the value in Go.  This is the gccgo version.
   * ---------------------------------------------------------------------- */

  String *gccgoCTypeForGoValue(Node *n, SwigType *type, String *name) {
    return gcCTypeForGoValue(n, type, name);
  }

  /* ----------------------------------------------------------------------
   * goTypeIsInterface
   *
   * Return whether this C++ type is represented as an interface type
   * in Go.  These types require adjustments in the Go code when
   * passing them back and forth between Go and C++.
   * ---------------------------------------------------------------------- */

  bool goTypeIsInterface(Node *n, SwigType *type) {
    bool is_interface;
    Delete(goTypeWithInfo(n, type, &is_interface));
    return is_interface;
  }

  /* ----------------------------------------------------------------------
   * hasGoTypemap
   *
   * Return whether a type has a "gotype" typemap entry.
   * ---------------------------------------------------------------------- */

  bool hasGoTypemap(Node *n, SwigType *type) {
    Parm *p = NewParm(type, "test", n);
    SwigType *tm = Swig_typemap_lookup("gotype", p, "", NULL);
    Delete(p);
    if (tm && Strstr(tm, "$gotypename") == 0) {
      Delete(tm);
      return true;
    }
    Delete(tm);
    return false;
  }

  /* ----------------------------------------------------------------------
   * goEnumName()
   *
   * Given an enum node, return a string to use for the enum type in Go.
   * ---------------------------------------------------------------------- */

  String *goEnumName(Node *n) {
    String *ret = Getattr(n, "go:enumname");
    if (ret) {
      return Copy(ret);
    }

    if (Equal(Getattr(n, "type"), "enum ")) {
      return NewString("int");
    }

    String *type = Getattr(n, "enumtype");
    assert(type);
    char *p = Char(type);
    int len = Len(type);
    String *s = NewString("");
    bool capitalize = true;
    for (int i = 0; i < len; ++i, ++p) {
      if (*p == ':') {
	++i;
	++p;
	assert(*p == ':');
	capitalize = true;
      } else if (capitalize) {
	Putc(toupper(*p), s);
	capitalize = false;
      } else {
	Putc(*p, s);
      }
    }

    ret = Swig_name_mangle(s);
    Delete(s);
    return ret;
  }


  /* ----------------------------------------------------------------------
   * getParm()
   *
   * Get the real parameter to use.
   * ---------------------------------------------------------------------- */

  Parm *getParm(Parm *p) {
    while (p && checkAttribute(p, "tmap:in:numinputs", "0")) {
      p = Getattr(p, "tmap:in:next");
    }
    return p;
  }

  /* ----------------------------------------------------------------------
   * nextParm()
   *
   * Return the next parameter.
   * ---------------------------------------------------------------------- */

  Parm *nextParm(Parm *p) {
    if (!p) {
      return NULL;
    } else if (Getattr(p, "tmap:in")) {
      return Getattr(p, "tmap:in:next");
    } else {
      return nextSibling(p);
    }
  }

  /* ----------------------------------------------------------------------
   * isStatic
   *
   * Return whether a node should be considered as static rather than
   * as a member.
   * ---------------------------------------------------------------------- */

  bool isStatic(Node *n) {
    String *storage = Getattr(n, "storage");
    return (storage && (Swig_storage_isstatic(n) || Strcmp(storage, "friend") == 0) && (!SmartPointer || !Getattr(n, "allocate:smartpointeraccess")));
  }

  /* ----------------------------------------------------------------------
   * isFriend
   *
   * Return whether a node is a friend.
   * ---------------------------------------------------------------------- */

  bool isFriend(Node *n) {
    String *storage = Getattr(n, "storage");
    return storage && Strcmp(storage, "friend") == 0;
  }

};				/* class GO */

/* -----------------------------------------------------------------------------
 * swig_go()    - Instantiate module
 * ----------------------------------------------------------------------------- */

static Language *new_swig_go() {
  return new GO();
}
extern "C" Language *swig_go(void) {
  return new_swig_go();
}

/* -----------------------------------------------------------------------------
 * Static member variables
 * ----------------------------------------------------------------------------- */

// Usage message.
const char * const GO::usage = "\
Go Options (available with -go)\n\
     -gccgo              - Generate code for gccgo rather than 6g/8g\n\
     -go-pkgpath <p>     - Like gccgo -fgo-pkgpath option\n\
     -go-prefix <p>      - Like gccgo -fgo-prefix option\n\
     -intgosize <s>      - Set size of Go int type--32 or 64 bits\n\
     -package <name>     - Set name of the Go package to <name>\n\
     -use-shlib          - Force use of a shared library\n\
     -soname <name>      - Set shared library holding C/C++ code to <name>\n\
\n";