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
  
#! /usr/bin/env pike 
 
#if __REAL_VERSION__ < 7.8 
#error Pike binary is too old to be used for precompile. 
#error At least 7.8 is required. 
#endif 
 
#pike __REAL_VERSION__ 
 
#define TOSTR(X) #X 
#define DEFINETOSTR(X) TOSTR(X) 
 
#if constant(Pike.__HAVE_CPP_PREFIX_SUPPORT__) 
constant precompile_api_version = "6"; 
#else 
constant precompile_api_version = "3"; 
#endif 
 
constant want_args = 1; 
 
//! Convert .cmod-files to .c files. 
 
constant description = "Converts .cmod-files to .c files"; 
 
mapping map_types = ([]), need_obj_defines = ([]); 
 
string usage = #"[options] <from> > <to> 
 
 
 This script is used to process *.cmod files into *.c files, it 
 reads Pike style prototypes and converts them into C code. 
 
 Supported options are: 
 
   -h,--help     Display this help text. 
 
   -v,--version  Display the API version. 
 
   --api         Set the API version. 
 
   -b,--base     Set the base name for the file. 
 
   -o,--out      Set the output filename. 
 
   -w,--warnings Enable warnings. 
 
 The input can look something like this: 
 
 DECLARATIONS 
 
 PIKECLASS fnord 
  attributes; 
 { 
   INHERIT bar 
     attributes; 
 
   INHERIT \"__builtin.foo\" 
     attributes; 
 
   CVAR int foo; 
   PIKEVAR mapping m 
     attributes; 
 
   DECLARE_STORAGE; // optional 
 
   PIKEFUN int function_name (int x, CTYPE char * foo) 
    attribute; 
    attribute value; 
   { 
     C code using 'x' and 'foo'. 
 
     RETURN x; 
   } 
 
   INIT 
   { 
     // Object initialization code. 
   } 
 
   EXIT 
     gc_trivial; 
   { 
     // Object cleanup code. 
   } 
 
   GC_RECURSE 
   { 
     // Code to run under the gc recurse pass. 
   } 
 
   GC_CHECK 
   { 
     // Code to run under the gc check pass. 
   } 
 
   EXTRA 
   { 
     // Code for adding extra constants etc. 
   } 
 
   OPTIMIZE 
   { 
     // Code for optimizing calls that clone the class. 
     // The node for the call is available in the variable n. 
   } 
 } 
 
 All the begin_class/ADD_EFUN/ADD_FUNCTION calls will be inserted 
 instead of the word INIT in your code. 
 
 The corresponding cleanup code will be inserted instead of the word EXIT. 
 
 Argument count checks are added both for too many (unless the last 
 arg is varargs) and too args. The too many args check can be 
 disabled by putting \", ...\" last in the argument list. 
 
 Magic types in function argument lists: 
 
   bignum    A native int or bignum object. The C storage type is 
             struct svalue. 
 
   longest   A native int or bignum object which is range checked and stored 
             in a LONGEST. 
 
   zero      If used like \"zero|Something\" then a zero value is allowed in 
             addition to Something (which is how it works by default in pike 
             code). This will not cause an svalue to be constructed on the C 
             level, rather 0/NULL is assigned to the C type. 
 
             Note that this is almost the same as how void works in 
             \"void|Something\", except that the argument still is required. 
 
             \"zero\" interacts with \"void\" in a special way: If you write 
             \"void|int\" then the C storage will be an svalue to make it 
             possible to tell a missing argument from a zero integer. If you 
             write \"void|zero|int\" then it's assumed that you don't care 
             about that, and so the C storage will be an INT_TYPE which will 
             be assigned zero both if the argument is zero and when it's left 
             out. This applies to the int and float runtime types, but not 
             for the special case \"void|zero\". 
 
 Note: If a function argument accepts more than one runtime type, e.g. 
 \"int|string\", then no type checking at all is performed on the svalue. That 
 is not a bug - the user code has to do a type check later anyway, and it's 
 more efficient to add the error handling there. 
 
 Currently, the following attributes are understood: 
   efun;          makes this function a global constant (no value) 
   export;        Declare the corresponding C-symbol PMOD_EXPORT. 
   flags;         ID_STATIC | ID_NOMASK etc. 
   optflags;      OPT_TRY_OPTIMIZE | OPT_SIDE_EFFECT etc. 
   optfunc;       Optimization function. 
   type;          Override the pike type in the prototype with this type. 
                  FIXME: this doesn't quite work 
   rawtype;       Override the pike type in the prototype with this C-code 
                  type, e.g. tInt, tMix etc. 
   errname;       The name used when throwing errors. 
   name;          The name used when doing add_function. 
   prototype;     Ignore the function body, just add a prototype entry. 
   program_flags; PROGRAM_USES_PARENT | PROGRAM_DESTRUCT_IMMEDIATE etc. 
   gc_trivial;    Only valid for EXIT functions. This instructs the gc that 
                  the EXIT function is trivial and that it's ok to destruct 
                  objects of this program in any order. In general, if there 
                  is an EXIT function, the gc has to take the same care as if 
                  there is a destroy function. But if the EXIT function 
                  doesn't mind that arbitrary referenced pike objects gets 
                  destructed before this one (a very common trait since most 
                  EXIT functions only do simple cleanup), then this attribute 
                  can be added to make the gc work a little easier. 
 
 POLYMORPHIC FUNCTION OVERLOADING 
   You can define the same function several times with different 
   types. This program will select the proper function whenever 
   possible. 
 
 AUTOMATIC ALLOCATION AND DEALLOCATION OF CONSTANT STRINGS 
   You can use the syntax MK_STRING(\"my string\") to refer to 
   a struct pike_string with the content \"my string\", or the 
   syntax MK_STRING_SVALUE(\"my string\") for the same, but a 
   full svalue. Note that this syntax can not be used in macros. 
 
 BUGS/LIMITATIONS 
  o Parenthesis must match, even within #if 0 
  o Not all Pike types are supported yet. 
  o RETURN; (void) doesn't work yet 
  o need a RETURN_NULL; or something.. RETURN 0; might work but may 
    be confusing as RETURN x; will not work if x is zero. 
  o Comments does not work inside prototypes (?) 
 
 C ENVIRONMENT 
  o The macro PRECOMPILE_API_VERSION is provided to be able 
    to detect the version of precompile at compile time. 
"; 
 
#define PC Parser.Pike 
#define split PC.split 
 
int api;    // Requested API level. 
 
int warnings; 
 
void warn(string s, mixed ... args) 
{ 
  if (warnings) { 
    if (sizeof(args)) s = sprintf(s, @args); 
    werror(s); 
    return; 
  } 
  error(s, @args); 
} 
 
multiset check_used = (<>); 
 
/* Strings declared with MK_STRING. */ 
mapping(string:string) strings = ([ 
  // From stralloc.h: 
  "":"empty_pike_string", 
 
  // From program.h: 
  "this_program":"this_program_string", 
  "this":"this_string", 
  // lfuns: 
  "__INIT":"lfun_strings[LFUN___INIT]", 
  "create":"lfun_strings[LFUN_CREATE]", 
  "destroy":"lfun_strings[LFUN_DESTROY]", 
  "`+":"lfun_strings[LFUN_ADD]", 
  "`-":"lfun_strings[LFUN_SUBTRACT]", 
  "`&":"lfun_strings[LFUN_AND]", 
  "`|":"lfun_strings[LFUN_OR]", 
  "`^":"lfun_strings[LFUN_XOR]", 
  "`<<":"lfun_strings[LFUN_LSH]", 
  "`>>":"lfun_strings[LFUN_RSH]", 
  "`*":"lfun_strings[LFUN_MULTIPLY]", 
  "`/":"lfun_strings[LFUN_DIVIDE]", 
  "`%":"lfun_strings[LFUN_MOD]", 
  "`~":"lfun_strings[LFUN_COMPL]", 
  "`==":"lfun_strings[LFUN_EQ]", 
  "`<":"lfun_strings[LFUN_LT]", 
  "`>":"lfun_strings[FLUN_GT]", 
  "__hash":"lfun_strings[LFUN___HASH]", 
  "cast":"lfun_strings[LFUN_CAST]", 
  "`!":"lfun_strings[LFUN_NOT]", 
  "`[]":"lfun_strings[LFUN_INDEX]", 
  "`[]=":"lfun_strings[LFUN_ASSIGN_INDEX]", 
  "`->":"lfun_strings[LFUN_ARROW]", 
  "`->=":"lfun_strings[LFUN_ASSIGN_ARROW]", 
  "_sizeof":"lfun_strings[LFUN__SIZEOF]", 
  "_indices":"lfun_strings[LFUN__INDICES]", 
  "_values":"lfun_strings[LFUN__VALUES]", 
  "`()":"lfun_strings[LFUN_CALL]", 
  "``+":"lfun_strings[LFUN_RADD]", 
  "``-":"lfun_strings[LFUN_RSUBTRACT]", 
  "``&":"lfun_strings[LFUN_RAND]", 
  "``|":"lfun_strings[LFUN_ROR]", 
  "``^":"lfun_strings[LFUN_RXOR]", 
  "``<<":"lfun_strings[LFUN_RLSH]", 
  "``>>":"lfun_strings[LFUN_RRSH]", 
  "``*":"lfun_strings[LFUN_RMULTIPLY]", 
  "``/":"lfun_strings[LFUN_RDIVIDE]", 
  "``%":"lfun_strings[LFUN_RMOD]", 
  "`+=":"lfun_strings[LFUN_ADD_EQ]", 
  "_is_type":"lfun_strings[LFUN__IS_TYPE]", 
  "_sprintf":"lfun_strings[LFUN__SPRINTF]", 
  "_equal":"lfun_strings[LFUN__EQUAL]", 
  "_m_delete":"lfun_strings[LFUN__M_DELETE]", 
  "_get_iterator":"lfun_strings[LFUN__GET_ITERATOR]", 
  "`[..]":"lfun_strings[LFUN_RANGE]", 
  "_search":"lfun_strings[LFUN__SEARCH]", 
]); 
int last_str_id = 0; 
array(string) stradd = ({}); 
int last_svalue_id = 0; 
mapping(string:string) svalues = ([]); 
 
string parse_string(string str) 
{ 
  if (search(str, "\\") == -1) { 
    return str[1..sizeof(str)-2]; 
  } 
  error("String escapes not supported yet.\n"); 
} 
 
string allocate_string(string orig_str) 
{ 
  string str, str_sym; 
 
  if (sizeof(orig_str) >= 2 && `==('"', orig_str[0], orig_str[-1])) 
    str = parse_string(orig_str); 
  else 
    str = orig_str; 
  str_sym = strings[str]; 
  if (str_sym) return str_sym; 
 
  if (String.width(str)>8) { 
    error("Automatic allocation of wide strings with MK_STRING() or MK_STRING_SVALUE() not supported yet.\n"); 
  } 
  int str_id = last_str_id++; 
  stradd += ({ 
    sprintf("module_strings[%d] = \n" 
            "  make_shared_binary_string(%s,\n" 
            "                            CONSTANT_STRLEN(%s));\n", 
            str_id, 
            orig_str, orig_str), 
  }); 
  str_sym = strings[str] = sprintf("module_strings[%d] /* %s */", 
                                   str_id, orig_str); 
  return str_sym; 
} 
 
string allocate_string_svalue(string orig_str) 
{ 
  string str_sym = allocate_string(orig_str); 
  string svalue_sym = svalues[str_sym]; 
  if (svalue_sym) return svalue_sym; 
  int svalue_id = last_svalue_id++; 
  stradd += ({ 
    sprintf("\n#ifdef module_svalues_declared\n" 
            "SET_SVAL(module_svalues[%d], PIKE_T_STRING, 0, string, %s);\n" 
            "add_ref(module_svalues[%d].u.string);\n" 
            "#endif\n", 
            svalue_id, str_sym, svalue_id), 
  }); 
  svalue_sym = svalues[str_sym] = sprintf("(module_svalues+%d)", svalue_id); 
  return svalue_sym; 
} 
 
/* 
 * This function takes an array of tokens containing a type 
 * written in the 'array(int)' format. It returns position of 
 * the first token that is not a part of the type. 
 */ 
int parse_type(array t, int p) 
{ 
  while(1) 
  { 
    while(1) 
    { 
      if(arrayp(t[p])) 
      { 
        p++; 
      }else{ 
        switch( (string) t[p++]) 
        { 
          case "CTYPE": 
            p=sizeof(t)-2; 
            break; 
          case "0": case "1": case "2": case "3": case "4": 
          case "5": case "6": case "7": case "8": case "9": 
            if("=" != t[p]) break; 
          case "!": 
            continue; 
 
          case "object": 
          case "program": 
          case "function": 
          case "mapping": 
          case "array": 
          case "multiset": 
          case "int": 
          case "type": 
          case "string": 
            if(arrayp(t[p])) p++; 
          case "bignum": 
          case "longest": 
          case "float": 
            break; 
        } 
      } 
      break; 
    } 
    switch( arrayp(t[p]) ? "" : (string) t[p]) 
    { 
      case "|": 
      case "&": 
        p++; 
        continue; 
    } 
    break; 
  } 
  return p; 
} 
 
/* 
 * This function takes an array of tokens and 
 * reconstructs the string they came from. It does 
 * not insert linenumbers. 
 */ 
string merge(array x) 
{ 
  return PC.simple_reconstitute(x); 
} 
 
/* 
 * make a C identifier representation of 'n' 
 */ 
string cquote(string|object(PC.Token) n) 
{ 
  string ret=""; 
  while(sscanf((string)n,"%[a-zA-Z0-9]%c%s",string safe, int c, n)==3) 
  { 
    switch(c) 
    { 
      default: ret+=sprintf("%s_%02X",safe,c); break; 
      case '+':     ret+=sprintf("%s_add",safe); break; 
      case '`': ret+=sprintf("%s_backtick",safe);  break; 
      case '_': ret+=sprintf("%s_",safe); break; 
      case '=': ret+=sprintf("%s_eq",safe); break; 
    } 
  } 
  ret+=n; 
  if(ret[0]=='_' || (ret[0]>='0' && ret[0]<='9')) 
    ret="cq_"+ret; 
  return ret; 
} 
 
 
/* 
 * This function maps C types to the appropriate 
 * pike type. It is used by the CTYPE syntax. 
 * 
 * @param tokens 
 *   An array of C tokens representing the C type. 
 * 
 * @returns 
 *   Returns the corresponding Pike type. 
 */ 
PikeType convert_ctype(array(PC.Token) tokens) 
{ 
  int signed = 1; 
 
  while (1) { 
    switch((string)tokens[0]) { 
    case "unsigned": 
      signed = 0; 
      tokens = tokens[1..]; 
      if (!sizeof(tokens)) 
        return PikeType("int(0..)"); 
      break; 
 
    case "signed": 
      signed = 1; 
      tokens = tokens[1..]; 
      if (!sizeof(tokens)) 
        return PikeType("int"); 
      break; 
 
    case "char": /* char* */ 
      if(sizeof(tokens) >1 && "*" == (string)tokens[1]) 
        return PikeType("string(8bit)"); 
      else if (signed) 
        return PikeType("int(-128..127)"); 
      else 
        return PikeType("int(8bit)"); 
 
    case "short": 
      if (signed) 
        return PikeType("int(-32768..32767)"); 
      else 
        return PikeType("int(16bit)"); 
 
    case "int": 
    case "long": 
    case "INT32": 
      if (signed) return PikeType("int"); 
      return PikeType("int(0..)"); 
 
    case "size_t": 
      return PikeType("int(0..)"); 
 
    case "ptrdiff_t": 
      return PikeType("int"); 
 
    case "double": 
    case "float": 
      return PikeType("float"); 
 
    default: 
      error("Unknown C type.\n"); 
    } 
  } 
} 
 
string stringify(string s) 
{ 
  return sprintf("\"%{\\%o%}\"",(array)s); 
//  return sprintf("%O",s); 
} 
 
class PikeType 
{ 
  PC.Token t; 
  array(PikeType|string|int) args=({}); 
 
  protected string fiddle(string name, array(string) tmp) 
    { 
      while(sizeof(tmp) > 7) 
      { 
        int p=sizeof(tmp)-7; 
        string z=name + "7(" + tmp[p..]*"," +")"; 
        tmp=tmp[..p]; 
        tmp[-1]=z; 
      } 
      switch(sizeof(tmp)) 
      { 
        default: 
          return sprintf("%s%d(%s)",name,sizeof(tmp),tmp*","); 
        case 2: return sprintf("%s(%s,%s)",name,tmp[0],tmp[1]); 
        case 1: return tmp[0]; 
        case 0: return ""; 
      } 
    } 
 
  protected array(PikeType) strip_zero_alt() 
  /* Assumes this is an '|' node. Returns args without any 'zero' 
   * alternatives. */ 
  { 
    if (!args) return 0; 
    array(PikeType) a = ({}); 
    foreach (args, PikeType arg) 
      if (arg->basetype() != "zero") a += ({arg}); 
    if (!sizeof (a) && sizeof (args)) 
      // Make sure we don't strip away the entire type. 
      a = ({args[0]}); 
    return a; 
  } 
 
  /* 
   * return the 'one-word' description of this type 
   */ 
  string basetype() 
    { 
      string ret=(string)t; 
      switch(ret) 
      { 
        case "CTYPE": 
          return args[1]->basetype(); 
 
        case "|": { 
          // If there's only one type except "void" and "zero" then return it, 
          // else return "mixed". Plus some special cases if we only got "void" 
          // and "zero" in there. 
          int got_zero; 
          string single_type; 
          foreach (args, PikeType arg) { 
            string type = arg->basetype(); 
            if (type == "zero") 
              got_zero = 1; 
            else if (type != "void") { 
              if (single_type && single_type != type) 
                return "mixed"; 
              else 
                single_type = type; 
            } 
          } 
          if (single_type) return single_type; 
          else if (got_zero) return "zero"; 
          else return "void"; 
        } 
 
        case "=": 
        case "&": 
          return args[-1]->basetype(); 
 
        case "!": 
        case "any": 
        case "0": 
        case "1": 
        case "2": 
        case "3": 
        case "4": 
        case "5": 
        case "6": 
        case "7": 
        case "8": 
        case "9": 
        case "bignum": 
          return "mixed"; 
 
          // FIXME: Guess the special "longest" type ought to be 
          // "CTYPE LONGEST" instead, but the CTYPE stuff seems to be 
          // broken and I don't want to dig into it.. /mast 
        case "longest": return "LONGEST"; 
 
      case "int": 
      case "float": 
      case "string": 
      case "object": 
      case "function": 
      case "array": 
      case "mapping": 
      case "multiset": 
      case "type": 
      case "program": 
      case "mixed": 
      case "void": 
      case "zero": 
        return ret; 
 
        default: return "object"; 
      } 
    } 
 
  string realtype() 
  /* Similar to basetype, but returns the source description if the 
   * base type. */ 
  { 
    string ts = (string) t; 
    switch (ts) { 
      case "bignum": 
      case "longest": 
        return ts; 
      default: 
        return basetype(); 
    } 
  } 
 
  /* Return an array of all possible basetypes for this type 
   */ 
  array(string) basetypes() 
    { 
      string ret=(string)t; 
      switch(ret) 
      { 
        case "CTYPE": 
          return args[1]->basetypes(); 
 
        case "|": 
          return `|(@args->basetypes()); 
 
        case "=": 
        case "&": 
          return args[-1]->basetypes(); 
 
        case "!": 
        case "any": 
        case "0": 
        case "1": 
        case "2": 
        case "3": 
        case "4": 
        case "5": 
        case "6": 
        case "7": 
        case "8": 
        case "9": 
 
        case "mixed": 
          return ({ 
            "int", 
            "float", 
            "string", 
            "object", 
            "program", 
            "function", 
            "array", 
            "mapping", 
            "multiset", 
            "type", 
          }); 
        case "program": 
          return ({ 
            "object", 
            "program", 
            "function", 
          }); 
 
      case "int": 
      case "float": 
      case "string": 
      case "object": 
      case "function": 
      case "array": 
      case "mapping": 
      case "multiset": 
      case "type": 
      case "void": 
      case "zero": 
        return ({ ret }); 
 
        case "bignum": 
        case "longest": 
          return ({"int", "object"}); 
 
        default:  return ({ "object" }); 
      } 
    } 
 
 
  /* 
   * PIKE_T_INT, PIKE_T_STRING etc. 
   */ 
  string type_number() 
    { 
      string btype=basetype(); 
 
      if (btype == "function") { 
        btype = "mixed"; 
      } 
      return "PIKE_T_"+upper_case(btype); 
    } 
 
  /* 
   * Check if this type matches 'void' and/or 'zero'. 
   */ 
  int may_be_void_or_zero (int(0..) may_be_void, int(0..) may_be_zero) 
  { 
    switch((string)t) 
    { 
      case "zero": return may_be_zero; 
      case "void": return may_be_void; 
      case "|": 
        return max (0, @args->may_be_void_or_zero (may_be_void, may_be_zero)); 
 
      case "=": 
      case "&": 
        return args[-1]->may_be_void_or_zero (may_be_void, may_be_zero); 
    } 
    return 0; 
  } 
 
  int may_be_void()         // Compat wrapper. 
  { 
    return may_be_void_or_zero (1, 0); 
  } 
 
  string c_storage_type(int|void is_struct_entry) 
    { 
      string btype = realtype(); 
      switch (btype) 
      { 
        case "void": return "void"; 
        case "zero": 
          return may_be_void()?"struct svalue *":"INT_TYPE"; 
        case "int": 
          return (may_be_void_or_zero (1, 2) == 1 ? 
                  "struct svalue *" : "INT_TYPE"); 
        case "float": 
          return (may_be_void_or_zero (1, 2) == 1 ? 
                  "struct svalue *" : "FLOAT_TYPE"); 
        case "string": return "struct pike_string *"; 
 
        case "array": 
        case "multiset": 
        case "mapping": 
 
        case "object": 
        case "program": return "struct "+btype+" *"; 
 
        case "type": return "struct pike_type *"; 
 
        case "function": 
        case "mixed": 
        case "bignum": 
          if (is_struct_entry) { 
            return "struct svalue"; 
          } else { 
            return "struct svalue *"; 
          } 
 
        case "longest": 
          return "LONGEST"; 
 
        default: 
          error("Unknown type %s\n", btype); 
      } 
    } 
 
  /* 
   * Make a C representation, like 'tInt'. Can also strip off an 
   * "|zero" alternative on the top level. 
   */ 
  string output_c_type (void|int ignore_zero_alt) 
    { 
      string ret=(string)t; 
//      werror("FOO: %O %O\n",t,args); 
      switch(ret) 
      { 
        case "CTYPE": 
          return (string)args[0]->t; 
 
        case "&": 
          return fiddle("tAnd",args->output_c_type()); 
 
        case "|": 
          array(PikeType) a = strip_zero_alt(); 
          if (sizeof (a) == 1) return a[0]->output_c_type(); 
          return fiddle("tOr",a->output_c_type()); 
 
        case "!": 
          return sprintf("tNot(%s)",args[0]->output_c_type()); 
 
        case "mapping": 
          ret=sprintf("tMap(%s)",args->output_c_type()*","); 
          if(ret=="tMap(tMix,tMix)") return "tMapping"; 
          return ret; 
 
        case "multiset": 
          ret=sprintf("tSet(%s)",args[0]->output_c_type()); 
          if(ret=="tSet(tMix)") return "tMultiset"; 
          return ret; 
 
        case "array": 
          ret=sprintf("tArr(%s)",args[0]->output_c_type()); 
          if(ret=="tArr(tMix)") return "tArray"; 
          return ret; 
 
        case "type": 
          return sprintf("tType(%s)", args[0]->output_c_type()); 
 
        case "function": 
          string t=args[..sizeof(args)-3]->output_c_type()*" "; 
          if(t == "") t="tNone"; 
          if(args[-2]->output_pike_type(0) == "void") 
          { 
            return sprintf("tFunc(%s,%s)", 
                           t, 
                           args[-1]->output_c_type()); 
          }else{ 
            return sprintf("tFuncV(%s,%s,%s)", 
                           t, 
                           args[-2]->output_c_type(), 
                           args[-1]->output_c_type()); 
          } 
 
        case "=": 
          return sprintf("tSetvar(%s,%s)", 
                         (string)args[0]->t, 
                         args[1]->output_c_type (ignore_zero_alt)); 
 
        case "0": 
        case "1": 
        case "2": 
        case "3": 
        case "4": 
        case "5": 
        case "6": 
        case "7": 
        case "8": 
        case "9":       return sprintf("tVar(%s)",ret); 
 
        case "zero":    return "tZero"; 
        case "void":    return "tVoid"; 
        case "float":   return "tFloat"; 
        case "string": 
          { 
            // Clamp the integer range to 32 bit signed. 
            int low = limit(-0x80000000, (int)(string)(args[0]->t), 0x7fffffff); 
            int high = limit(-0x80000000, (int)(string)(args[1]->t), 0x7fffffff); 
            if (high < low) 
              exit(1, "Error: Inversed range in integer type, string(%s..%s).\n", 
                   (string)args[0]->t, (string)args[1]->t); 
 
            if (!low) { 
              switch(high) { 
              case 0x0000: return "tStr0"; 
              case 0x007f: return "tStr7"; 
              case 0x00ff: return "tStr8"; 
              case 0xffff: return "tStr16"; 
              } 
            } else if ((low == -0x80000000) && (high == 0x7fffffff)) { 
              return "tStr"; 
            } 
            // NOTE! This piece of code KNOWS that the serialized 
            //       value of PIKE_T_INT is 8! 
            return sprintf("tNStr(%s)", 
                           stringify(sprintf("\010%4c%4c", low, high))); 
          } 
        case "program": return "tPrg(tObj)"; 
        case "any":     return "tAny"; 
        case "mixed":   return "tMix"; 
        case "int": 
          // Clamp the integer range to 32 bit signed. 
          int low = limit(-0x80000000, (int)(string)(args[0]->t), 0x7fffffff); 
          int high = limit(-0x80000000, (int)(string)(args[1]->t), 0x7fffffff); 
          if (high < low) 
            exit(1, "Error: Inversed range in integer type, int(%s..%s).\n", 
                 (string)args[0]->t, (string)args[1]->t); 
 
          // NOTE! This piece of code KNOWS that PIKE_T_INT is 8! 
          return stringify(sprintf("\010%4c%4c", low, high)); 
 
        case "bignum": 
        case "longest": 
          return "tInt"; 
 
        case "object": 
          return "tObj"; 
        default: 
          string define = "tObjImpl_"+replace(upper_case(ret), ".", "_"); 
          if( !need_obj_defines[define] ) 
            need_obj_defines[define] = ret; 
          return sprintf("tName(%O, tObjImpl_%s)", 
                         ret, replace(upper_case(ret), ".", "_")); 
      } 
    } 
 
 
  /* 
   * Output pike type, such as array(int) 
   */ 
  string output_pike_type(int pri) 
    { 
      string ret=(string)t; 
      switch(ret) 
      { 
        case "CTYPE": 
          return args[1]->output_pike_type(pri); 
 
        case "&": 
        case "|": 
          ret=args->output_pike_type(1)*ret; 
          if(pri) ret="("+ret+")"; 
          return ret; 
 
        case "!": 
          return "!"+args[0]->output_pike_type(1); 
 
        case "mapping": 
          ret=sprintf("mapping(%s:%s)", 
                      args[0]->output_pike_type(0), 
                      args[1]->output_pike_type(0)); 
          if(ret=="mapping(mixed:mixed") 
            return "mapping"; 
          return ret; 
 
        case "multiset": 
        case "array": 
        { 
          string tmp=args[0]->output_pike_type(0); 
          if(tmp=="mixed") return ret; 
          return sprintf("%s(%s)",ret,tmp); 
        } 
 
        case "function": 
          array(string) tmp=args->output_pike_type(0); 
          ret=sprintf("function(%s:%s)", 
                      tmp[..sizeof(tmp)-3]*","+ 
                      (tmp[-2]=="void"?"":tmp[-2] + "..."), 
                      tmp[-1]); 
          if(ret=="function(mixed...:any)") 
            return "function"; 
          return ret; 
 
        case "=": 
          return sprintf("%s=%s", 
                         args[0]->output_pike_type(0), 
                         args[1]->output_pike_type(0)); 
 
        case "int": 
        case "string": 
          // Clamp the integer range to 32 bit signed. 
          int low = limit(-0x80000000, (int)(string)(args[0]->t), 0x7fffffff); 
          int high = limit(-0x80000000, (int)(string)(args[1]->t), 0x7fffffff); 
          if (!low && !(high & (high + 1))) { 
            if (!high) { 
              if (ret == "int") return "zero"; 
              return sprintf("%s(zero)", ret); 
            } 
 
            int i; 
            for (i = 0; high; high >>= 1, i++) 
              ; 
            return sprintf("%s(%dbit)", ret, i); 
          } 
          ret=sprintf("%s(%s..%s)", 
                      ret, 
                      args[0]->t == "-2147483648" ? "" : args[0]->t, 
                      args[1]->t ==  "2147483647" ? "" : args[1]->t); 
          if(has_suffix(ret, "(..)")) return ret[..sizeof(ret)-5]; 
          return ret; 
 
        case "bignum": 
        case "longest": 
          return "int"; 
 
        default: 
          return ret; 
      } 
    } 
 
 
  /* Make a copy of this type */ 
  PikeType copy() 
    { 
      return PikeType(t, args->copy()); 
    } 
 
  /* 
   * Copy and remove type assignments. Can also strip off an "|zero" 
   * alternative on the top level. 
   */ 
  PikeType copy_and_strip_type_assignments (void|int ignore_zero_alt) 
    { 
      if("=" == (string)t) 
        return args[1]->copy_and_strip_type_assignments (ignore_zero_alt); 
      array(PikeType) a; 
      if (args && ignore_zero_alt && (string) t == "|") 
        a = strip_zero_alt(); 
      else 
        a = args; 
      return PikeType(t, a && a->copy_and_strip_type_assignments (0)); 
    } 
 
  string _sprintf(int how) 
    { 
      switch(how) 
      { 
        case 'O': 
          catch { 
            return sprintf("PikeType(%O)",output_pike_type(0)); 
          }; 
          return sprintf("PikeType(%O)",t); 
 
        case 's': 
          return output_pike_type(0); 
        case 't': 
          return "object"; 
      } 
    } 
 
  /* 
   * Possible ways to initialize a PikeType: 
   * PikeType("array(array(int))") 
   * PikeType("CTYPE char *") 
   * PikeType( ({ PC.Token("array"), ({ PC.Token("("),PC.Token("int"),PC.Token(")"), }) }) ) 
   * 
   * And this way is for internal use only: 
   * PikeType( PC.Token("array"), ({ PikeType("int") }) ) 
   */ 
  void create(string|array(PC.Token)|PC.Token|array(array) tok, 
              void|array(PikeType) a) 
    { 
      switch(sprintf("%t",tok)) 
      { 
        case "object": 
          t=tok; 
          args=a; 
          break; 
 
        case "string": 
          tok=convert_comments(PC.tokenize(split(tok),"piketype")); 
          tok=PC.group(PC.hide_whitespaces(tok)); 
 
        case "array": 
          /* strip parenthesis */ 
          while(sizeof(tok) == 1 && arrayp(tok[0])) 
            tok=tok[0][1..sizeof(tok[0])-2]; 
 
          array(array(PC.Token|array(PC.Token|array))) tmp; 
          tmp=tok/({"|"}); 
 
          if(sizeof(tmp) >1) 
          { 
            t=PC.Token("|"); 
            args=map(tmp,PikeType); 
            return; 
          } 
 
          tmp=tok/({"&"}); 
          if(sizeof(tmp) >1) 
          { 
            t=PC.Token("&"); 
            args=map(tmp,PikeType); 
            return; 
          } 
 
          tmp=tok/({"="}); 
          if(sizeof(tmp) >1) 
          { 
            t=PC.Token("="); 
            args=map(tmp,PikeType); 
            return; 
          } 
 
          t=tok[0]; 
 
          if(sizeof(tok) == 1) 
          { 
            switch((string)t) 
            { 
              case "CTYPE": 
                args=({ PikeType(PC.Token(merge(tok[1..]))), 
                          convert_ctype(tok[1..]) }); 
                break; 
 
              case "mapping": 
                args=({PikeType("mixed"), PikeType("mixed")}); 
                break; 
              case "multiset": 
              case "array": 
                args=({PikeType("mixed")}); 
                break; 
              case "int": 
              case "string": 
                string low = (string)(int)-0x80000000; 
                string high = (string)0x7fffffff; 
                args=({PikeType(PC.Token(low)),PikeType(PC.Token(high))}); 
                break; 
 
              case "function": 
                args=({ PikeType("mixed"), PikeType("any") }); 
                break; 
 
              case "type": 
                args=({ PikeType("mixed") }); 
                break; 
            } 
          }else{ 
            array q; 
            switch((string)t) 
            { 
              case "!": 
                args=({ PikeType(tok[1..]) }); 
                break; 
 
              case "array": 
              case "multiset": 
                args=({ PikeType(tok[1..]) }); 
                break; 
 
              case "mapping": 
                if(arrayp(q=tok[1])) 
                { 
                  tmp=q[1..sizeof(q)-2]/({":"}); 
                  args=map(tmp,PikeType); 
                }else{ 
                  args=({PikeType("mixed"),PikeType("mixed")}); 
                } 
                break; 
 
              case "function": 
                if(arrayp(q=tok[1])) 
                { 
                  tmp=q[1..sizeof(q)-2]/({":"}); 
                  if(sizeof(tmp)<2) 
                  { 
                    throw( ({ 
                      sprintf("%s:%d: Missing return type in function type.\n", 
                              t->file||"-", 
                              t->line), 
                        backtrace() 
                        }) ); 
                  } 
                  array rettmp=tmp[1]; 
                  array argstmp=tmp[0]/({","}); 
 
                  int end=sizeof(argstmp)-1; 
                  PikeType repeater; 
                  if(sizeof(argstmp) && 
                     sizeof(argstmp[-1]) && 
                     argstmp[-1][-1]=="...") 
                  { 
                    repeater=PikeType(argstmp[-1][..sizeof(argstmp[-1])-2]); 
                    end--; 
                  }else{ 
                    repeater=PikeType("void"); 
                  } 
                  args=map(argstmp[..end]-({({})}),PikeType)+ 
                    ({repeater, PikeType(rettmp) }); 
                }else{ 
                  args=({PikeType("mixed"),PikeType("any")}); 
                } 
                return; 
 
              case "int": 
              case "string": 
                string low = (string)(int)-0x80000000; 
                string high = (string)0x7fffffff; 
 
                if(arrayp(q=tok[1])) 
                { 
                  tmp=q[1..sizeof(q)-2]/({".."}); 
                  /* Workaround for buggy Parser.Pike */ 
                  if(sizeof(tmp)==1) tmp=q[1..sizeof(q)-2]/({".. "}); 
                  if (sizeof(tmp) == 1) { 
                    int bits; 
                    /* Support the string(Xbit) syntax too. */ 
                    if ((sizeof(q) == 4) && ((string)q[2] == "bit") && 
                        ((bits = (int)(string)q[1]) > 0)) { 
                      low = "0"; 
                      high = sprintf("%d", (1 << bits) - 1); 
                    } else { 
                      error("Syntax error in string subtype.\n"); 
                    } 
                  } else { 
                    if(sizeof(tmp[0])) low=(array(string))tmp[0]*""; 
                    if(sizeof(tmp[1])) high=(array(string))tmp[1]*""; 
                  } 
                } 
                args=({PikeType(PC.Token(low)),PikeType(PC.Token(high))}); 
                break; 
 
              case "object": 
              case "type": 
                if (arrayp(tok[1]) && sizeof(tok[1]) > 2) { 
                  if ((sizeof(tok[1]) > 3) && (api < 3)) { 
                    // Make sure that the user specifies 
                    // the correct minimum API level 
                    // for build-script compatibility. 
                    warn("%s:%d: API level 3 (or higher) is required " 
                         "for type %s.\n", 
                         t->file, t->line, 
                         PC.simple_reconstitute(({ t, tok[1] }))); 
                  } 
                  t = PC.Token(merge(tok[1][1..sizeof(tok[1])-2])); 
                } 
                break; 
            } 
          } 
      } 
    } 
}; 
 
class CType { 
  inherit PikeType; 
  string ctype; 
 
  string output_c_type() { return ctype; } 
  void create(string _ctype) { 
    ctype = _ctype; 
  } 
} 
 
// Used to find the declared upper and lower range for strings 
// in argument types. 
array(int) clamp_int_range(PikeType complex_type, string ranged_type) 
{ 
  switch((string)complex_type->t) { 
  case "|": 
    { 
      array(int) res = UNDEFINED; 
      foreach(complex_type->args, PikeType arg) { 
        array(int) sub_res = clamp_int_range(arg, ranged_type); 
        if (!sub_res) continue; 
        if (!res) { 
          res = sub_res; 
          continue; 
        } 
        if (res[0] > sub_res[0]) res[0] = sub_res[0]; 
        if (res[1] < sub_res[1]) res[1] = sub_res[1]; 
      } 
      return res; 
    } 
  case "&": 
    { 
      array(int) res = ({ -0x80000000, 0x7fffffff }); 
      foreach(complex_type->args, PikeType arg) { 
        array(int) sub_res = clamp_int_range(arg, ranged_type); 
        if (!sub_res) return UNDEFINED; 
        if (res[0] < sub_res[0]) res[0] = sub_res[0]; 
        if (res[1] > sub_res[1]) res[1] = sub_res[1]; 
      } 
      if (res[0] > res[1]) return UNDEFINED; 
      return res; 
    } 
  default: 
    if (((string)complex_type->t) == ranged_type) { 
      array(PikeType) args = complex_type->args; 
      if (sizeof(args) == 2) { 
        return ({ limit(-0x80000000, 
                        (int)(string)(args[0]->t), 
                        0x7fffffff), 
                  limit(-0x80000000, 
                        (int)(string)(args[1]->t), 
                        0x7fffffff), 
        }); 
      } 
      return ({ -0x80000000, 0x7fffffff }); 
    } 
    return UNDEFINED; 
  } 
} 
 
/* 
 * This class is used to represent one function argument 
 */ 
class Argument 
{ 
  /* internal */ 
  string _name;             // Name of argument. 
  PikeType _type;   // Declared Pike type. 
  int _line;                // Line number in CMOD. 
  string _file;             // Filename of CMOD. 
 
  int _is_c_type; 
 
  // The following are cached values. 
  string _c_type;   // _type->c_storage_type(). 
  string _basetype; // _type->basetype(). 
  string _typename; // Pretty-printed Pike type (used in error messages). 
  string _realtype; // _type->realtype(). 
 
  int is_c_type() { return _is_c_type; } 
  int may_be_void_or_zero (int may_be_void, int may_be_zero) 
    { return type()->may_be_void_or_zero (may_be_void, may_be_zero); } 
  int may_be_void() { return type()->may_be_void(); } 
  int line() { return _line; } 
  string name() { return _name; } 
  PikeType type() { return _type; } 
 
  string basetype() 
    { 
      if(_basetype) return _basetype; 
      return _basetype = type()->basetype(); 
    } 
 
  string realtype() 
  { 
    if (_realtype) return _realtype; 
    return _realtype = type()->realtype(); 
  } 
 
  string c_type() 
    { 
      if(_c_type) return _c_type; 
      return _c_type = type()->c_storage_type(); 
    } 
 
  string typename() 
    { 
      if(_typename) return _typename; 
      return _typename= 
        type()->copy_and_strip_type_assignments (1)->output_pike_type(0); 
    } 
 
  void create(array x) 
    { 
      _name=(string)x[-1]; 
      _file=x[-1]->file; 
      _line=x[-1]->line; 
      _type=PikeType(x[..sizeof(x)-2]); 
    } 
 
  string _sprintf(int how) 
    { 
      return type()->output_pike_type(0)+" "+name(); 
    } 
}; 
 
/* 
 * This function takes a bunch of strings an makes 
 * a unique C identifier with underscores in between. 
 */ 
string mkname(string ... parts) 
{ 
  return map(parts - ({"",0}), cquote) * "_"; 
} 
 
mapping(string:int) names = ([]); 
 
/* 
 * Variant of mkname that always returns a unique name. 
 */ 
string make_unique_name(string ... parts) 
{ 
  string id = mkname(@parts); 
  if (names[id]) { 
    int i = 2; 
    while (names[id + "_" + i]) i++; 
    id += "_" + i; 
  } 
  names[id] = 1; 
  return id; 
} 
 
 
/* 
 * Create C code for popping 'howmany' arguments from 
 * the stack. 'howmany' may be a constant or an expression. 
 */ 
string make_pop(mixed howmany) 
{ 
  switch(howmany) 
  { 
    default: 
      return "pop_n_elems("+howmany+");"; 
 
    case "0": case 0: return ""; 
    case "1": case 1: return "pop_stack();"; 
  } 
} 
 
/* Fixme: 
 * This routine inserts non-tokenized strings into the data, which 
 * can confuse a later stage, we might need to do something about that. 
 * However, I need a *simple* way of doing it first... 
 * -Hubbe 
 */ 
array fix_return(array body, PikeType rettype, mixed args) 
{ 
  int pos=0; 
 
  while( (pos=search(body,PC.Token("RETURN",0),pos)) != -1) 
  { 
    int pos2=search(body,PC.Token(";",0),pos+1); 
    body[pos]=sprintf("do { %s ret_=(",rettype->c_storage_type()); 
    body[pos2]=sprintf("); %s push_%s(ret_); return; }while(0);", 
                       make_pop(args), 
                       rettype->basetype()); 
    pos=pos2+1; 
  } 
 
  pos=0; 
  while( (pos=search(body,PC.Token("REF_RETURN",0),pos)) != -1) 
  { 
    int pos2=search(body,PC.Token(";",0),pos+1); 
    body[pos]=sprintf("do { %s ret_=(",rettype->c_storage_type()); 
    body[pos2]=sprintf("); add_ref(ret_); %s push_%s(ret_); return; }while(0);", 
                       make_pop(args), 
                       rettype->basetype()); 
    pos=pos2+1; 
  } 
  return body; 
} 
 
 
array recursive(mixed func, array data, mixed ... args) 
{ 
  array ret=({}); 
 
  foreach(data, mixed foo) 
    { 
      if(arrayp(foo)) 
      { 
        ret+=({ recursive(func, foo, @args) }); 
      }else{ 
        ret+=({ foo }); 
      } 
    } 
 
  return func(ret, @args); 
} 
 
// FIXME: We could expand this to declare which attributes are valid 
// where. 
constant valid_attributes = (< 
  "efun", 
  "export", 
  "flags", 
  "optflags", 
  "optfunc", 
  "type", 
  "rawtype", 
  "errname", 
  "name", 
  "prototype", 
  "program_flags", 
>); 
 
/* 
 * This function takes a list of tokens, containing attributes on the form: 
 *   attributename foo bar gazonk ; 
 *   attributename2 foo2 bar2 gazonk2 ; 
 * 
 * Returns a mapping like: 
 * ([ 
 *   "attributename":"foo bar gazonk", 
 *   "attributename2":"foo2 bar2 gazonk2", 
 *   "attrflagname":1, 
 * ]) 
 */ 
mapping parse_attributes(array attr, void|string location, 
                         void|multiset really_valid_attributes) 
{ 
  mapping attributes=([]); 
  foreach(attr/ ({";"}), attr) 
    { 
      while(sizeof(attr) && has_prefix((string)attr[0], "/*")) 
        attr = attr[1..]; 
      switch(sizeof(attr)) 
      { 
        case 0: continue; 
        case 1: 
          if(arrayp(attr[0])) 
          { 
            werror("%s:%d: Expected attribute name!\n", 
                   attr[0][0]->file, 
                   attr[0][0]->line); 
            if(location) 
              werror("%s: This is where the attributes belong\n", location); 
            error("This is what I got: %O\n", attr[0]); 
          } 
          attributes[(string)attr[0]]=1; 
          break; 
        default: 
          array tmp=attr[1..]; 
          if(sizeof(tmp) == 1 && arrayp(tmp[0]) && tmp[0][0]=="(") 
            tmp=tmp[0][1..sizeof(tmp[0])-2]; 
 
          attributes[(string)attr[0]]=merge(tmp); 
      } 
 
      if(!(really_valid_attributes || valid_attributes)[(string)attr[0]]) { 
        error("%s:%d: Invalid attribute name %O.\n", 
              attr[0]->file, attr[0]->line, (string)attr[0]); 
      } 
    } 
 
  if(attributes->optfunc && !attributes->efun) { 
    warn("Only efuns may have an optfunc.\n"); 
  } 
 
  return attributes; 
} 
 
/* 
 * Generate an #ifdef/#else/#endif 
 */ 
array IFDEF(string|array(string) define, 
            array yes, 
            void|array no) 
{ 
  array ret=({}); 
  if(!arrayp(define)) define=({define}); 
  if(!yes || !sizeof(yes)) 
  { 
    if(!no || !sizeof(no)) return ({"\n"}); 
    if(sizeof(define)==1) 
    { 
      ret+=({ sprintf("\n#ifndef %s\n",define[0]) }); 
    }else{ 
      ret+=({ sprintf("\n#if !defined(%s)\n",define*") && !defined(") }); 
    } 
  }else{ 
    if(sizeof(define)==1) 
    { 
      ret+=({ sprintf("\n#ifdef %s\n",define[0]) }); 
    }else{ 
      ret+=({ sprintf("\n#if defined(%s)\n",define*") || defined(") }); 
    } 
    ret+=yes; 
    if(no && sizeof(no)) 
    { 
      ret+=({sprintf("\n#else /* %s */\n",define*", ")}); 
      ret+=no; 
    } 
  } 
  ret+=no || ({}); 
  ret+=({sprintf("\n#endif /* %s */\n",define*", ")}); 
  return ret; 
} 
 
/* 
 * Generate a #define 
 */ 
array DEFINE(string define, void|string as) 
{ 
  string tmp=define; 
  sscanf(tmp,"%s(",tmp); 
 
  return ({ 
    sprintf("\n#undef %s\n",tmp), 
    sprintf("#define %s%s\n",define, as?" "+as:"") 
      }); 
} 
 
 
class FuncData 
{ 
  string name; 
  string define; 
  PikeType type; 
  mapping attributes; 
  int max_args; 
  int min_args; 
  array(Argument) args; 
 
  string _sprintf() 
    { 
      return sprintf("FuncData(%s)",define); 
    } 
 
  int `==(mixed q) 
    { 
      return objectp(q) && q->name == name; 
//      return 0; 
    } 
}; 
 
// Returns the number of non-empty equvivalence classes in q. 
int evaluate_method(mixed q) 
{ 
  int val=0; 
  q=values(q) - ({ ({}) }); 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
  werror("evaluate: %O\n",q); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
  for(int e=0;e<sizeof(q);e++) 
  { 
    if(q[e] && sizeof(q[e])) 
    { 
      val++; 
      for(int d=e+1;d<sizeof(q);d++) 
      { 
        if(q[d] && !sizeof(q[e] ^ q[d])) /* equal is broken in some Pikes */ 
        { 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
        werror("EQ, %d %d\n",e,d); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
        q[d]=0; 
        } 
      } 
    } 
  } 
  return val; 
} 
 
// Polymorphic overloader. 
array generate_overload_func_for(array(FuncData) d, 
                                 int indent, 
                                 int min_possible_arg, 
                                 int max_possible_arg, 
                                 string name, 
                                 mapping attributes) 
{ 
  if(sizeof(d)==1) 
  { 
    return IFDEF(d[0]->define, ({ 
      PC.Token(sprintf("%*n%s(args);\n",indent,mkname("f",d[0]->name))), 
        PC.Token(sprintf("%*nreturn;\n",indent)), 
        }))+ 
      ({ PC.Token(sprintf("%*nbreak;\n",indent)) }); 
  } 
 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
  werror("generate_overload_func_for(%O, %d, %d, %d, %O, %O)...\n", 
         d, indent, min_possible_arg, max_possible_arg, name, attributes); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
 
  array out=({}); 
 
  /* This part should be recursive */ 
  array(array(FuncData)) x=allocate(256,({})); 
  int min_args=0x7fffffff; 
  int max_args=0; 
  foreach(d, FuncData q) 
    { 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
      werror("LOOP: q:%O, min_args:%O, max_args:%O\n", 
             q, q->min_args, q->max_args); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
      int low = max(min_possible_arg, q->min_args); 
      int high = min(max_possible_arg, q->max_args); 
      for(int a = low; a <= min(high, 255); a++) 
        x[a]+=({q}); 
      min_args=min(min_args, low); 
      max_args=max(max_args, high); 
    } 
 
  min_args=max(min_args, min_possible_arg); 
  max_args=min(max_args, max_possible_arg); 
 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
  werror("MIN: %O\n",min_args); 
  werror("MAX: %O\n",max_args); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
 
  string argbase="-args"; 
 
  int best_method = -1; 
  int best_method_value=evaluate_method(x); 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
  werror("Value X: %d\n",best_method_value); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
 
  array(mapping(string:array(FuncData))) y; 
  if(min_args >= 0) 
  { 
    y=allocate(min(min_args,16), ([])); 
    for(int a=0;a<sizeof(y);a++) 
    { 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
      werror("BT: arg: %d\n", a); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
      foreach(d, FuncData q) 
        { 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
        werror("BT: q: %O %s\n",q, q->args[a]->type()->basetypes()*"|"); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
        foreach(q->args[a]->type()->basetypes(), string t) 
          { 
            if (t != "void") { 
              if(!y[a][t]) y[a][t]=({}); 
              y[a][t]+=({q}); 
            } 
          } 
        } 
    } 
 
    for(int a=0;a<sizeof(y);a++) 
    { 
      int v=evaluate_method(y[a]); 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
      werror("Value %d: %d\n",a,v); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
      if(v>best_method_value) 
      { 
        best_method=a; 
        best_method_value=v; 
      } 
    } 
  } 
 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
  werror("Best method=%d\n",best_method); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
 
  if(best_method == -1) 
  { 
    if (min_args == max_args) { 
      error("Can't differentiate between %d implementations of %s().\n", 
            sizeof(d), name); 
    } 
 
    /* Switch on number of arguments */ 
    out+=({PC.Token(sprintf("%*nswitch(args) {\n",indent))}); 
    for(int a=min_args;a<=max_args;a++) 
    { 
      array tmp=x[a]; 
      if(tmp && sizeof(tmp)) 
      { 
        int d; 
        for(d=a;d<sizeof(x);d++) 
        { 
          if(equal(tmp, x[d]) && !sizeof(tmp ^ x[d])) 
          { 
            out+=({sprintf("%*n case %d:\n",indent,d) }); 
            x[d]=0; 
          }else{ 
            break; 
          } 
        } 
#ifdef PRECOMPILE_OVERLOAD_DEBUG 
      werror("Generating code for %d..%d arguments.\n", a, d-1); 
#endif /* PRECOMPILE_OVERLOAD_DEBUG */ 
      out+=generate_overload_func_for(tmp, 
                                        indent+2, 
                                        a, 
                                        d-1, 
                                        name, 
                                        attributes); 
      } 
    } 
    out+=({ 
      PC.Token(sprintf("%*n default:\n",indent)), 
        PC.Token(sprintf("%*n  wrong_number_of_args_error(%O,args,%d);\n", 
                         indent, 
                         name, 
                         min_args)), 
        PC.Token(sprintf("%*n}\n",indent)), 
        }); 
  }else{ 
    /* Switch on an argument */ 
    /* First check that we have at least that many arguments (if needed) */ 
 
    if(min_possible_arg < best_method+1) 
    { 
      out+=({ 
        PC.Token(sprintf("%*nif(args < %d) wrong_number_of_args_error(%O,args,%d);\n", 
                         indent, 
                         best_method+1, 
                         name, 
                         min_args)) 
          }); 
      min_possible_arg=best_method; 
    } 
 
    if(min_possible_arg == max_possible_arg) 
      argbase=(string) (-min_possible_arg); 
 
    out+=({PC.Token(sprintf("%*nswitch(TYPEOF(Pike_sp[%d%s])) {\n", 
                            indent, 
                            best_method,argbase)) }); 
 
    mapping m=y[best_method]; 
    mapping m2=m+([]); 
    foreach(indices(m), string type) 
      { 
        array tmp=m[type]; 
        if(tmp && sizeof(tmp)) 
        { 
          foreach(indices(m), string t2) 
            { 
              if(equal(tmp, m[t2]) && !sizeof(tmp ^ m[t2])) 
              { 
                m_delete(m,t2); 
                out+=({PC.Token(sprintf("%*n case PIKE_T_%s:\n", 
                                        indent, 
                                        upper_case(t2)))}); 
              } 
            } 
          out+=generate_overload_func_for(tmp, 
                                          indent+2, 
                                          min_possible_arg, 
                                          max_possible_arg, 
                                          name, 
                                          attributes); 
        } 
      } 
    out+=({ 
      PC.Token(sprintf("%*n default:\n",indent)), 
        PC.Token(sprintf("%*n  SIMPLE_BAD_ARG_ERROR(%O,%d,%O);\n", 
                         indent, 
                         attributes->errname || name, 
                         best_method+1, 
                         indices(m2)*"|")), 
        PC.Token(sprintf("%*n}\n",indent)), 
        }); 
  } 
  return out; 
} 
 
int gid; 
 
// Parses a block of cmod code, separating it into declarations, 
// functions to add, exit functions and other code. 
class ParseBlock 
{ 
  array code=({}); 
  array addfuncs=({}); 
  array exitfuncs=({}); 
  array declarations=({}); 
  int local_id = ++gid; 
 
  void create(array(array|PC.Token) x, string base, string class_name) 
    { 
      array(array|PC.Token) ret=({}); 
      array thestruct=({}); 
 
      // FIXME: Consider generating code in the order it appears in 
      //        the source file. 
      //      /grubba 2004-12-10 
 
      string gc_live_obj_define = make_unique_name (base, "gc", "live", "obj"); 
 
      int e; 
      for(e = 0; e < sizeof(x); e++) { 
        array|PC.Token t; 
        if (arrayp(t = x[e])) { 
          ret += ({ t }); 
          continue; 
        } 
        switch((string)t) { 
        default: 
          ret += ({ t }); 
          break; 
        case "extern": 
          ret += ({ t }); 
 
          if ((e+2 < sizeof(x)) && (((string)x[e+1])[0] == '\"') && 
              arrayp(x[e+2])) { 
            // C++ syntax support... 
            create(x[e+2], base, class_name); 
            ret += ({ x[e+1], code }); 
            code = ({}); 
            e += 2; 
          } 
          break; 
        case "INHERIT": 
          { 
            int pos=search(x,PC.Token(";",0),e); 
 
            string p; 
            string numid = "-1"; 
            string offset = "0"; 
            string indent = "  "; 
            array pre = ({}); 
            array post = ({}); 
 
            mixed name=x[e+1]; 
            string define=make_unique_name("inherit",name,base,"defined"); 
            string inh_num = make_unique_name(base, name, "inh_num"); 
            string inh_offset = make_unique_name(base, name, "inh_offset"); 
            if ((string)name == "::") { 
              e++; 
              name = x[e+1]; 
              if ((name == "this_program") && 
                  has_suffix(base, "_" + class_name)) { 
                define=make_unique_name("inherit",name,base,"defined"); 
                inh_num = make_unique_name(base, name, "inh_num"); 
                inh_offset = make_unique_name(base, name, "inh_offset"); 
                name = UNDEFINED; 
                pre = ({ 
                  PC.Token( 
sprintf("  do {\n" 
        "    int i__ =\n" 
        "      reference_inherited_identifier(Pike_compiler->previous, NULL,\n" 
        "                                     %s);\n" 
        "    if (i__ != -1) {\n" 
        "      struct program *p = Pike_compiler->previous->new_program;\n" 
        "      struct identifier *id__ = ID_FROM_INT(p, i__);\n" 
        "      if (IDENTIFIER_IS_CONSTANT(id__->identifier_flags) &&\n" 
        "          (id__->func.const_info.offset != -1)) {\n" 
        "        struct svalue *s = &PROG_FROM_INT(p, i__)->\n" 
        "          constants[id__->func.const_info.offset].sval;\n" 
        "        if (TYPEOF(*s) == T_PROGRAM) {\n" 
        "          p = s->u.program;\n", 
        allocate_string(sprintf("%q", class_name))), 
                           x[e]->line), 
                }); 
                indent = "          "; 
                p = "p"; 
                numid = "i__"; 
                offset = "1 + 42"; 
                post = ({ 
                  PC.Token( 
sprintf("        } else {\n" 
        "          yyerror(\"Previous definition of %s is not a program.\");\n" 
        "        }\n" 
        "      } else {\n" 
        "        yyerror(\"Previous definition of %s is not constant.\");\n" 
        "      }\n" 
        "    } else {\n" 
        "      yyerror(\"Failed to find previous definition of %s.\");\n" 
        "    }\n" 
        "  } while(0);\n", 
        class_name, class_name, class_name), 
                           x[e]->line), 
                }); 
              } else { 
                error("Unsupported INHERIT syntax.\n"); 
              } 
            } 
 
            mapping attributes = parse_attributes(x[e+2..pos]); 
            if (((string)name)[0] == '\"') { 
              pre = ({ 
                PC.Token("  do {\n"), 
                PC.Token("    struct program *p = resolve_program(" + 
                         allocate_string((string)name) + 
                         ");\n", 
                         name->line), 
                PC.Token("    if (p) {\n"), 
              }); 
              indent = "      "; 
              p = "p"; 
              post = ({ 
                PC.Token("      free_program(p);\n" 
                         "    } else {\n", name->line), 
                PC.Token("      yyerror(\"Inherit failed.\");\n" 
                         "    }\n" 
                         "  } while(0);", x[e]->line), 
              }); 
              if (api < 5) { 
                warn("%s:%d: API level 5 (or higher) is required " 
                     "for inherit of strings.\n", 
                     name->file, name->line); 
              } 
            } else if (name) { 
              p = mkname((string)name, "program"); 
            } 
            addfuncs += 
              IFDEF(define, 
                    ({ 
                      PC.Token( 
                               sprintf("  %s = Pike_compiler->new_program->" 
                                       "num_inherits;\n", 
                                       inh_num), 
                               x[e]->line), 
                    }) + pre + ({ 
                      PC.Token(sprintf("%slow_inherit(%s, NULL, %s, " 
                                       "%s, %s, NULL);\n", 
                                       indent, p, numid, offset, 
                                       attributes->flags || "0"), 
                               x[e]->line), 
                      PC.Token(sprintf("%s%s = Pike_compiler->new_program->" 
                                       "inherits[%s].identifier_level;\n", 
                                       indent, inh_offset, inh_num), 
                               x[e]->line), 
                    }) + post); 
            ret += DEFINE(define) + ({ 
              PC.Token(sprintf("static int %s = -1;\n", inh_num), 
                       x[e]->line), 
              PC.Token(sprintf("static int %s = -1;\n", inh_offset), 
                       x[e]->line), 
            }); 
            e = pos; 
            break; 
          } 
        case "EXTRA": 
          { 
            string define = make_unique_name("extra",base,"defined"); 
            addfuncs += IFDEF(define, x[e+1]); 
            ret += DEFINE(define); 
            e++; 
            break; 
          } 
        case "PIKECLASS": 
          { 
            int p; 
            for(p=e+1;p<sizeof(x);p++) 
              if(arrayp(x[p]) && x[p][0]=="{") 
                break; 
 
            array proto = x[e+1..p-1]; 
            array body = x[p]; 
 
            string name=(string)proto[0]; 
            string lname = mkname(base, name); 
            mapping attributes=parse_attributes(proto[1..]); 
 
            ParseBlock subclass = ParseBlock(body[1..sizeof(body)-2], 
                                             mkname(base, name), name); 
            string program_var = mkname(base, name, "program"); 
 
            string define = make_unique_name("class", base, name, "defined"); 
 
            ret+=DEFINE(define); 
            ret+=({sprintf("DEFAULT_CMOD_STORAGE struct program *%s=NULL;\n", 
                           program_var)}); 
            ret+=IFDEF(program_var+"_fun_num_used", 
                       ({sprintf("static int %s_fun_num=-1;", program_var)})); 
            ret+=subclass->declarations; 
            ret+=subclass->code; 
 
            need_obj_defines["tObjImpl_"+upper_case(lname)] = 1; 
            map_types[subclass->local_id] = ({ define, "return "+program_var+"->id;" }); 
 
            check_used[program_var+"_fun_num"]=1; 
            addfuncs+= 
              IFDEF(define, 
                    ({ 
                      IFDEF("PROG_"+upper_case(lname)+"_ID", 
                            ({ 
                              PC.Token(sprintf("  START_NEW_PROGRAM_ID(%s);\n", 
                                               upper_case(lname)), 
                                       proto[0]->line), 
                              "#else\n", 
                              PC.Token("  start_new_program();\n", 
                                       proto[0]->line), 
                            })), 
                      PC.Token(sprintf("  %s = Pike_compiler->new_program;\n", 
                                       program_var), 
                               proto[0]->line), 
                      IFDEF("tObjImpl_"+upper_case(lname), 
                            0, 
                            DEFINE("tObjIs_"+upper_case(lname), 
                                   sprintf("%O", sprintf("\3\1\x7f%3c", 
                                                         subclass->local_id)))+ 
                            DEFINE("tObjImpl_"+upper_case(lname), 
                                   sprintf("%O", sprintf("\3\0\x7f%3c", 
                                                         subclass->local_id)))), 
                    })+ 
                    subclass->addfuncs+ 
                    ({ 
                      attributes->program_flags? 
                      PC.Token(sprintf("  Pike_compiler->new_program->flags |= %s;\n", 
                                     attributes->program_flags), 
                               proto[1]->line):"", 
                      PC.Token(sprintf("  %s=end_program();\n",program_var), 
                               proto[0]->line), 
                      PC.Token(sprintf("#ifdef %[0]s_fun_num_used\n%s_fun_num=\n#endif\n" 
                                       +" add_program_constant(%O,%s,%s);\n", 
                                       program_var, 
                                       name, 
                                       program_var, 
                                       attributes->flags || "0"), 
                               proto[0]->line), 
                    }) 
                    ); 
            exitfuncs+= 
              IFDEF(define, 
                    subclass->exitfuncs+ 
                    ({ 
                      sprintf("  if(%s) {\n", program_var), 
                      PC.Token(sprintf("    free_program(%s);\n", program_var), 
                               proto[0]->line), 
                      sprintf("    %s=0;\n" 
                              "  }\n", 
                              program_var), 
                    })); 
            e = p; 
            break; 
          } 
 
        case "PIKEVAR": 
          { 
            int pos = search(x, PC.Token(";",0), e); 
            int pos2 = parse_type(x, e+1); 
            mixed name = x[pos2]; 
            PikeType type = PikeType(x[e+1..pos2-1]); 
            string define = make_unique_name("var",name,base,"defined"); 
        while( x[pos2+1] == "." ) 
        { 
            name = (string)name + (string)x[pos2+1]+ (string)x[pos2+2]; 
            pos2+=2; 
        } 
            mapping attributes = parse_attributes(x[pos2+1..pos]); 
//    werror("type: %O\n",type); 
        if( !has_value( name, "." ) ) 
        { 
            thestruct+= 
                IFDEF(define, 
                      ({ sprintf("  %s %s;\n",type->c_storage_type(1),name) })); 
        } 
        else 
        { 
            if( name[0] == "." ) 
                name = name[1..]; 
        } 
 
            addfuncs+= 
              IFDEF(define, 
                    ({ 
                      sprintf("  PIKE_MAP_VARIABLE(%O, %s_storage_offset + OFFSETOF(%s_struct, %s),\n" 
                              "                    %s, %s, %s);", 
                              ((string)name/".")[-1], base, base, name, 
                              type->output_c_type(), type->type_number(), 
                              attributes->flags || "0"), 
                    })); 
            ret+=DEFINE(define); 
            ret+=({ PC.Token("DECLARE_STORAGE") }); 
            e = pos; 
            break; 
          } 
 
        case "CVAR": 
          { 
            int pos = search(x,PC.Token(";",0),e); 
            int npos=pos-1; 
            while(arrayp(x[npos])) npos--; 
            mixed name=(string)x[npos]; 
 
            string define=make_unique_name("var",name,base,"defined"); 
 
            thestruct+=IFDEF(define,x[e+1..pos-1]+({";"})); 
            ret+=DEFINE(define); 
            ret+=({ PC.Token("DECLARE_STORAGE") }); 
            e = pos; 
            break; 
          } 
 
        case "EXIT": { 
          int p; 
          for(p=e+1;p<sizeof(x);p++) 
            if(arrayp(x[p]) && x[p][0]=="{") 
              break; 
 
          mapping attributes = 
            parse_attributes (x[e+1..p-1], 0, (<"gc_trivial">)); 
 
          if (!attributes->gc_trivial) 
            ret += DEFINE (gc_live_obj_define); 
        } 
          // Fall through. 
 
        case "INIT": 
        case "GC_RECURSE": 
        case "GC_CHECK": 
        case "OPTIMIZE": 
          { 
            ret += ({ 
              PC.Token("PIKE_INTERNAL"), 
              PC.Token(lower_case((string)t)), 
            }); 
            break; 
          } 
        } 
      } 
 
      x=ret/({"PIKE_INTERNAL"}); 
      ret=x[0]; 
 
      string ev_handler_define=make_unique_name(base,"event","handler","defined"); 
      string opt_callback_define=make_unique_name(base,"optimize","callback","defined"); 
      int opt_callback; 
      array ev_handler=({}); 
      for(int f=1;f<sizeof(x);f++) 
      { 
        array func=x[f]; 
        int p; 
        for(p=0;p<sizeof(func);p++) 
          if(arrayp(func[p]) && func[p][0]=="{") 
            break; 
 
        array body=func[p]; 
        array rest=func[p+1..]; 
//    werror("%O\n",func); 
        string name=(string)func[0]; 
        string funcname=mkname(name,base,"struct"); 
        string define=make_unique_name("internal",name,base,"defined"); 
        ret+=DEFINE(define); 
        if (name == "optimize") { 
          opt_callback = 1; 
          ret += DEFINE(opt_callback_define); 
          ret += ({ PC.Token(sprintf("static node *%s(node *n)\n", 
                                     funcname)) }); 
        } else { 
          ret+=DEFINE(ev_handler_define); 
          ret+=({ PC.Token(sprintf("static void %s(void)\n",funcname)) }); 
          ev_handler+=IFDEF(define,({ 
            sprintf("  case PROG_EVENT_%s: %s(); break;\n", 
                    upper_case(name), 
                    funcname) 
          })); 
        } 
        ret+=body; 
        ret+=rest; 
      } 
      if(sizeof(ev_handler)) 
      { 
        string funcname=mkname(base,"event","handler"); 
        ret+=IFDEF(ev_handler_define, 
                   ({ 
                     sprintf("static void %s(int ev) {\n",funcname), 
                       "  switch(ev) {\n" 
                       })+ 
                   ev_handler+ 
                   ({ "  default: break; \n" 
                      "  }\n}\n" })); 
 
        addfuncs+= 
          IFDEF(ev_handler_define, 
                ({ PC.Token(sprintf("  pike_set_prog_event_callback(%s);\n",funcname)) }) + 
                IFDEF (gc_live_obj_define, 
                       0, 
                       ({PC.Token ("  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;\n")})) 
               ); 
      } 
      if (opt_callback) { 
        addfuncs += 
          IFDEF(opt_callback_define, 
                ({ PC.Token(sprintf("  pike_set_prog_optimize_callback(%s);\n", 
                                    mkname("optimize",base,"struct"))) })); 
      } 
 
      if(sizeof(thestruct)) 
      { 
        /* We insert the struct definition after the last 
         * variable definition 
         */ 
        string structname = base+"_struct"; 
        string this=sprintf("((struct %s *)(Pike_interpreter.frame_pointer->current_storage))",structname); 
 
        /* FIXME: 
         * Add runtime debug to these defines... 
         * Add defines for parents when possible 
         */ 
        declarations= 
                  DEFINE("THIS",this)+   // FIXME: we should 'pop' this define later 
          DEFINE("THIS_"+upper_case(base),this)+ 
          DEFINE("OBJ2_"+upper_case(base)+"(o)", 
                 sprintf("((struct %s *)(o->storage+%s_storage_offset))", 
                         structname, base))+ 
          DEFINE("GET_"+upper_case(base)+"_STORAGE(o)", 
                 sprintf("((struct %s *)(o->storage+%s_storage_offset)", 
                         structname, base))+ 
            ({ 
              sprintf("static ptrdiff_t %s_storage_offset;\n",base), 
                sprintf("struct %s {\n",structname), 
                })+thestruct+({ 
                  "};\n", 
                  sprintf (#"\ 
#ifdef PIKE_DEBUG 
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */ 
static struct %s *%s_gdb_dummy_ptr; 
#endif\n", structname, base), 
                    }) 
          +declarations; 
        addfuncs = ({ 
          IFDEF("THIS_"+upper_case(base), ({ 
                  PC.Token(sprintf("  %s_storage_offset = " 
                                   "ADD_STORAGE(struct %s);", 
                                   base, structname)), 
                })), 
        }) + addfuncs; 
      } 
 
      x=ret/({"DECLARE_STORAGE"}); 
      ret=x[..sizeof(x)-2]*({})+declarations+x[-1]; 
      declarations=({}); 
 
      x=ret/({"PIKEFUN"}); 
      ret=x[0]; 
 
      mapping(string:array(FuncData)) name_data=([]); 
      mapping(string:int) name_occurances=([]); 
 
      for(int f=1;f<sizeof(x);f++) 
      { 
        array func=x[f]; 
        int p; 
        for(p=0;p<sizeof(func);p++) 
          if(arrayp(func[p]) && func[p][0]=="{") 
            break; 
 
        array proto=func[..p-1]; 
        p=parse_type(proto,0); 
        if(arrayp(proto[p])) 
        { 
          error("%s:%d: Missing return type?\n", 
                proto[p][0]->file||"-", 
                proto[p][0]->line); 
        } 
        string name=(string)proto[p]; 
        name_occurances[name]++; 
      } 
 
      for(int f=1;f<sizeof(x);f++) 
      { 
        array func=x[f]; 
        int p; 
        for(p=0;p<sizeof(func);p++) 
          if(arrayp(func[p]) && func[p][0]=="{") 
            break; 
 
        array proto=func[..p-1]; 
        array body=func[p]; 
        array rest=func[p+1..]; 
 
        // Not all versions of Pike allow Token objects 
        // to be indexed. 
        catch { 
          foreach(Array.flatten(proto), string t) 
            if(has_prefix((string)t, "/*!")) 
              body = ({t})+body; 
        }; 
 
        p=parse_type(proto,0); 
        PikeType rettype=PikeType(proto[..p-1]); 
 
        if(arrayp(proto[p])) 
        { 
          error("%s:%d: Missing type?\n", 
                proto[p][0]->file||"-", 
                proto[p][0]->line); 
        } 
        string location=proto[p]->file+":"+proto[p]->line; 
 
        string name=""; 
        do { 
          name += (string)proto[p]; 
          p++; 
        } while(!arrayp(proto[p])); 
        p--; // Readjust the pointer 
 
        array args_tmp=proto[p+1]; 
 
        mapping attributes=parse_attributes(proto[p+2..],location); 
        string common_name=name; 
        if(!attributes->errname) 
          attributes->errname=name; 
        if(name_occurances[common_name]>1) 
          name+="_"+(++name_occurances[common_name+".cnt"]); 
 
        args_tmp=args_tmp[1..sizeof(args_tmp)-2]; 
        if(sizeof(args_tmp)) 
        { 
          args_tmp/=({","}); 
        }else{ 
          args_tmp=({}); 
        } 
 
        string funcname=mkname("f",base,name); 
        string define=make_unique_name("f",base,name,"defined"); 
        string func_num=mkname("f", base,name,"fun_num"); 
 
//    werror("FIX RETURN: %O\n",body); 
 
//    werror("name=%s\n",name); 
//    werror("  rettype=%O\n",rettype); 
//    werror("  args=%O\n",args); 
 
        ret+=({ 
          sprintf("#define %s\n", define), 
        }); 
 
        if (!attributes->efun) { 
          check_used[func_num] = 1; 
          ret += ({ 
            IFDEF(func_num+"_used", 
                  ({ sprintf("DEFAULT_CMOD_STORAGE ptrdiff_t %s = 0;\n", 
                             func_num) }), 
                  0) 
          }); 
        } 
 
        // werror("%O %O\n",proto,args); 
        int last_argument_repeats, ignore_more_args; 
        if (sizeof(args_tmp)) { 
          array last_arg = args_tmp[-1]; 
          if (sizeof (last_arg) > 1) { 
            if (!arrayp(last_arg[-2]) && "..." == (string)last_arg[-2]) { 
              last_argument_repeats = 1; 
              args_tmp[-1] = last_arg[..sizeof(last_arg)-3] + ({last_arg[-1]}); 
            } 
          } 
          else if( sizeof(last_arg)) 
      { 
            if (!arrayp(last_arg[0]) && "..." == (string)last_arg[0]) { 
              ignore_more_args = 1; 
              args_tmp = args_tmp[..sizeof (args_tmp) - 2]; 
            } 
      } 
      else 
      { 
          warn("%s:%s Failed to parse types\n", location,name); 
      } 
        } 
        array(Argument) args=map(args_tmp,Argument); 
        // werror("%O %O\n",proto,args); 
        // werror("parsed args: %O\n", args); 
 
        if((<"`<", "`>", "`==", "_equal">)[name]) 
        { 
          if(sizeof(args) != 1) 
          { 
            warn("%s must take one argument.\n"); 
          } 
          if(sprintf("%s",args[0]->type()) != "mixed") 
          { 
            warn("%s:%s must take a mixed argument (was declared as %s)\n", 
                 location, name, args[0]->type()); 
          } 
        } 
 
        // FIXME: support ... types 
        PikeType type; 
 
        if(attributes->rawtype) 
          type = CType(attributes->rawtype); 
        else if(attributes->type) 
        { 
          mixed err=catch { 
            type=PikeType(attributes->type); 
          }; 
          if(err) 
          { 
            werror("%s: Something went wrong when parsing type: %s\n", 
                   location, 
                   attributes->type); 
            throw(err); 
          } 
        }else{ 
          if(last_argument_repeats) 
          { 
            type = PikeType(PC.Token("function"), 
                            args[..sizeof(args)-2]->type() + 
                            ({ args[-1]->type(), rettype }) ); 
          }else{ 
            type = PikeType(PC.Token("function"), 
                            args->type() + ({ PikeType("void"), rettype }) ); 
          } 
        } 
 
//    werror("NAME: %O\n",name); 
//    werror("type: %O\n", type); 
//    werror("C type: %O\n", type->output_c_type()); 
 
        if (attributes->prototype) { 
          funcname = "NULL"; 
        } else { 
          if (attributes->export) { 
            ret+=({ 
              sprintf("PMOD_EXPORT void %s(INT32 args) ",funcname), 
            }); 
          } else { 
            ret+=({ 
              sprintf("DEFAULT_CMOD_STORAGE void %s(INT32 args) ",funcname), 
            }); 
          } 
          ret += ({ 
            "{","\n", 
          }); 
 
          int min_args=sizeof(args); 
          int max_args=sizeof(args); 
          int repeat_arg = -1; 
 
          if(last_argument_repeats) 
          { 
            min_args--; 
            max_args=0x7fffffff; 
            repeat_arg = min_args; 
            args[-1]->_c_type = "struct svalue *"; 
          } 
          else if (ignore_more_args) 
            max_args = 0x7fffffff; 
 
          while(min_args>0 && args[min_args-1]->may_be_void()) 
            min_args--; 
 
          foreach(args, Argument arg) 
            if( arg->name() != "UNUSED" ) { 
              ret+=({ 
                  PC.Token(sprintf("%s %s;\n",arg->c_type(), arg->name()), 
                           arg->line()), 
              }); 
              if (arg->c_type() == "struct object *") { 
                ret += ({ 
                  PC.Token(sprintf("int %s_inh_num;\n", arg->name()), 
                           arg->line()), 
                }); 
              } 
            } 
 
 
          int argnum; 
 
          argnum=0; 
          string argbase; 
          string num_arguments; 
          if(min_args == max_args) 
          { 
            ret+=({ 
              PC.Token(sprintf("if(args != %d) " 
                               "wrong_number_of_args_error(%O,args,%d);\n", 
                               sizeof(args), 
                               attributes->errname || name, 
                               sizeof(args)), proto[0]->line) 
            }); 
            argbase=(string) (-sizeof(args)); 
            num_arguments=(string)sizeof(args); 
          }else{ 
            argbase="-args"; 
            num_arguments="args"; 
            if(min_args > 0) { 
              ret+=({ 
                PC.Token(sprintf("if(args < %d) " 
                                 "wrong_number_of_args_error(%O,args,%d);\n", 
                                 min_args, 
                                 name, 
                                 min_args), proto[0]->line) 
              }); 
            } 
 
            if(max_args != 0x7fffffff && max_args != -1) { 
              ret+=({ 
                PC.Token(sprintf("if(args > %d) " 
                                 "wrong_number_of_args_error(%O,args,%d);\n", 
                                 max_args, 
                                 name, 
                                 max_args), proto[0]->line) 
              }); 
            } 
          } 
 
          string check_argbase = argbase; 
 
          foreach(args, Argument arg) 
          { 
            int got_void_or_zero_check = 0; 
        if( arg->name() == "UNUSED" ) 
        { 
            // simply skip directly for now. 
            // should probably also handle ... etc? 
            argnum++; 
            continue; 
        } 
            if (argnum == repeat_arg) { 
              // Begin the argcnt loop. 
              check_argbase = "+argcnt"+argbase; 
              ret += ({ PC.Token(sprintf("if (args > %d) {\n" 
                                         "  INT32 argcnt = 0;\n" 
                                         "  do {\n" 
                                         "    dmalloc_touch_svalue(Pike_sp%+d%s);\n", 
                                         argnum, argnum, check_argbase), 
                                 arg->line()) }); 
            } 
 
            else { 
              int void_or_zero = arg->may_be_void_or_zero (2, 1); 
              if (void_or_zero == 2) { 
                if (!(<"int","mixed">)[arg->basetype()]) { 
                  ret+=({ 
                    PC.Token(sprintf("if (args > %d &&\n" 
                                     "    (TYPEOF(Pike_sp[%d%s]) != PIKE_T_INT ||\n" 
                                     "     Pike_sp[%d%s].u.integer)) {\n", 
                                     argnum, 
                                     argnum, check_argbase, 
                                     argnum, check_argbase), arg->line()), 
                  }); 
                } else { 
                  ret+=({ 
                    PC.Token(sprintf("if ((args > %d) &&\n" 
                                     "    ((TYPEOF(Pike_sp[%d%s]) != PIKE_T_INT) ||\n" 
                                     "     (SUBTYPEOF(Pike_sp[%d%s]) != NUMBER_UNDEFINED))) {\n", 
                                     argnum, 
                                     argnum, check_argbase, 
                                     argnum, check_argbase), arg->line()), 
                  }); 
                } 
                got_void_or_zero_check = 1; 
              } 
 
              else if (void_or_zero == 1) { 
                if (!(<"int", "mixed">)[arg->basetype()]) { 
                  ret += ({ 
                    PC.Token (sprintf ("if (TYPEOF(Pike_sp[%d%s]) != PIKE_T_INT ||\n" 
                                       "    Pike_sp[%d%s].u.integer) {\n", 
                                       argnum, check_argbase, 
                                       argnum, check_argbase), arg->line()), 
                  }); 
                  got_void_or_zero_check = 1; 
                } 
              } 
            } 
 
          check_arg: { 
            if(arg->is_c_type() && arg->basetype() == "string") 
            { 
              // FIXME: Probably dead code! 
              /* Special case for 'char *' */ 
              /* This will have to be amended when we want to support 
               * wide strings 
               */ 
              ret+=({ 
                PC.Token(sprintf("if(TYPEOF(Pike_sp[%d%s]) != PIKE_T_STRING ||\n" 
                                 "   Pike_sp[%d%s].u.string->shift_size)", 
                                 argnum,check_argbase, 
                                 argnum,check_argbase), arg->line()) 
              }); 
            } else { 
 
              switch(arg->realtype()) 
              { 
              case "string": 
                // Clamp the integer range to 32 bit signed. 
                [int low, int high] = clamp_int_range(arg->type(), "string"); 
                if ((low >= 0) && (high <= 0xffff)) { 
                  // Narrow string. 
                  if (high <= 0xff) { 
                    if (low > 0) { 
                      ret += ({ 
                        PC.Token(sprintf("if((TYPEOF(Pike_sp[%d%s]) != PIKE_T_%s) || " 
                                         "Pike_sp[%d%s].u.string->size_shift || " 
                                         "string_has_null(Pike_sp[%d%s].u.string))", 
                                         argnum, check_argbase, 
                                         upper_case(arg->basetype()), 
                                         argnum, check_argbase, 
                                         argnum, check_argbase), 
                                 arg->line()), 
                      }); 
                    } else { 
                      ret += ({ 
                        PC.Token(sprintf("if((TYPEOF(Pike_sp[%d%s]) != PIKE_T_%s) || " 
                                         "Pike_sp[%d%s].u.string->size_shift)", 
                                         argnum, check_argbase, 
                                         upper_case(arg->basetype()), 
                                         argnum, check_argbase), 
                                 arg->line()), 
                      }); 
                    } 
                  } else { 
                    ret += ({ 
                      PC.Token(sprintf("if((TYPEOF(Pike_sp[%d%s]) != PIKE_T_%s) || " 
                                       "(Pike_sp[%d%s].u.string->size_shift > 1))", 
                                       argnum, check_argbase, 
                                       upper_case(arg->basetype()), 
                                       argnum, check_argbase), 
                               arg->line()), 
                    }); 
                  } 
                  break; 
                } 
                // FALL_THROUGH 
              default: 
                ret+=({ 
                  PC.Token(sprintf("if(TYPEOF(Pike_sp[%d%s]) != PIKE_T_%s)", 
                                   argnum,check_argbase, 
                                   upper_case(arg->basetype())),arg->line()) 
                }); 
                break; 
 
              case "program": 
                ret+=({ 
                  PC.Token(sprintf("if(!(%sprogram_from_svalue(Pike_sp%+d%s)))", 
                                   (arg->c_type() == "struct program *" ? 
                                    arg->name() + "=" : ""), 
                                   argnum,check_argbase), 
                           arg->line()) 
                }); 
                break; 
 
              case "longest": 
              case "bignum": 
                // Note that for "longest" we always accept a bignum 
                // object, even if LONGEST isn't longer than INT_TYPE. 
                // That way we get a more natural error below if the 
                // bignum is too large (i.e. "Integer too large" 
                // instead of "Expected int, got object"). 
                ret += ({ 
                  PC.Token ( 
                    sprintf ("if (TYPEOF(Pike_sp[%d%s]) != PIKE_T_INT", 
                             argnum, check_argbase), 
                    arg->line()), 
                  PC.Token ( 
                    sprintf ("  && !is_bignum_object_in_svalue (Pike_sp%+d%s))", 
                             argnum, check_argbase), 
                    arg->line()), 
                }); 
                break; 
 
              case "mixed": 
                break check_arg; 
              } 
            } 
 
            ret+=({ 
              PC.Token(sprintf(" SIMPLE_ARG_TYPE_ERROR(%O,%d%s,%O);\n", 
                               attributes->errname || attributes->name || name, 
                               argnum+1, 
                               (argnum == repeat_arg)?"+argcnt":"", 
                               arg->typename()),arg->line()), 
            }); 
            } 
 
            if (argnum == repeat_arg) { 
              // End the argcnt loop. 
              ret += ({ PC.Token(sprintf ("  } while (++argcnt < %s-%d);\n" 
                                          "  %s=Pike_sp%+d%s;\n" 
                                          "} else %s = NULL;\n", 
                                          num_arguments, argnum, 
                                          arg->name(), argnum, argbase, 
                                          arg->name()), 
                                 arg->line()) }); 
            } 
 
            else { 
              switch(arg->c_type()) 
              { 
                case "INT_TYPE": 
                  ret+=({ 
                    PC.Token (sprintf("%s=Pike_sp[%d%s].u.integer;\n", 
                                      arg->name(), argnum,argbase), 
                              arg->line()) 
                  }); 
                  break; 
 
                case "FLOAT_TYPE": 
                  ret+=({ 
                    PC.Token (sprintf("%s=Pike_sp[%d%s].u.float_number;\n", 
                                      arg->name(), argnum,argbase), 
                              arg->line()) 
                  }); 
                  break; 
 
                case "struct svalue *": 
                  ret+=({ 
                    PC.Token(sprintf("%s=Pike_sp%+d%s; dmalloc_touch_svalue(Pike_sp%+d%s);\n", 
                                     arg->name(), 
                                     argnum,argbase,argnum,argbase),arg->line()), 
                  }); 
                  break; 
 
                case "struct program *": 
                  // Program arguments are assigned directly in the check above. 
                  break; 
 
                case "LONGEST": 
                  ret += ({ 
                    PC.Token ( 
                      sprintf ("if (TYPEOF(Pike_sp[%d%s]) == PIKE_T_INT)\n", 
                               argnum, argbase), 
                      arg->line()), 
                    PC.Token ( 
                      sprintf (" %s = Pike_sp[%d%s].u.integer;\n", 
                               arg->name(), argnum, argbase), 
                      arg->line()), 
                    PC.Token ("else", arg->line()), 
                    "\n#if SIZEOF_LONGEST > SIZEOF_INT_TYPE\n", 
                    PC.Token ( 
                      sprintf ("if (!int64_from_bignum (&(%s), " 
                               "Pike_sp[%d%s].u.object))\n", 
                               arg->name(), argnum, argbase), 
                      arg->line()), 
                    "\n#endif\n", 
                    PC.Token ( 
                      sprintf (" SIMPLE_ARG_ERROR (%O, %d," 
                               " \"Integer too large.\");\n", 
                               attributes->errname || attributes->name || name, 
                               argnum+1), 
                      arg->line()), 
                  }); 
                  break; 
 
                default: 
                  if(arg->is_c_type() && arg->basetype() == "string") 
                  { 
                    /* some sort of 'char *' */ 
                    /* This will have to be amended when we want to support 
                     * wide strings 
                     */ 
                    ret+=({ 
                      PC.Token(sprintf("%s=Pike_sp[%d%s].u.string->str; debug_malloc_touch(Pike_sp[%d%s].u.string)\n", 
                                       arg->name(), 
                                       argnum,argbase, 
                                       argnum,argbase),arg->line()) 
                    }); 
 
                  }else{ 
                    ret+=({ 
                      PC.Token(sprintf("debug_malloc_pass(%s=Pike_sp[%d%s].u.%s);\n", 
                                       arg->name(), 
                                       argnum,argbase, 
                                       arg->basetype()),arg->line()) 
                    }); 
                    if (arg->c_type() == "struct object *") { 
                      ret += ({ 
                        PC.Token(sprintf("%s_inh_num = SUBTYPEOF(Pike_sp[%d%s]);\n", 
                                         arg->name(), 
                                         argnum,argbase),arg->line()) 
                      }); 
                    } 
                  } 
 
                case "program": 
              } 
 
              if (got_void_or_zero_check) 
              { 
                string zero_val; 
                switch (arg->c_type()) { 
                  case "INT_TYPE": zero_val = "0"; break; 
                  case "FLOAT_TYPE": zero_val = "0.0"; break; 
                  default: zero_val = "NULL"; break; 
                } 
                ret+=({  PC.Token(sprintf("} else %s = %s;\n", 
                                          arg->name(), zero_val), 
                                  arg->line()) }); 
              } 
            } 
 
            argnum++; 
          } 
 
          body=recursive(fix_return,body,rettype, num_arguments); 
          if(sizeof(body)) 
            ret+=({body}); 
          ret+=({ "}\n" }); 
 
          if(name_occurances[common_name] > 1) 
          { 
            FuncData d=FuncData(); 
            d->name=name; 
            d->define=define; 
            d->type=type; 
            d->attributes=attributes; 
            d->max_args=max_args; 
            d->min_args=min_args; 
            d->args=args; 
            name_data[common_name]=( name_data[common_name] || ({}) ) + ({d}); 
 
            if(name_occurances[common_name]!=name_occurances[common_name+".cnt"]) 
            { 
              ret+=rest; 
              continue; 
            } 
            array(FuncData) tmp=map(name_data[common_name], 
                                    lambda(FuncData fun) { 
                                      fun->name = mkname(base, fun->name); 
                                      return fun; 
                                    }); 
            /* Generate real funcname here */ 
            name=common_name; 
            funcname=mkname("f",base,common_name); 
            define=make_unique_name("f",base,common_name,"defined"); 
            func_num=mkname(base,funcname,"fun_num"); 
            array(string) defines=({}); 
 
            type=PikeType(PC.Token("|"), tmp->type); 
            attributes=`|(@ tmp->attributes); 
 
            array out=generate_overload_func_for(tmp, 
                                                 2, 
                                                 0, 
                                                 0x7fffffff, 
                                                 common_name, 
                                                 attributes); 
 
            /* FIXME: This definition should be added 
             * somewhere outside of all #ifdefs really! 
             * -Hubbe 
             */ 
            check_used[func_num] = 1; 
            ret+=IFDEF(tmp->define, ({ 
              sprintf("#define %s\n",define), 
              IFDEF(func_num+"_used", 
                    ({sprintf("DEFAULT_CMOD_STORAGE ptrdiff_t %s = 0;\n", func_num)})), 
              sprintf("DEFAULT_CMOD_STORAGE void %s(INT32 args) ",funcname), 
              "{\n", 
            })+out+({ 
              "}\n", 
            })); 
          } 
        } 
        ret+=rest; 
 
        if (attributes->efun) { 
          if(attributes->optfunc) 
            addfuncs+=IFDEF(define,({ 
              PC.Token(sprintf("  ADD_EFUN2(%O, %s, %s, %s, %s, 0);\n", 
                               attributes->name || name, 
                               funcname, 
                               type->output_c_type(), 
                               (attributes->optflags)|| "0", 
                               attributes->optfunc 
                               ), proto[0]->line), 
            })); 
          else 
            addfuncs+=IFDEF(define,({ 
              PC.Token(sprintf("  ADD_EFUN(%O, %s, %s, %s);\n", 
                               attributes->name || name, 
                               funcname, 
                               type->output_c_type(), 
                               (attributes->optflags)|| "0" 
                               ), proto[0]->line), 
            })); 
        } else { 
          check_used[func_num] = 1; 
          addfuncs+=IFDEF(define, ({ 
               IFDEF(func_num+"_used", 
                    ({PC.Token(sprintf("  %s =", func_num))})), 
            PC.Token(sprintf("    ADD_FUNCTION2(%O, %s, %s, %s, %s);\n", 
                             attributes->name || name, 
                             funcname, 
                             type->output_c_type(), 
                             attributes->flags || "0" , 
                             attributes->optflags || 
                             "OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT" 
                             ),proto[0]->line), 
          })); 
        } 
      } 
 
      code=ret; 
    } 
} 
 
array(PC.Token) convert_comments(array(PC.Token) tokens) 
{ 
  // Filter AutoDoc mk II, and convert other C++ comments to C-style. 
  array new = ({}); 
  array autodoc; 
 
  foreach(tokens, PC.Token token) { 
    if(has_prefix((string)token, "//!") || 
       has_prefix((string)token, "/*!")) { 
      if(!autodoc) 
        autodoc = ({}); 
      autodoc += ({ ((string)token)[3..] }); 
    } 
    else { 
      if(autodoc) { 
        new += ({ PC.Token("/*!" + autodoc*"\n *!" ) }); 
        autodoc = 0; 
      } 
      if(has_prefix((string)token, "//")) 
        new += ({ PC.Token("/*" + ((string)token)[2..] + " */") }); 
      else 
        new += ({ token }); 
    } 
  } 
 
  return new; 
} 
 
array(PC.Token) allocate_strings(array(PC.Token|array(PC.Token)) tokens) 
{ 
  int i = -1; 
 
  while ((i = search(tokens, PC.Token("MK_STRING"), i+1)) != -1) { 
    // werror("MK_STRING found: %O\n", tokens[i..i+10]); 
    if (arrayp(tokens[i+1]) && (sizeof(tokens[i+1]) == 3)) { 
      tokens[i] = PC.Token(allocate_string((string)tokens[i+1]->text[1])); 
      tokens = tokens[..i] + tokens[i+2..]; 
    } 
  } 
  while ((i = search(tokens, PC.Token("MK_STRING_SVALUE"), i+1)) != -1) { 
    // werror("MK_STRING_SVALUE found: %O\n", tokens[i..i+10]); 
    if (arrayp(tokens[i+1]) && (sizeof(tokens[i+1]) == 3)) { 
      tokens[i] = PC.Token(allocate_string_svalue((string)tokens[i+1][1])); 
      tokens = tokens[..i] + tokens[i+2..]; 
    } 
  } 
  return tokens; 
} 
 
class ArgCheckFunction(array tokens) 
{ 
} 
 
class Handler { 
    inherit "/master"; 
 
    mixed resolv(string identifier, string|void current_file, 
                 object|void current_handler) { 
        return predef::master()->resolv(identifier, current_file, 
                                        current_handler); 
    } 
 
    void create(mapping|void predefines) { 
        ::create(); 
        if (predefines) this_program::predefines = predefines; 
    } 
} 
 
int find_identifier( array in, string ident ) 
{ 
  foreach( in, mixed q ) 
  { 
    if( objectp(q) ) 
    { 
      if( q == ident ) 
        return 1; 
    } 
    else if( arrayp( q ) ) 
    { 
      if( find_identifier( q, ident ) ) 
        return 1; 
    } 
  } 
} 
 
array resolve_obj_defines() 
{ 
  array res = ({}); 
 
  foreach( need_obj_defines; string key; int|string id ) 
  { 
    if( intp( id ) ) 
    { 
      m_delete( need_obj_defines, key ); 
      continue; /* type in this file. Not external. */ 
    } 
  } 
  if( sizeof( need_obj_defines ) ) 
  { 
    res += ({ "{ int i=0;\n"}); 
    foreach( need_obj_defines; string key; string id ) 
    { 
      int local_id = ++gid; 
      res += ({ 
        sprintf("#ifndef %s\n" 
                "# define %[0]s %s\n" 
                "{\n" 
                "   struct program *tmp = resolve_program(%s);\n" 
                "   if( tmp ) {\n" 
                "      ___cmod_ext_used[i].from = %d;\n" 
                "      ___cmod_ext_used[i].to = tmp->id;\n" 
                "      i++;\n" 
                "   }\n" 
                "}\n" 
                "#endif /* %[0]s */\n", 
                key, sprintf("%O", sprintf("\3\0\x7f%3c", local_id)), 
                allocate_string(sprintf("%O",id)), local_id) 
      }); 
    } 
    res += ({"}\n"}); 
  } 
  return res; 
} 
 
int main(int argc, array(string) argv) 
{ 
  mixed x; 
 
  string base = ""; 
 
  warnings = 1; 
  api = (int)precompile_api_version; 
 
  string outpath; 
  if( has_suffix( lower_case(dirname( argv[0] )), "standalone.pmod" ) ) 
    usage = "pike -x " + basename( argv[0] )-".pike" + " " + usage; 
  foreach(Getopt.find_all_options( argv, ({ 
      ({ "api",        Getopt.HAS_ARG,      "--api"/"," }), 
      ({ "help",       Getopt.NO_ARG,       "-h,--help"/"," }), 
      ({ "output",     Getopt.HAS_ARG,      "-o,--out"/"," }), 
      ({ "version",    Getopt.NO_ARG,       "-v,--version"/"," }), 
      ({ "warnings",   Getopt.NO_ARG,       "-w,--warnings"/"," }), 
      ({ "base",       Getopt.HAS_ARG,      "-b,--base"/"," }), 
   })), array opt ) { 
    switch(opt[0]) { 
    case "version": 
      write( "Precompile format version "+precompile_api_version+"\n"); 
      return 0; 
    case "help": 
      write( usage ); 
      return 0; 
 
    case "api": 
 
        /* If we want to be able to compile old versions of pike with 
         * new precompile.pike, and new versions of pike with old 
         * precompile.pike we have to ignore the api version. 
         * 
         * Since none of the API changes really change how previously 
         * valid code is interpreted the whole API system only adds 
         * incompatibility. 
         * 
         * As an example, backend.cmod in pike 7.8 can not be 
         * precompiled if you only have a pike 7.9 installed, which 
         * makes it impossible to build a pike 7.8 if you have pike 
         * 7.9+ installed (specifically, the object(Thread.Thread) 
         * will break, since newer precompile added actual support for 
         * it, while the backend.cmod depends on the old non-support, 
         * but both version works just fine if the check is removed). 
         * 
         * Adding the --api argument to the 7.8 makefiles is not 
         * really an option, because that will not work for older 
         * releases, and will make it impossible to precompile pike 
         * 7.8 .cmod-files with pikes older than 7.9 (which is sort of 
         * non-optimal). 
         * 
         * Similar issues occured when compiling pike 7.9 with an 
         * installed pike 7.8. 
         * 
         * Simply removing the api check makes all issues just go away. 
         */ 
#if 0 
      if (lower_case(opt[1]) == "max") { 
        // This is used by eg the autodoc extractor, to ensure 
        // that all files are precompilable. 
        api = (int)precompile_api_version; 
        break; 
      } 
      api = (int)opt[1]; 
      if (api > (int)precompile_api_version) { 
        werror("Unsupported API version: %d (max: %d)\n", 
               api, (int)precompile_api_version); 
        return 1; 
      } else if (api < 3) { 
        // The --api option was not supported by the API level 2 precompiler. 
        werror("API level 2 and earlier are implicit, and\n" 
               "must not be specified with the --api option.\n"); 
        return 1; 
      } 
#endif 
      break; 
    case "output": 
      outpath = opt[1]; 
      break; 
    case "base": 
      base = opt[1]; 
      break; 
    } 
  } 
  argv = Getopt.get_args(argv); 
  if( sizeof( argv ) < 2 ) 
  { 
    write((usage/"\n")[0]+"\n"); 
    return 1; 
  } 
  string file = argv[1]; 
 
  x=Stdio.read_file(file)-"\r"; 
 
#if constant(Pike.__HAVE_CPP_PREFIX_SUPPORT__) 
  // Make sure that the user specifies the correct 
  // minimum API level for build-script compatibility. 
  if (api >= 4) { 
    x=sprintf("#cmod_line %d %O\n%s", __LINE__+1, __FILE__, 
              sprintf("#cmod_define cmod_CONCAT_EVAL(x...)\tcmod_CONCAT(x)\n" 
                      "#cmod_define cmod_EVAL(x...)\tcmod_CONCAT(x)\n" 
                      "#cmod_define cmod_STRFY(x...)\t#x\n" 
                      "#cmod_define cmod_DEFINE_EVAL(x...)\tcmod_DEFINE(x)\n" 
                      "#cmod_define cmod_STRFY_EVAL(x...)\tcmod_STRFY( x )\n" 
                      "#cmod_define cmod_REDEFINE(x)\tcmod_DEFINE(##x, x)\n" 
                      "#cmod_define cmod_COMMA ,\n" 
                      "#cmod_line 1 %O\n%s", file, x)); 
    x=cpp(x, ([ 
            "current_file" : file, 
            "prefix" : "cmod", 
            "keep_comments" : 1, 
            "handler" : Handler(([ 
                                  "cmod___SLASH__" : "/", 
                                  "DOCSTART()" : 
                                  lambda() { return "cmod___SLASH__*!"; }, 
                                  "DOCEND()" : 
                                  lambda() { return "*cmod___SLASH__"; }, 
                                  "cmod_DEFINE()" : 
                                  lambda(string x, string y) { 
                                    return sprintf("#ifdef %s\n" 
                                                   "#undef %<s\n" 
                                                   "#endif\n" 
                                                   "#define %<s %s", x, y); 
                                  }, 
                                  "cmod_CONCAT()" : 
                                  lambda(string ... s) { return s*""; }, 
                                  "cmod___CMOD__" : "1", 
                                ])) 
          ])); 
  } else 
#endif 
    if (has_value(x, "cmod_include") || has_value(x, "cmod_define") ){ 
      werror("%[0]s:1: Warning: It looks like %[0]O might use features not present in\n" 
             "%[0]s:1: Warning: the pike used to run the precompiler\n", file); 
    } 
  x=split(x); 
  x=PC.tokenize(x,file); 
  x = convert_comments(x); 
  x=PC.hide_whitespaces(x); 
  x=PC.group(x); 
 
  x = ({ 
    sprintf("/* Generated from %O by precompile.pike running %s\n" 
            " *\n" 
            " * Do NOT edit this file.\n" 
            " */\n", 
            argv[1], version()), 
  }) + DEFINE("PRECOMPILE_API_VERSION", (string)precompile_api_version) + ({ 
    "\n\n", 
  }) 
#if constant(Pike.__HAVE_CPP_PREFIX_SUPPORT__) 
  + DEFINE("cmod___CMOD__", "1") 
#endif 
  + x; 
 
//  werror("%O\n",x); 
 
  x = recursive(allocate_strings, x); 
 
  ParseBlock tmp=ParseBlock(x, base, ""); 
 
  tmp->declarations += ({ 
    "\n\n" 
    "#ifndef PIKE_UNUSED_ATTRIBUTE\n" 
    "#define PIKE_UNUSED_ATTRIBUTE\n" 
    "#endif\n" 
    "#define CMOD_MAP_PROGRAM_IDS_DEFINED 1\n" 
    "static int ___cmod_map_program_ids(int id) PIKE_UNUSED_ATTRIBUTE;\n" 
    "#ifndef TYPEOF\n" 
    "/* Compat with older Pikes. */\n" 
    "#define TYPEOF(SVAL)\t((SVAL).type)\n" 
    "#define SUBTYPEOF(SVAL)\t((SVAL).subtype)\n" 
    "#define SET_SVAL_TYPE(SVAL, TYPE)\t(TYPEOF(SVAL) = TYPE)\n" 
    "#define SET_SVAL_SUBTYPE(SVAL, TYPE)\t(SUBTYPEOF(SVAL) = TYPE)\n" 
    "#define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {\t\\\n" 
    "    /* Set the type afterwards to avoid a clobbered\t\\\n" 
    "     * svalue in case EXPR throws. */\t\t\t\\\n" 
    "    (SVAL).u.FIELD = (EXPR);\t\t\t\t\\\n" 
    "    SET_SVAL_TYPE((SVAL), (TYPE));\t\t\t\\\n" 
    "    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));\t\t\\\n" 
    "  } while(0)\n" 
    "#endif /* !TYPEOF */\n" 
    "#ifndef PIKE_UNUSED\n" 
    "/* Compat with Pike 7.8 and earlier. */\n" 
    "/* NB: Not strictly correct; PIKE_UNUSED was added the\n" 
    " *     day after set_program_id_to_id(), but good enough.\n" 
    " */\n" 
    "static void set_program_id_to_id(void*UNUSED(id)){}\n" 
    "#else /* */\n" 
    "PMOD_EXPORT void set_program_id_to_id( int (*to)(int) );\n" 
    "#endif /* !PIKE_UNUSED */\n" 
    "#if !defined(string_has_null) && !defined(STRING_CONTENT_CHECKED)\n" 
    "/* This symbol was added as a macro in Pike 7.7.20, and is an\n" 
    " * inline function in Pike 7.9.4 and later, at which time the\n" 
    " * flag STRING_CONTENT_CHECKED was added.\n" 
    " */\n" 
    "#define string_has_null(X) (strlen((X)->str)!=(size_t)(X)->len)\n" 
    "#endif\n" 
    "\n\n", 
 
    "#ifndef DEFAULT_CMOD_STORAGE\n" 
    "#define CMOD_COND_USED\n" 
    "#define DEFAULT_CMOD_STORAGE static\n" 
    "#endif\n" 
  }); 
 
 
  tmp->addfuncs = 
    IFDEF("CMOD_MAP_PROGRAM_IDS_DEFINED", 
          resolve_obj_defines() + 
          ({ "set_program_id_to_id( ___cmod_map_program_ids );\n" })) 
    + tmp->addfuncs 
    + IFDEF("CMOD_MAP_PROGRAM_IDS_DEFINED", 
            ({ "set_program_id_to_id( 0 );" })); 
 
  if (last_str_id) { 
    // Add code for allocation and deallocation of the strings. 
    tmp->addfuncs = 
      ({ "\n#ifdef module_strings_declared\n" }) + 
      stradd + 
      ({ "#endif\n" }) + tmp->addfuncs; 
    tmp->exitfuncs += ({ 
      sprintf("\n#ifdef module_strings_declared\n" 
              "{\n" 
              "  int i;\n" 
              "  for(i=0; i < %d; i++) {\n" 
              "    if (module_strings[i]) free_string(module_strings[i]);\n" 
              "    module_strings[i] = NULL;\n" 
              "  }\n" 
              "}\n" 
              "#endif\n", 
              last_str_id), 
    }); 
 
    tmp->declarations += ({ 
      sprintf("#define module_strings_declared\n" 
              "static struct pike_string *module_strings[%d] = {\n" 
              "%s};\n", 
              last_str_id, "  NULL,\n"*last_str_id), 
    }); 
 
    // Same for svalues. 
    // NOTE: This code needs changing in several aspects if 
    //       support for other svalues than strings is added. 
    if (last_svalue_id) { 
      tmp->exitfuncs += ({ 
        sprintf("\n#ifdef module_svalues_declared\n" 
                "free_svalues(module_svalues, %d, BIT_STRING);\n" 
                "#endif\n", 
                last_svalue_id), 
      }); 
      tmp->declarations += ({ 
        sprintf("#define module_svalues_declared\n" 
                "static struct svalue module_svalues[%d];\n", 
                last_svalue_id), 
      }); 
    } 
  } 
 
  x = tmp->code; 
 
  x += ({ 
    "\n" 
    "#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED\n" 
    "static int ___cmod_map_program_ids(int id)\n" 
    "{\n" 
    "  int i = 0;\n" 
    "  if( (id&0x7f000000) != 0x7f000000 ) return id;\n" 
    "  id = id&0x00ffffff;\n" 
  }); 
 
  if( sizeof(map_types) ) 
  { 
    x += ({ "  switch(id) {\n" }); 
    foreach( map_types; int i; string how ) 
    { 
      if( how[0] ) 
        x += ({ "#ifdef "+how[0]+"\n" }); 
      x += ({  "  case "+i+":\n    "+how[1]+"\n    break;\n" }); 
      if( how[0] ) 
        x += ({ "#endif\n" }); 
    } 
    x += ({ "  };\n\n" }); 
  } 
 
  if( sizeof( need_obj_defines ) ) 
  { 
    tmp->declarations += ({ 
      "static struct { INT32 from;INT32 to; } ___cmod_ext_used[" + 
      sizeof( need_obj_defines ) + "];\n" 
    }); 
 
    x += ({ 
      "  while(___cmod_ext_used[i].from ) {\n" 
      "   if( ___cmod_ext_used[i].from == id ) return ___cmod_ext_used[i].to;\n" 
      "   i++;\n" 
      "  }\n" 
    }); 
  } 
  x += ({ 
    "  return 0;\n" 
    "}\n" 
    "#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */\n" 
  }); 
 
  tmp->code = x; 
  x=recursive(replace,x,PC.Token("INIT",0),tmp->addfuncs); 
  int need_init; 
  if ((need_init = equal(x, tmp->code))) 
  { 
    // No INIT, add our own stuff.. 
 
    x+=({ 
      "PIKE_MODULE_INIT {\n", 
      tmp->addfuncs, 
      "}\n", 
    }); 
  } 
  tmp->code = x; 
  x=recursive(replace,x,PC.Token("EXIT",0),tmp->exitfuncs); 
  if(equal(x, tmp->code)) 
  { 
    // No EXIT, add our own stuff.. 
 
    x+=({ 
      "PIKE_MODULE_EXIT {\n", 
      tmp->exitfuncs, 
      "}\n", 
    }); 
 
    if (!need_init) { 
      werror("Warning: INIT without EXIT. Added PIKE_MODULE_EXIT.\n"); 
    } 
  } else if (need_init) { 
    werror("Warning: EXIT without INIT. Added PIKE_MODULE_INIT.\n"); 
  } 
  tmp->code = x; 
 
  // FIXME: This line is fishy; there is no optfuncs in ParseBlock. 
  x=recursive(replace,x,PC.Token("OPTIMIZE",0),tmp->optfuncs); 
 
  foreach( check_used; string key; ) 
  { 
      tmp->declarations += ({ 
          "#ifndef CMOD_COND_USED\n" 
          "# define "+key+"_used 1\n" 
          "#else\n" 
      }); 
      if( find_identifier( x, key ) ) 
          tmp->declarations +=({ "#define "+key+"_used 1\n" }); 
      else 
          tmp->declarations += ({ "#undef "+key+"_used\n" }); 
      tmp->declarations += ({ "#endif\n" }); 
  } 
  tmp->code = x; 
  x=recursive(replace,x,PC.Token("DECLARATIONS",0),tmp->declarations); 
 
 
  if(equal(x,tmp->code)) 
  { 
    // No OPTIMIZE / DECLARATIONS 
    // FIXME: Add our own stuff... 
    // NOTA BENE: DECLARATIONS are not handled automatically 
    //            on the file level 
  } 
  Stdio.File out = Stdio.stdout; 
  if (outpath) { 
    out = Stdio.File(outpath, "twc", 0666); 
  } 
  if(getenv("PIKE_DEBUG_PRECOMPILER")) 
    out->write(PC.simple_reconstitute(x)); 
  else 
    out->write(PC.reconstitute_with_line_numbers(x)); 
}