1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157
|
%{
/*******************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
*******************************************************************************/
/***********************************************************************
* $Header: /cvsroot/SWIG1.1/SWIG/parser.y,v 1.4 1999/08/13 19:34:18 beazley Exp $
*
* parser.y
*
* YACC parser for parsing function declarations.
*
* *** DISCLAIMER ***
*
* This is the most ugly, incredibly henious, and completely unintelligible
* file in SWIG. While it started out simple, it has grown into a
* monster that is almost unmaintainable. A complete parser rewrite is
* currently in progress that should make this file about 1/4 the size
* that it is now. Needless to say, don't modify this file or even look
* at it for that matter!
***********************************************************************/
#define yylex yylex
extern "C" int yylex();
void yyerror (char *s);
extern int line_number;
extern int start_line;
extern void skip_brace(void);
extern void skip_define(void);
extern void skip_decl(void);
extern int skip_cond(int);
extern void skip_to_end(void);
extern void skip_template(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);
extern void scanner_clear_start(void);
extern void start_inline(char *, int);
extern void format_string(char *);
extern void swig_pragma(char *, char *);
#include "internal.h"
#ifdef NEED_ALLOC
void *alloca(unsigned n) {
return((void *) malloc(n));
}
#else
// This redefinition is apparently needed on a number of machines,
// particularly HPUX
#undef alloca
#define alloca malloc
#endif
// Initialization flags. These indicate whether or not certain
// features have been initialized. These were added to allow
// interface files without the block (required in previous
// versions).
static int module_init = 0; /* Indicates whether the %module name was given */
static int title_init = 0; /* Indicates whether %title directive has been given */
static int doc_init = 0;
static int lang_init = 0; /* Indicates if the language has been initialized */
static int i;
int Error = 0;
static char temp_name[128];
static DataType *temp_typeptr, temp_type;
static char yy_rename[256];
static int Rename_true = 0;
static DataType *Active_type = 0; // Used to support variable lists
static int Active_extern = 0; // Whether or not list is external
static int Active_static = 0;
static DataType *Active_typedef = 0; // Used for typedef lists
static int InArray = 0; // Used when an array declaration is found
static int in_then = 0;
static int in_else = 0;
static int allow = 1; // Used during conditional compilation
static int doc_scope = 0; // Documentation scoping
static String ArrayString; // Array type attached to parameter names
static String ArrayBackup; // Array backup string
static char *DefArg = 0; // Default argument hack
static char *ConstChar = 0; // Used to store raw character constants
static ParmList *tm_parm = 0; // Parameter list used to hold typemap parameters
static Hash name_hash; // Hash table containing renamings
char *objc_construct = "new"; // Objective-C constructor
char *objc_destruct = "free"; // Objective-C destructor
/* Some macros for building constants */
#define E_BINARY(TARGET, SRC1, SRC2, OP) \
TARGET = new char[strlen(SRC1) + strlen(SRC2) +strlen(OP)+1];\
sprintf(TARGET,"%s%s%s",SRC1,OP,SRC2);
/* C++ modes */
#define CPLUS_PUBLIC 1
#define CPLUS_PRIVATE 2
#define CPLUS_PROTECTED 3
int cplus_mode;
// Declarations of some functions for handling C++
extern void cplus_open_class(char *name, char *rname, char *ctype);
extern void cplus_member_func(char *, char *, DataType *, ParmList *, int);
extern void cplus_constructor(char *, char *, ParmList *);
extern void cplus_destructor(char *, char *);
extern void cplus_variable(char *, char *, DataType *);
extern void cplus_static_func(char *, char *, DataType *, ParmList *);
extern void cplus_declare_const(char *, char *, DataType *, char *);
extern void cplus_class_close(char *);
extern void cplus_inherit(int, char **);
extern void cplus_cleanup(void);
extern void cplus_static_var(char *, char *, DataType *);
extern void cplus_register_type(char *);
extern void cplus_register_scope(Hash *);
extern void cplus_inherit_scope(int, char **);
extern void cplus_add_pragma(char *, char *, char *);
extern DocEntry *cplus_set_class(char *);
extern void cplus_unset_class();
extern void cplus_abort();
// ----------------------------------------------------------------------
// static init_language()
//
// Initialize the target language.
// Does nothing if this function has already been called.
// ----------------------------------------------------------------------
static void init_language() {
if (!lang_init) {
lang->initialize();
// Initialize the documentation system
if (!doctitle) {
doctitle = new DocTitle(title,0);
}
if (!doc_init)
doctitle->usage = title;
doc_stack[0] = doctitle;
doc_stack_top = 0;
int oldignore = IgnoreDoc;
IgnoreDoc = 1;
if (ConfigFile) {
include_file(ConfigFile);
}
IgnoreDoc = oldignore;
}
lang_init = 1;
title_init = 1;
}
// ----------------------------------------------------------------------
// int promote(int t1, int t2)
//
// Promote types (for constant expressions)
// ----------------------------------------------------------------------
int promote(int t1, int t2) {
if ((t1 == T_ERROR) || (t2 == T_ERROR)) return T_ERROR;
if ((t1 == T_DOUBLE) || (t2 == T_DOUBLE)) return T_DOUBLE;
if ((t1 == T_FLOAT) || (t2 == T_FLOAT)) return T_FLOAT;
if ((t1 == T_ULONG) || (t2 == T_ULONG)) return T_ULONG;
if ((t1 == T_LONG) || (t2 == T_LONG)) return T_LONG;
if ((t1 == T_UINT) || (t2 == T_UINT)) return T_UINT;
if ((t1 == T_INT) || (t2 == T_INT)) return T_INT;
if ((t1 == T_USHORT) || (t2 == T_USHORT)) return T_SHORT;
if ((t1 == T_SHORT) || (t2 == T_SHORT)) return T_SHORT;
if ((t1 == T_UCHAR) || (t2 == T_UCHAR)) return T_UCHAR;
if (t1 != t2) {
fprintf(stderr,"%s : Line %d. Type mismatch in constant expression\n",
input_file, line_number);
FatalError();
}
return t1;
}
/* Generate the scripting name of an object. Takes %name directive into
account among other things */
static char *make_name(char *name) {
// Check to see if the name is in the hash
char *nn = (char *) name_hash.lookup(name);
if (nn) return nn; // Yep, return it.
if (Rename_true) {
Rename_true = 0;
return yy_rename;
} else {
// Now check to see if the name contains a $
if (strchr(name,'$')) {
static String temp;
temp = "";
temp << name;
temp.replace("$","_S_");
return temp;
} else {
return name;
}
}
}
/* Return the parent of a documentation entry. If wrapping externally, this is 0 */
static DocEntry *doc_parent() {
if (!WrapExtern)
return doc_stack[doc_stack_top];
else
return 0;
}
// ----------------------------------------------------------------------
// create_function(int ext, char *name, DataType *t, ParmList *l)
//
// Creates a function and manages documentation creation. Really
// only used internally to the parser.
// ----------------------------------------------------------------------
void create_function(int ext, char *name, DataType *t, ParmList *l) {
if (Active_static) return; // Static declaration. Ignore
init_language();
if (WrapExtern) return; // External wrapper file. Ignore
char *iname = make_name(name);
// Check if symbol already exists
if (add_symbol(iname, t, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, iname);
} else {
Stat_func++;
if (Verbose) {
fprintf(stderr,"Wrapping function : ");
emit_extern_func(name, t, l, 0, stderr);
}
// If extern, make an extern declaration in the SWIG wrapper file
if (ext)
emit_extern_func(name, t, l, ext, f_header);
else if (ForceExtern) {
emit_extern_func(name, t, l, 1, f_header);
}
// If this function has been declared inline, produce a function
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
lang->create_function(name, iname, t, l);
l->check_defined();
t->check_defined();
}
scanner_clear_start();
}
// -------------------------------------------------------------------
// create_variable(int ext, char *name, DataType *t)
//
// Create a link to a global variable.
// -------------------------------------------------------------------
void create_variable(int ext, char *name, DataType *t) {
if (WrapExtern) return; // External wrapper file. Ignore
int oldstatus = Status;
if (Active_static) return; // If static ignore
init_language();
char *iname = make_name(name);
if (add_symbol(iname, t, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n",
input_file, line_number, iname);
} else {
Stat_var++;
if (Verbose) {
fprintf(stderr,"Wrapping variable : ");
emit_extern_var(name, t, 0, stderr);
}
// If externed, output an external declaration
if (ext)
emit_extern_var(name, t, ext, f_header);
else if (ForceExtern) {
emit_extern_var(name, t, 1, f_header);
}
// If variable datatype is read-only, we'll force it to be readonly
if (t->status & STAT_READONLY) Status = Status | STAT_READONLY;
// Now dump it out
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
lang->link_variable(name, iname, t);
t->check_defined();
Status = oldstatus;
}
scanner_clear_start();
}
// ------------------------------------------------------------------
// create_constant(char *name, DataType *type, char *value)
//
// Creates a new constant.
// -------------------------------------------------------------------
void create_constant(char *name, DataType *type, char *value) {
if (Active_static) return;
if (WrapExtern) return; // External wrapper file. Ignore
init_language();
if (Rename_true) {
fprintf(stderr,"%s : Line %d. %%name directive ignored with #define\n",
input_file, line_number);
Rename_true = 0;
}
if ((type->type == T_CHAR) && (!type->is_pointer))
type->is_pointer++;
if (!value) value = copy_string(name);
sprintf(temp_name,"const:%s", name);
if (add_symbol(temp_name, type, value)) {
fprintf(stderr,"%s : Line %d. Constant %s multiply defined. (2nd definition ignored)\n",
input_file, line_number, name);
} else {
// Update symbols value if already defined.
update_symbol(name, type, value);
if (!WrapExtern) { // Only wrap the constant if not in %extern mode
Stat_const++;
if (Verbose)
fprintf(stderr,"Creating constant %s = %s\n", name, value);
doc_entry = new DocDecl(name,doc_stack[doc_stack_top]);
lang->declare_const(name, name, type, value);
type->check_defined();
}
}
scanner_clear_start();
}
/* Print out array brackets */
void print_array() {
int i;
for (i = 0; i < InArray; i++)
fprintf(stderr,"[]");
}
/* manipulate small stack for managing if-then-else */
static int then_data[100];
static int else_data[100];
static int allow_data[100];
static int te_index = 0;
static int prev_allow = 1;
void if_push() {
then_data[te_index] = in_then;
else_data[te_index] = in_else;
allow_data[te_index] = allow;
prev_allow = allow;
te_index++;
if (te_index >= 100) {
fprintf(stderr,"SWIG. Internal parser error. if-then-else stack overflow.\n");
SWIG_exit(1);
}
}
void if_pop() {
if (te_index > 0) {
te_index--;
in_then = then_data[te_index];
in_else = else_data[te_index];
allow = allow_data[te_index];
if (te_index > 0) {
prev_allow = allow_data[te_index-1];
} else {
prev_allow = 1;
}
}
}
// Structures for handling code fragments built for nested classes
struct Nested {
String code; // Associated code fragment
int line; // line number where it starts
char *name; // Name associated with this nested class
DataType *type; // Datatype associated with the name
Nested *next; // Next code fragment in list
};
// Some internal variables for saving nested class information
static Nested *nested_list = 0;
// Add a function to the nested list
static void add_nested(Nested *n) {
Nested *n1;
if (!nested_list) nested_list = n;
else {
n1 = nested_list;
while (n1->next) n1 = n1->next;
n1->next = n;
}
}
// Dump all of the nested class declarations to the inline processor
// However. We need to do a few name replacements and other munging
// first. This function must be called before closing a class!
static void dump_nested(char *parent) {
Nested *n,*n1;
n = nested_list;
int oldstatus = Status;
Status = STAT_READONLY;
while (n) {
// Token replace the name of the parent class
n->code.replace("$classname",parent);
// Fix up the name of the datatype (for building typedefs and other stuff)
sprintf(n->type->name,"%s_%s",parent,n->name);
// Add the appropriate declaration to the C++ processor
doc_entry = new DocDecl(n->name,doc_stack[doc_stack_top]);
cplus_variable(n->name,(char *) 0, n->type);
// Dump the code to the scanner
if (Verbose)
fprintf(stderr,"Splitting from %s : (line %d) \n%s\n", parent,n->line, n->code.get());
fprintf(f_header,"\n%s\n", n->code.get());
start_inline(n->code.get(),n->line);
n1 = n->next;
delete n;
n = n1;
}
nested_list = 0;
Status = oldstatus;
}
%}
/* The type of each node in the parse tree
must be one of the elements of the union
given below. This is used to derive the
C++ declaration for "yylval" that appears
in parser.tab.h. */
%union {
char *id;
struct Declaration {
char *id;
int is_pointer;
int is_reference;
} decl;
struct InitList {
char **names;
int count;
} ilist;
struct DocList {
char **names;
char **values;
int count;
} dlist;
struct Define {
char *id;
int type;
} dtype;
DataType *type;
Parm *p;
TMParm *tmparm;
ParmList *pl;
int ivalue;
};
%token <id> ID
%token <id> HBLOCK WRAPPER POUND
%token <id> STRING
%token <id> NUM_INT NUM_FLOAT CHARCONST NUM_UNSIGNED NUM_LONG NUM_ULONG
%token <ivalue> TYPEDEF
%token <type> TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_TYPEDEF
%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE DEFINE PERIOD
%token CONST STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET
%token WEXTERN ILLEGAL
%token READONLY READWRITE NAME RENAME INCLUDE CHECKOUT ADDMETHODS PRAGMA
%token CVALUE COUT
%token ENUM ENDDEF MACRO
%token CLASS PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND OPERATOR THROW TEMPLATE
%token NATIVE INLINE
%token IFDEF IFNDEF ENDIF ELSE UNDEF IF DEFINED ELIF
%token RAW_MODE ALPHA_MODE TEXT DOC_DISABLE DOC_ENABLE STYLE LOCALSTYLE
%token TYPEMAP EXCEPT IMPORT ECHO NEW APPLY CLEAR DOCONLY
%token <ivalue> TITLE SECTION SUBSECTION SUBSUBSECTION
%token LESSTHAN GREATERTHAN
%token <id> USERDIRECTIVE
/* Objective C tokens */
%token OC_INTERFACE OC_END OC_PUBLIC OC_PRIVATE OC_PROTECTED OC_CLASS OC_IMPLEMENT OC_PROTOCOL
%left OR
%left XOR
%left AND
%left LSHIFT RSHIFT
%left PLUS MINUS
%left STAR SLASH
%left UMINUS NOT LNOT
%left DCOLON
%type <ivalue> extern array array2 parm_specifier parm_specifier_list;
%type <pl> parms ptail;
%type <p> parm parm_type;
%type <tmparm> typemap_parm tm_list tm_tail;
%type <id> pname cpptype base_specifier access_specifier typemap_name tm_method idstring;
%type <type> type opt_signed opt_unsigned strict_type;
%type <decl> declaration nested_decl;
%type <ivalue> stars cpp_const_expr;
%type <ilist> initlist base_list inherit;
%type <dtype> definetype definetail def_args;
%type <dtype> etype;
%type <dtype> expr;
%type <id> ename stylearg objc_inherit;
%type <dlist> stylelist styletail;
%type <type> objc_ret_type objc_arg_type;
%type <id> objc_protolist objc_separator;
%type <pl> objc_args;
%%
/* The productions of the grammar with their
associated semantic actions. */
program : {
{
int ii;
for (ii = 0; ii < 256; ii++) {
handler_stack[ii] = 0;
}
handler_stack[0] = comment_handler;
}
doc_stack[0] = doctitle;
} command {
CommentHandler::cleanup();
cplus_cleanup();
doc_entry = doctitle;
if (lang_init) {
lang->close();
}
if (te_index) {
fprintf(stderr,"%s : EOF. Missing #endif detected.\n", input_file);
FatalError();
}
}
;
command : command statement {
scanner_clear_start();
Error = 0;
}
| empty {
}
;
statement : INCLUDE idstring {
if (allow) {
// init_language();
doc_entry = 0;
// comment_handler->clear();
include_file($2);
}
}
/* %extern directive */
| WEXTERN idstring {
if (allow) {
int oldextern = WrapExtern;
// init_language();
doc_entry = 0;
// comment_handler->clear();
WrapExtern = 1;
if (include_file($2) >= 0) {
add_symbol("SWIGEXTERN",0,0);
} else {
WrapExtern = oldextern;
}
}
}
/* %import directive. Like %extern but calls out to a language module */
| IMPORT idstring {
if (allow) {
int oldextern = WrapExtern;
init_language();
doc_entry = 0;
WrapExtern = 1;
if (include_file($2) >= 0) {
add_symbol("SWIGEXTERN",0,0);
lang->import($2);
} else {
WrapExtern = oldextern;
}
}
}
/* %checkout directive. Like %include, but simply copies the file into the
current directory */
| CHECKOUT idstring {
if (allow) {
if ((checkout_file($2,$2)) == 0) {
fprintf(stderr,"%s checked out from the SWIG library.\n",$2);
}
}
}
/* An unknown C preprocessor statement. Just throw it away */
| POUND {
if (allow) {
doc_entry = 0;
if (Verbose) {
fprintf(stderr,"%s : Line %d. CPP %s ignored.\n", input_file, line_number,$1);
}
}
}
/* A variable declaration */
| extern type declaration array2 def_args {
if (allow) {
init_language();
if (Active_type) delete Active_type;
Active_type = new DataType($2);
Active_extern = $1;
$2->is_pointer += $3.is_pointer;
if ($4 > 0) {
$2->is_pointer++;
$2->status = STAT_READONLY;
$2->arraystr = copy_string(ArrayString);
}
if ($3.is_reference) {
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
FatalError();
} else {
if ($2->qualifier) {
if ((strcmp($2->qualifier,"const") == 0)) {
if ($5.type != T_ERROR)
create_constant($3.id, $2, $5.id);
} else
create_variable($1,$3.id,$2);
} else
create_variable($1,$3.id,$2);
}
}
delete $2;
} stail { }
/* Global variable that smells like a function pointer */
| extern strict_type LPAREN STAR {
skip_decl();
fprintf(stderr,"%s : Line %d. Function pointers not currently supported.\n",
input_file, line_number);
}
/* A static variable declaration (Ignored) */
| STATIC type declaration array2 def_args {
if (Verbose) {
fprintf(stderr,"static variable %s ignored.\n",$3.id);
}
Active_static = 1;
delete $2;
} stail {
Active_static = 0;
}
/* Global variable that smells like a function pointer */
| STATIC strict_type LPAREN STAR {
skip_decl();
fprintf(stderr,"%s : Line %d. Function pointers not currently supported.\n",
input_file, line_number);
}
/* A function declaration */
| extern type declaration LPAREN parms RPAREN cpp_const {
if (allow) {
init_language();
if (Active_type) delete Active_type;
Active_type = new DataType($2);
Active_extern = $1;
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
create_function($1, $3.id, $2, $5);
}
delete $2;
delete $5;
} stail { }
/* A function declaration with code after it */
| extern type declaration LPAREN parms RPAREN func_end {
if (allow) {
init_language();
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
create_function($1, $3.id, $2, $5);
}
delete $2;
delete $5;
};
/* A function declared without any return datatype */
| extern declaration LPAREN parms RPAREN cpp_const {
if (allow) {
init_language();
DataType *t = new DataType(T_INT);
t->is_pointer += $2.is_pointer;
t->is_reference = $2.is_reference;
create_function($1,$2.id,t,$4);
delete t;
}
} stail { };
/* A static function declaration code after it */
| STATIC type declaration LPAREN parms RPAREN func_end {
if ((allow) && (Inline)) {
if (strlen(CCode.get())) {
init_language();
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
create_function(0, $3.id, $2, $5);
}
}
delete $2;
delete $5;
};
/* A function with an explicit inline directive. Not safe to use inside a %inline block */
| INLINE type declaration LPAREN parms RPAREN func_end {
if (allow) {
init_language();
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
if (Inline) {
fprintf(stderr,"%s : Line %d. Repeated %%inline directive.\n",input_file,line_number);
FatalError();
} else {
if (strlen(CCode.get())) {
fprintf(f_header,"static ");
emit_extern_func($3.id,$2,$5,3,f_header);
fprintf(f_header,"%s\n",CCode.get());
}
create_function(0, $3.id, $2, $5);
}
}
delete $2;
delete $5;
};
/* A static function declaration (ignored) */
| STATIC type declaration LPAREN parms RPAREN cpp_const {
if (allow) {
if (Verbose) {
fprintf(stderr,"static function %s ignored.\n", $3.id);
}
}
Active_static = 1;
delete $2;
delete $5;
} stail {
Active_static = 0;
}
/* Enable Read-only mode */
| READONLY {
if (allow)
Status = Status | STAT_READONLY;
}
/* Enable Read-write mode */
| READWRITE {
if (allow)
Status = Status & ~STAT_READONLY;
}
/* New %name directive */
| NAME LPAREN ID RPAREN {
if (allow) {
strcpy(yy_rename,$3);
Rename_true = 1;
}
}
/* %rename directive */
| RENAME ID ID SEMI {
if (name_hash.lookup($2)) {
name_hash.remove($2);
}
name_hash.add($2,copy_string($3));
}
/* %new directive */
| NEW {
NewObject = 1;
} statement {
NewObject = 0;
}
/* Empty name directive. No longer allowed */
| NAME LPAREN RPAREN {
if (allow) {
fprintf(stderr,"%s : Lind %d. Empty %%name() is no longer supported.\n",
input_file, line_number);
FatalError();
}
} cpp {
Rename_true = 0;
}
/* A native wrapper function */
| NATIVE LPAREN ID RPAREN extern ID SEMI {
if (allow && (!WrapExtern)) {
init_language();
if (add_symbol($3,(DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n",
input_file, line_number, $3);
} else {
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
lang->add_native($3,$6);
}
}
}
| NATIVE LPAREN ID RPAREN extern type declaration LPAREN parms RPAREN SEMI {
if (allow && (!WrapExtern)) {
init_language();
$6->is_pointer += $7.is_pointer;
if (add_symbol($3,(DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n",
input_file, line_number, $3);
} else {
if ($5) {
emit_extern_func($7.id, $6, $9, $5, f_header);
}
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
lang->add_native($3,$7.id);
}
}
delete $6;
delete $9;
}
/* %title directive */
| TITLE STRING styletail {
if (allow && (!WrapExtern)) {
if (!title_init) {
title_init = 1;
doc_init = 1;
if (!comment_handler) {
comment_handler = new CommentHandler();
}
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
comment_handler->style($3.names[ii],$3.values[ii]);
}
}
// Create a new title for documentation
{
int temp = line_number;
line_number = $1;
if (!doctitle)
doctitle = new DocTitle($2,0);
else {
doctitle->name = copy_string(title);
doctitle->line_number = $1;
doctitle->end_line = $1;
}
line_number = temp;
}
doctitle->usage = $2;
doc_entry = doctitle;
doc_stack[0] = doc_entry;
doc_stack_top = 0;
handler_stack[0] = comment_handler;
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
doc_stack[doc_stack_top]->style($3.names[ii],$3.values[ii]);
}
}
} else {
// Ignore it
}
}
}
/* %section directive */
| SECTION STRING styletail {
if (allow && (!WrapExtern) && (!IgnoreDoc)) {
// Copy old comment handler
// if (handler_stack[1]) delete handler_stack[1];
handler_stack[1] = new CommentHandler(handler_stack[0]);
comment_handler = handler_stack[1];
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
comment_handler->style($3.names[ii],$3.values[ii]);
}
}
{
int temp = line_number;
line_number = $1;
doc_entry = new DocSection($2,doc_stack[0]);
line_number = temp;
}
doc_stack_top = 1;
doc_stack[1] = doc_entry;
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
doc_stack[doc_stack_top]->style($3.names[ii],$3.values[ii]);
}
}
}
}
/* %subsection directive */
| SUBSECTION STRING styletail {
if (allow && (!WrapExtern) && (!IgnoreDoc)) {
if (doc_stack_top < 1) {
fprintf(stderr,"%s : Line %d. Can't apply %%subsection here.\n", input_file,line_number);
FatalError();
} else {
// Copy old comment handler
// if (handler_stack[2]) delete handler_stack[2];
handler_stack[2] = new CommentHandler(handler_stack[1]);
comment_handler = handler_stack[2];
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
comment_handler->style($3.names[ii],$3.values[ii]);
}
}
{
int temp = line_number;
line_number = $1;
doc_entry = new DocSection($2,doc_stack[1]);
line_number = temp;
}
doc_stack_top = 2;
doc_stack[2] = doc_entry;
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
doc_stack[doc_stack_top]->style($3.names[ii],$3.values[ii]);
}
}
}
}
}
/* %subsubsection directive */
| SUBSUBSECTION STRING styletail {
if (allow && (!WrapExtern) && (!IgnoreDoc)) {
if (doc_stack_top < 2) {
fprintf(stderr,"%s : Line %d. Can't apply %%subsubsection here.\n", input_file,line_number);
FatalError();
} else {
// Copy old comment handler
// if (handler_stack[3]) delete handler_stack[3];
handler_stack[3] = new CommentHandler(handler_stack[2]);
comment_handler = handler_stack[3];
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
comment_handler->style($3.names[ii],$3.values[ii]);
}
}
{
int temp = line_number;
line_number = $1;
doc_entry = new DocSection($2,doc_stack[2]);
line_number = temp;
}
doc_stack_top = 3;
doc_stack[3] = doc_entry;
{
int ii;
for (ii = 0; ii < $3.count; ii++) {
doc_stack[doc_stack_top]->style($3.names[ii],$3.values[ii]);
}
}
}
}
}
/* %alpha directive (obsolete) */
| ALPHA_MODE {
if (allow && (!WrapExtern)) {
fprintf(stderr,"%%alpha directive is obsolete. Use '%%style sort' instead.\n");
handler_stack[0]->style("sort",0);
doc_stack[0]->style("sort",0);
}
}
/* %raw directive (obsolete) */
| RAW_MODE {
if (allow && (!WrapExtern)) {
fprintf(stderr,"%%raw directive is obsolete. Use '%%style nosort' instead.\n");
handler_stack[0]->style("nosort",0);
doc_stack[0]->style("nosort",0);
}
}
| doc_enable { }
/* %text directive */
| TEXT HBLOCK {
if (allow && (!WrapExtern)) {
$2[strlen($2) - 1] = 0;
doc_entry = new DocText($2,doc_stack[doc_stack_top]);
doc_entry = 0;
}
}
| typedef_decl { }
/* Code insertion block */
| HBLOCK {
if (allow && (!WrapExtern)) {
init_language();
$1[strlen($1) - 1] = 0;
// fprintf(f_header,"#line %d \"%s\"\n", start_line, input_file);
fprintf(f_header, "%s\n", $1);
}
}
/* Super-secret undocumented for people who really know what's going on feature */
| WRAPPER HBLOCK {
if (allow && (!WrapExtern)) {
init_language();
$2[strlen($2) - 1] = 0;
fprintf(f_wrappers,"%s\n",$2);
}
}
/* Initialization code */
| INIT HBLOCK {
if (allow && (!WrapExtern)) {
init_language();
$2[strlen($2) -1] = 0;
fprintf(f_init,"%s\n", $2);
}
}
/* Inline block */
| INLINE HBLOCK {
if (allow && (!WrapExtern)) {
init_language();
$2[strlen($2) - 1] = 0;
fprintf(f_header, "%s\n", $2);
start_inline($2,start_line);
}
}
/* Echo mode */
| ECHO HBLOCK {
if (allow && (!WrapExtern)) {
fprintf(stderr,"%s\n", $2);
}
}
| ECHO STRING {
if (allow && (!WrapExtern)) {
fprintf(stderr,"%s\n", $2);
}
}
/* Disable code generation */
| DOCONLY {
DocOnly = 1;
}
/* Init directive--to avoid errors in other modules */
| INIT ID initlist {
if (allow) {
if (!module_init) {
lang->set_init($2);
module_init = 1;
init_language();
} else {
if (Verbose)
fprintf(stderr,"%s : Line %d. %%init %s ignored.\n",
input_file, line_number, $2);
}
if ($3.count > 0) {
fprintf(stderr,"%s : Line %d. Warning. Init list no longer supported.\n",
input_file,line_number);
}
}
for (i = 0; i < $3.count; i++)
if ($3.names[i]) delete [] $3.names[i];
delete [] $3.names;
}
/* Module directive */
| MODULE ID initlist {
if (allow) {
if ($3.count)
lang->set_module($2,$3.names);
else
lang->set_module($2,0);
module_init = 1;
init_language();
}
for (i = 0; i < $3.count; i++)
if ($3.names[i]) delete [] $3.names[i];
delete [] $3.names;
}
/* #define directive */
| DEFINE ID definetail {
if (allow) {
if (($3.type != T_ERROR) && ($3.type != T_SYMBOL)) {
init_language();
temp_typeptr = new DataType($3.type);
create_constant($2, temp_typeptr, $3.id);
delete temp_typeptr;
} else if ($3.type == T_SYMBOL) {
// Add a symbol to the SWIG symbol table
if (add_symbol($2,(DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Warning. Symbol %s already defined.\n",
input_file,line_number, $2);
}
}
}
}
/* A CPP Macro. Ignore (hopefully) */
| DEFINE MACRO {
if (Verbose) {
fprintf(stderr,"%s : Line %d. CPP Macro ignored.\n", input_file, line_number);
}
}
/* An undef directive */
| UNDEF ID {
remove_symbol($2);
}
/* Enumerations */
| extern ENUM ename LBRACE { scanner_clear_start(); } enumlist RBRACE SEMI {
if (allow) {
init_language();
if ($3) {
temp_type.type = T_INT;
temp_type.is_pointer = 0;
temp_type.implicit_ptr = 0;
sprintf(temp_type.name,"int");
temp_type.typedef_add($3,1);
}
}
}
/* A typdef'd enum. Pretty common in C headers */
| TYPEDEF ENUM ename LBRACE { scanner_clear_start(); } enumlist RBRACE ID {
if (allow) {
init_language();
temp_type.type = T_INT;
temp_type.is_pointer = 0;
temp_type.implicit_ptr = 0;
sprintf(temp_type.name,"int");
Active_typedef = new DataType(&temp_type);
temp_type.typedef_add($8,1);
}
} typedeflist { }
/* -----------------------------------------------------------------
typemap support.
These constructs are used to support type-maps.
----------------------------------------------------------------- */
/* Create a new typemap */
| TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
TMParm *p;
skip_brace();
p = $7;
while (p) {
typemap_register($5,$3,p->p->t,p->p->name,CCode,p->args);
p = p->next;
}
delete $3;
delete $5;
}
/* Create a new typemap in current language */
| TYPEMAP LPAREN tm_method RPAREN tm_list LBRACE {
if (!typemap_lang) {
fprintf(stderr,"SWIG internal error. No typemap_lang specified.\n");
fprintf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number);
FatalError();
} else {
TMParm *p;
skip_brace();
p = $5;
while (p) {
typemap_register($3,typemap_lang,p->p->t,p->p->name,CCode,p->args);
p = p->next;
}
}
delete $3;
}
/* Clear a typemap */
| TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list SEMI {
TMParm *p;
p = $7;
while (p) {
typemap_clear($5,$3,p->p->t,p->p->name);
p = p->next;
}
delete $3;
delete $5;
}
/* Clear a typemap in current language */
| TYPEMAP LPAREN tm_method RPAREN tm_list SEMI {
if (!typemap_lang) {
fprintf(stderr,"SWIG internal error. No typemap_lang specified.\n");
fprintf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number);
FatalError();
} else {
TMParm *p;
p = $5;
while (p) {
typemap_clear($3,typemap_lang,p->p->t,p->p->name);
p = p->next;
}
}
delete $3;
}
/* Copy a typemap */
| TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list EQUAL typemap_parm SEMI {
TMParm *p;
p = $7;
while (p) {
typemap_copy($5,$3,$9->p->t,$9->p->name,p->p->t,p->p->name);
p = p->next;
}
delete $3;
delete $5;
delete $9->p;
delete $9;
}
/* Copy typemap in current language */
| TYPEMAP LPAREN tm_method RPAREN tm_list EQUAL typemap_parm SEMI {
if (!typemap_lang) {
fprintf(stderr,"SWIG internal error. No typemap_lang specified.\n");
fprintf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number);
FatalError();
} else {
TMParm *p;
p = $5;
while (p) {
typemap_copy($3,typemap_lang,$7->p->t,$7->p->name,p->p->t,p->p->name);
p = p->next;
}
}
delete $3;
delete $7->p;
delete $7;
}
/* -----------------------------------------------------------------
apply and clear support (for typemaps)
----------------------------------------------------------------- */
| APPLY typemap_parm LBRACE tm_list RBRACE {
TMParm *p;
p = $4;
while(p) {
typemap_apply($2->p->t,$2->p->name,p->p->t,p->p->name);
p = p->next;
}
delete $4;
delete $2->args;
delete $2;
}
| CLEAR tm_list SEMI {
TMParm *p;
p = $2;
while (p) {
typemap_clear_apply(p->p->t, p->p->name);
p = p->next;
}
}
/* -----------------------------------------------------------------
exception support
These constructs are used to define exceptions
----------------------------------------------------------------- */
/* An exception definition */
| EXCEPT LPAREN ID RPAREN LBRACE {
skip_brace();
fragment_register("except",$3, CCode);
delete $3;
}
/* A Generic Exception (no language specified */
| EXCEPT LBRACE {
skip_brace();
fragment_register("except",typemap_lang, CCode);
}
/* Clear an exception */
| EXCEPT LPAREN ID RPAREN SEMI {
fragment_clear("except",$3);
}
/* Generic clear */
| EXCEPT SEMI {
fragment_clear("except",typemap_lang);
}
/* Miscellaenous stuff */
| SEMI { }
| cpp { }
| objective_c { }
| error {
if (!Error) {
{
static int last_error_line = -1;
if (last_error_line != line_number) {
fprintf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number);
FatalError();
last_error_line = line_number;
// Try to make some kind of recovery.
skip_decl();
}
Error = 1;
}
}
}
/* A an extern C type declaration. Does nothing, but is ignored */
| EXTERN STRING LBRACE command RBRACE { }
| cond_compile { }
/* Officially, this directive doesn't exist yet */
| pragma { }
/* %style directive. This applies to all current styles */
| STYLE stylelist {
{
int ii,jj;
for (ii = 0; ii < $2.count; ii++) {
comment_handler->style($2.names[ii],$2.values[ii]);
for (jj = 0; jj < doc_stack_top; jj++)
doc_stack[jj]->style($2.names[ii],$2.values[ii]);
if (doctitle)
doctitle->style($2.names[ii],$2.values[ii]);
doc->style($2.names[ii],$2.values[ii]);
}
}
}
/* %localstyle directive. This applies only to the current style */
| LOCALSTYLE stylelist {
{
int ii;
for (ii = 0; ii < $2.count; ii++) {
comment_handler = new CommentHandler(comment_handler);
handler_stack[doc_stack_top] = comment_handler;
comment_handler->style($2.names[ii],$2.values[ii]);
doc_stack[doc_stack_top]->style($2.names[ii],$2.values[ii]);
}
}
}
/* User defined directive */
| user_directive{ }
;
/* Dcumentation disable/enable */
doc_enable : DOC_DISABLE {
if (allow) {
if (IgnoreDoc) {
/* Already in a disabled documentation */
doc_scope++;
} else {
if (Verbose)
fprintf(stderr,"%s : Line %d. Documentation disabled.\n", input_file, line_number);
IgnoreDoc = 1;
doc_scope = 1;
}
}
}
/* %enabledoc directive */
| DOC_ENABLE {
if (allow) {
if (IgnoreDoc) {
if (doc_scope > 1) {
doc_scope--;
} else {
if (Verbose)
fprintf(stderr,"%s : Line %d. Documentation enabled.\n", input_file, line_number);
IgnoreDoc = 0;
doc_scope = 0;
}
}
}
}
;
/* Note : This really needs to be re-done */
/* A typedef with pointers */
typedef_decl : TYPEDEF type declaration {
if (allow) {
init_language();
/* Add a new typedef */
Active_typedef = new DataType($2);
$2->is_pointer += $3.is_pointer;
$2->typedef_add($3.id);
/* If this is %typedef, add it to the header */
if ($1)
fprintf(f_header,"typedef %s %s;\n", $2->print_full(), $3.id);
cplus_register_type($3.id);
}
} typedeflist { };
/* A rudimentary typedef involving function pointers */
| TYPEDEF type LPAREN STAR pname RPAREN LPAREN parms RPAREN SEMI {
if (allow) {
init_language();
/* Typedef'd pointer */
if ($1) {
sprintf(temp_name,"(*%s)",$5);
fprintf(f_header,"typedef ");
emit_extern_func(temp_name, $2,$8,0,f_header);
}
strcpy($2->name,"<function ptr>");
$2->type = T_USER;
$2->is_pointer = 1;
$2->typedef_add($5,1);
cplus_register_type($5);
}
delete $2;
delete $5;
delete $8;
}
/* A typedef involving function pointers again */
| TYPEDEF type stars LPAREN STAR pname RPAREN LPAREN parms RPAREN SEMI {
if (allow) {
init_language();
if ($1) {
$2->is_pointer += $3;
sprintf(temp_name,"(*%s)",$6);
fprintf(f_header,"typedef ");
emit_extern_func(temp_name, $2,$9,0,f_header);
}
/* Typedef'd pointer */
strcpy($2->name,"<function ptr>");
$2->type = T_USER;
$2->is_pointer = 1;
$2->typedef_add($6,1);
cplus_register_type($6);
}
delete $2;
delete $6;
delete $9;
}
/* A typedef involving arrays */
| TYPEDEF type declaration array {
if (allow) {
init_language();
Active_typedef = new DataType($2);
// This datatype is going to be readonly
$2->status = STAT_READONLY | STAT_REPLACETYPE;
$2->is_pointer += $3.is_pointer;
// Turn this into a "pointer" corresponding to the array
$2->is_pointer++;
$2->arraystr = copy_string(ArrayString);
$2->typedef_add($3.id);
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap\n",input_file,line_number, $3.id);
cplus_register_type($3.id);
}
} typedeflist { }
;
/* ------------------------------------------------------------------------
Typedef list
The following rules are used to manage typedef lists. Only a temporary
hack until the SWIG 2.0 parser gets online.
Active_typedef contains the datatype of the last typedef (if applicable)
------------------------------------------------------------------------ */
typedeflist : COMMA declaration typedeflist {
if (allow) {
if (Active_typedef) {
DataType *t;
t = new DataType(Active_typedef);
t->is_pointer += $2.is_pointer;
t->typedef_add($2.id);
cplus_register_type($2.id);
delete t;
}
}
}
| COMMA declaration array {
DataType *t;
t = new DataType(Active_typedef);
t->status = STAT_READONLY | STAT_REPLACETYPE;
t->is_pointer += $2.is_pointer + 1;
t->arraystr = copy_string(ArrayString);
t->typedef_add($2.id);
cplus_register_type($2.id);
delete t;
fprintf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap.\n",input_file,line_number, $2.id);
}
| empty { }
;
/* ----------------------------------------------------------------------------------
Conditional Compilation
SWIG supports the following constructs
#ifdef
#ifndef
#else
#endif
#if defined(ID)
#if ! defined(ID)
#elif
#if, and #elif are a little weak in this implementation
---------------------------------------------------------------------------------- */
/* #ifdef directive */
cond_compile : IFDEF ID {
/* Push old if-then-else status */
if_push();
/* Look a symbol up in the symbol table */
if (lookup_symbol($2)) {
in_then = 1;
in_else = 0;
allow = 1 & prev_allow;
} else {
/* Condition is false. Skip over whatever is in this block */
in_else = skip_cond(1);
if (in_else == -1) {
/* Unrecoverable error */
SWIG_exit(1);
}
if (!in_else) {
if_pop(); // Pop out. Reached end of block
} else {
allow = prev_allow;
in_then = 0;
}
}
}
/* #ifndef directive */
| IFNDEF ID {
if_push();
if (lookup_symbol($2)) {
/* Condition is false. Skip over whatever is in this block */
in_else = skip_cond(1);
if (in_else == -1) {
/* Unrecoverable error */
SWIG_exit(1);
}
if (!in_else) {
if_pop(); // Pop out. Reached end of block
} else {
allow = prev_allow;
in_then = 0;
}
} else {
in_then = 1;
in_else = 0;
allow = 1 & prev_allow;
}
}
/* #else directive */
| ELSE {
if ((!in_then) || (in_else)) {
fprintf(stderr,"%s : Line %d. Misplaced else\n", input_file, line_number);
FatalError();
} else {
in_then = 0;
in_else = 1;
if (allow) {
allow = 0;
/* Skip over rest of the conditional */
skip_cond(0);
if_pop();
} else {
allow = 1;
}
allow = allow & prev_allow;
}
}
/* #endif directive */
| ENDIF {
if ((!in_then) && (!in_else)) {
fprintf(stderr,"%s : Line %d. Misplaced endif\n", input_file, line_number);
FatalError();
} else {
if_pop();
}
}
/* #if */
| IF cpp_const_expr {
/* Push old if-then-else status */
if_push();
if ($2) {
in_then = 1;
in_else = 0;
allow = 1 & prev_allow;
} else {
/* Condition is false. Skip over whatever is in this block */
in_else = skip_cond(1);
if (in_else == -1) {
/* Unrecoverable error */
SWIG_exit(1);
}
if (!in_else) {
if_pop(); // Pop out. Reached end of block
} else {
allow = prev_allow;
in_then = 0;
}
}
}
/* #elif. We treat this identical to an #if. Abit of a hack, but what
the hell. */
| ELIF cpp_const_expr {
/* have to pop old if clause off */
if_pop();
/* Push old if-then-else status */
if_push();
if ($2) {
in_then = 1;
in_else = 0;
allow = 1 & prev_allow;
} else {
/* Condition is false. Skip over whatever is in this block */
in_else = skip_cond(1);
if (in_else == -1) {
/* Unrecoverable error */
SWIG_exit(1);
}
if (!in_else) {
if_pop(); // Pop out. Reached end of block
} else {
allow = prev_allow;
in_then = 0;
}
}
}
;
/* C preprocessor expression (only used for conditional compilation */
cpp_const_expr : DEFINED LPAREN ID RPAREN {
/* Look ID up in the symbol table */
if (lookup_symbol($3)) {
$$ = 1;
} else {
$$ = 0;
}
}
| DEFINED ID {
if (lookup_symbol($2)) {
$$ = 1;
} else {
$$ = 0;
}
}
| LNOT cpp_const_expr {
if ($2) $$ = 0;
else $$ = 1;
}
;
pragma : PRAGMA LPAREN ID COMMA ID stylearg RPAREN {
if (allow && (!WrapExtern))
lang->pragma($3,$5,$6);
fprintf(stderr,"%s : Line %d. Warning. '%%pragma(lang,opt=value)' syntax is obsolete.\n",
input_file,line_number);
fprintf(stderr," Use '%%pragma(lang) opt=value' instead.\n");
}
| PRAGMA ID stylearg {
if (allow && (!WrapExtern))
swig_pragma($2,$3);
}
| PRAGMA LPAREN ID RPAREN ID stylearg {
if (allow && (!WrapExtern))
lang->pragma($3,$5,$6);
}
;
/* Allow lists of variables and functions to be built up */
stail : SEMI { }
| COMMA declaration array2 def_args {
if (allow) {
init_language();
temp_typeptr = new DataType(Active_type);
temp_typeptr->is_pointer += $2.is_pointer;
if ($3 > 0) {
temp_typeptr->is_pointer++;
temp_typeptr->status = STAT_READONLY;
temp_typeptr->arraystr = copy_string(ArrayString);
}
if ($2.is_reference) {
fprintf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number);
FatalError();
} else {
if (temp_typeptr->qualifier) {
if ((strcmp(temp_typeptr->qualifier,"const") == 0)) {
/* Okay. This is really some sort of C++ constant here. */
if ($4.type != T_ERROR)
create_constant($2.id, temp_typeptr, $4.id);
} else
create_variable(Active_extern,$2.id, temp_typeptr);
} else
create_variable(Active_extern, $2.id, temp_typeptr);
}
delete temp_typeptr;
}
} stail { }
| COMMA declaration LPAREN parms RPAREN cpp_const {
if (allow) {
init_language();
temp_typeptr = new DataType(Active_type);
temp_typeptr->is_pointer += $2.is_pointer;
temp_typeptr->is_reference = $2.is_reference;
create_function(Active_extern, $2.id, temp_typeptr, $4);
delete temp_typeptr;
}
delete $4;
} stail { }
;
definetail : definetype ENDDEF {
$$ = $1;
}
| ENDDEF {
$$.type = T_SYMBOL;
}
| error ENDDEF {
if (Verbose)
fprintf(stderr,"%s : Line %d. Warning. Unable to parse #define (ignored)\n", input_file, line_number);
$$.type = T_ERROR;
}
;
extern : EXTERN { $$ = 1; }
| empty {$$ = 0; }
| EXTERN STRING {
if (strcmp($2,"C") == 0) {
$$ = 2;
} else {
fprintf(stderr,"%s : Line %d. Unrecognized extern type \"%s\" (ignored).\n", input_file, line_number, $2);
FatalError();
}
}
;
/* End of a function declaration. Allows C++ "const" directive and inline code */
func_end : cpp_const LBRACE { skip_brace(); }
/* | LBRACE { skip_brace(); } */
;
/* ------------------------------------------------------------------------------
Function parameter lists
------------------------------------------------------------------------------ */
parms : parm ptail {
if (($1->t->type != T_VOID) || ($1->t->is_pointer))
$2->insert($1,0);
$$ = $2;
delete $1;
}
| empty { $$ = new ParmList;}
;
ptail : COMMA parm ptail {
$3->insert($2,0);
$$ = $3;
delete $2;
}
| empty { $$ = new ParmList;}
;
parm : parm_type {
$$ = $1;
if (typemap_check("ignore",typemap_lang,$$->t,$$->name))
$$->ignore = 1;
}
| parm_specifier_list parm_type {
$$ = $2;
$$->call_type = $$->call_type | $1;
if (InArray && ($$->call_type & CALL_VALUE)) {
fprintf(stderr,"%s : Line %d. Error. Can't use %%val with an array.\n", input_file, line_number);
FatalError();
}
if (!$$->t->is_pointer) {
fprintf(stderr,"%s : Line %d. Error. Can't use %%val or %%out with a non-pointer argument.\n", input_file, line_number);
FatalError();
} else {
$$->t->is_pointer--;
}
}
parm_type : type pname {
if (InArray) {
$1->is_pointer++;
if (Verbose) {
fprintf(stderr,"%s : Line %d. Warning. Array %s", input_file, line_number, $1->print_type());
print_array();
fprintf(stderr," has been converted to %s.\n", $1->print_type());
}
// Add array string to the type
$1->arraystr = copy_string(ArrayString.get());
}
$$ = new Parm($1,$2);
$$->call_type = 0;
$$->defvalue = DefArg;
if (($1->type == T_USER) && !($1->is_pointer)) {
if (Verbose)
fprintf(stderr,"%s : Line %d. Warning : Parameter of type '%s'\nhas been remapped to '%s *' and will be called using *((%s *) ptr).\n",
input_file, line_number, $1->name, $1->name, $1->name);
$$->call_type = CALL_REFERENCE;
$$->t->is_pointer++;
}
delete $1;
delete $2;
}
| type stars pname {
$$ = new Parm($1,$3);
$$->t->is_pointer += $2;
$$->call_type = 0;
$$->defvalue = DefArg;
if (InArray) {
$$->t->is_pointer++;
if (Verbose) {
fprintf(stderr,"%s : Line %d. Warning. Array %s", input_file, line_number, $$->t->print_type());
print_array();
fprintf(stderr," has been converted to %s.\n", $$->t->print_type());
}
// Add array string to the type
$$->t->arraystr = copy_string(ArrayString.get());
}
delete $1;
delete $3;
}
| type AND pname {
$$ = new Parm($1,$3);
$$->t->is_reference = 1;
$$->call_type = 0;
$$->t->is_pointer++;
$$->defvalue = DefArg;
if (!CPlusPlus) {
fprintf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number);
}
delete $1;
delete $3;
}
| type LPAREN stars pname RPAREN LPAREN parms RPAREN {
fprintf(stderr,"%s : Line %d. Error. Function pointer not allowed (remap with typedef).\n", input_file, line_number);
FatalError();
$$ = new Parm($1,$4);
$$->t->type = T_ERROR;
$$->name = copy_string($4);
strcpy($$->t->name,"<function ptr>");
delete $1;
delete $4;
delete $7;
}
| PERIOD PERIOD PERIOD {
fprintf(stderr,"%s : Line %d. Variable length arguments not supported (ignored).\n", input_file, line_number);
$$ = new Parm(new DataType(T_INT),"varargs");
$$->t->type = T_ERROR;
$$->name = copy_string("varargs");
strcpy($$->t->name,"<varargs>");
FatalError();
}
;
pname : ID def_args {
$$ = $1;
InArray = 0;
if ($2.type == T_CHAR)
DefArg = copy_string(ConstChar);
else
DefArg = copy_string($2.id);
if ($2.id) delete $2.id;
}
| ID array {
$$ = $1;
InArray = $2;
DefArg = 0;
}
| array {
$$ = new char[1];
$$[0] = 0;
InArray = $1;
DefArg = 0;
}
| empty { $$ = new char[1];
$$[0] = 0;
InArray = 0;
DefArg = 0;
}
;
def_args : EQUAL definetype { $$ = $2; }
| EQUAL AND ID {
$$.id = new char[strlen($3)+2];
$$.id[0] = '&';
strcpy(&$$.id[1], $3);
$$.type = T_USER;
}
| EQUAL LBRACE {
skip_brace();
$$.id = 0; $$.type = T_INT;
}
| COLON NUM_INT {
}
| empty {$$.id = 0; $$.type = T_INT;}
;
parm_specifier : CVALUE { $$ = CALL_VALUE; }
| COUT { $$ = CALL_OUTPUT; }
;
parm_specifier_list : parm_specifier_list parm_specifier {
$$ = $1 | $2;
}
| parm_specifier {
$$ = $1;
}
;
/* Declaration must be an identifier, possibly preceded by a * for pointer types */
declaration : ID { $$.id = $1;
$$.is_pointer = 0;
$$.is_reference = 0;
}
| stars ID {
$$.id = $2;
$$.is_pointer = $1;
$$.is_reference = 0;
}
| AND ID {
$$.id = $2;
$$.is_pointer = 1;
$$.is_reference = 1;
if (!CPlusPlus) {
fprintf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number);
}
}
;
stars : STAR empty { $$ = 1; }
| STAR stars { $$ = $2 + 1;}
;
array : LBRACKET RBRACKET array2 {
$$ = $3 + 1;
"[]" >> ArrayString;
}
| LBRACKET expr RBRACKET array2 {
$$ = $4 + 1;
"]" >> ArrayString;
$2.id >> ArrayString;
"[" >> ArrayString;
}
;
array2 : array {
$$ = $1;
}
| empty { $$ = 0;
ArrayString = "";
}
;
/* Data type must be a built in type or an identifier for user-defined types
This type can be preceded by a modifier. */
type : TYPE_INT {
$$ = $1;
}
| TYPE_SHORT opt_int {
$$ = $1;
}
| TYPE_LONG opt_int {
$$ = $1;
}
| TYPE_CHAR {
$$ = $1;
}
| TYPE_BOOL {
$$ = $1;
}
| TYPE_FLOAT {
$$ = $1;
}
| TYPE_DOUBLE {
$$ = $1;
}
| TYPE_VOID {
$$ = $1;
}
| TYPE_SIGNED opt_signed {
if ($2) $$ = $2;
else $$ = $1;
}
| TYPE_UNSIGNED opt_unsigned {
if ($2) $$ = $2;
else $$ = $1;
}
| TYPE_TYPEDEF objc_protolist {
$$ = $1;
if (strlen($2) > 0) {
if ((strlen($2) + strlen($$->name)) >= MAX_NAME) {
fprintf(stderr,"%s : Line %d. Fatal error. Type-name is too long!\n",
input_file, line_number);
} else {
strcat($$->name,$2);
}
}
}
| ID objc_protolist {
$$ = new DataType;
strcpy($$->name,$1);
$$->type = T_USER;
/* Do a typedef lookup */
$$->typedef_resolve();
if (strlen($2) > 0) {
if ((strlen($2) + strlen($$->name)) >= MAX_NAME) {
fprintf(stderr,"%s : Line %d. Fatal error. Type-name is too long!\n",
input_file, line_number);
} else {
strcat($$->name,$2);
}
}
}
| CONST type {
$$ = $2;
$$->qualifier = new char[6];
strcpy($$->qualifier,"const");
}
| cpptype ID {
$$ = new DataType;
sprintf($$->name,"%s %s",$1, $2);
$$->type = T_USER;
}
| ID DCOLON ID {
$$ = new DataType;
sprintf($$->name,"%s::%s",$1,$3);
$$->type = T_USER;
$$->typedef_resolve();
}
/* This declaration causes a shift-reduce conflict. Unresolved for now */
| DCOLON ID {
$$ = new DataType;
sprintf($$->name,"%s", $2);
$$->type = T_USER;
$$->typedef_resolve(1);
}
| ENUM ID {
$$ = new DataType;
sprintf($$->name,"enum %s", $2);
$$->type = T_INT;
$$->typedef_resolve(1);
}
;
/* type specification without ID symbol. Used in some cases to prevent shift-reduce conflicts */
strict_type : TYPE_INT {
$$ = $1;
}
| TYPE_SHORT opt_int {
$$ = $1;
}
| TYPE_LONG opt_int {
$$ = $1;
}
| TYPE_CHAR {
$$ = $1;
}
| TYPE_BOOL {
$$ = $1;
}
| TYPE_FLOAT {
$$ = $1;
}
| TYPE_DOUBLE {
$$ = $1;
}
| TYPE_VOID {
$$ = $1;
}
| TYPE_SIGNED opt_signed {
if ($2) $$ = $2;
else $$ = $1;
}
| TYPE_UNSIGNED opt_unsigned {
if ($2) $$ = $2;
else $$ = $1;
}
| TYPE_TYPEDEF objc_protolist {
$$ = $1;
strcat($$->name,$2);
}
| CONST type {
$$ = $2;
$$->qualifier = new char[6];
strcpy($$->qualifier,"const");
}
| cpptype ID {
$$ = new DataType;
sprintf($$->name,"%s %s",$1, $2);
$$->type = T_USER;
}
;
/* Optional signed types */
opt_signed : empty {
$$ = (DataType *) 0;
}
| TYPE_INT {
$$ = $1;
$$->type = T_INT;
sprintf(temp_name,"signed %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_SHORT opt_int {
$$ = $1;
$$->type = T_SHORT;
sprintf(temp_name,"signed %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_LONG opt_int {
$$ = $1;
$$->type = T_LONG;
sprintf(temp_name,"signed %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_CHAR {
$$ = $1;
$$->type = T_SCHAR;
sprintf(temp_name,"signed %s",$1->name);
strcpy($$->name,temp_name);
}
;
/* Optional unsigned types */
opt_unsigned : empty {
$$ = (DataType *) 0;
}
| TYPE_INT {
$$ = $1;
$$->type = T_UINT;
sprintf(temp_name,"unsigned %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_SHORT opt_int {
$$ = $1;
$$->type = T_USHORT;
sprintf(temp_name,"unsigned %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_LONG opt_int {
$$ = $1;
$$->type = T_ULONG;
sprintf(temp_name,"unsigned %s",$1->name);
strcpy($$->name,temp_name);
}
| TYPE_CHAR {
$$ = $1;
$$->type = T_UCHAR;
sprintf(temp_name,"unsigned %s",$1->name);
strcpy($$->name,temp_name);
}
;
opt_int : TYPE_INT { }
| empty { }
;
definetype : { scanner_check_typedef(); } expr {
$$ = $2;
scanner_ignore_typedef();
if (ConstChar) delete ConstChar;
ConstChar = 0;
}
| STRING {
$$.id = $1;
$$.type = T_CHAR;
if (ConstChar) delete ConstChar;
ConstChar = new char[strlen($1)+3];
sprintf(ConstChar,"\"%s\"",$1);
}
| CHARCONST {
$$.id = $1;
$$.type = T_CHAR;
if (ConstChar) delete ConstChar;
ConstChar = new char[strlen($1)+3];
sprintf(ConstChar,"'%s'",$1);
}
;
/* Initialization function links */
initlist : initlist COMMA ID {
$$ = $1;
$$.names[$$.count] = copy_string($3);
$$.count++;
$$.names[$$.count] = (char *) 0;
}
| empty {
$$.names = new char *[NI_NAMES];
$$.count = 0;
for (i = 0; i < NI_NAMES; i++)
$$.names[i] = (char *) 0;
}
;
/* Some stuff for handling enums */
ename : ID { $$ = $1; }
| empty { $$ = (char *) 0;}
;
/* SWIG enum list.
*/
enumlist : enumlist COMMA edecl {}
| edecl {}
;
edecl : ID {
temp_typeptr = new DataType(T_INT);
create_constant($1, temp_typeptr, $1);
delete temp_typeptr;
}
| ID EQUAL { scanner_check_typedef();} etype {
temp_typeptr = new DataType($4.type);
// Use enum name instead of value
// OLD create_constant($1, temp_typeptr, $4.id);
create_constant($1, temp_typeptr, $1);
delete temp_typeptr;
}
| cond_compile edecl { }
| empty { }
;
etype : expr {
$$ = $1;
if (($$.type != T_INT) && ($$.type != T_UINT) &&
($$.type != T_LONG) && ($$.type != T_ULONG) &&
($$.type != T_SHORT) && ($$.type != T_USHORT) &&
($$.type != T_SCHAR) && ($$.type != T_UCHAR)) {
fprintf(stderr,"%s : Lind %d. Type error. Expecting an int\n",
input_file, line_number);
FatalError();
}
}
| CHARCONST {
$$.id = $1;
$$.type = T_CHAR;
}
;
/* Arithmetic expressions. Used for constants and other cool stuff.
Really, we're not doing anything except string concatenation, but
this does allow us to parse many constant declarations.
*/
expr : NUM_INT {
$$.id = $1;
$$.type = T_INT;
}
| NUM_FLOAT {
$$.id = $1;
$$.type = T_DOUBLE;
}
| NUM_UNSIGNED {
$$.id = $1;
$$.type = T_UINT;
}
| NUM_LONG {
$$.id = $1;
$$.type = T_LONG;
}
| NUM_ULONG {
$$.id = $1;
$$.type = T_ULONG;
}
| SIZEOF LPAREN type RPAREN {
$$.id = new char[strlen($3->name)+9];
sprintf($$.id,"sizeof(%s)", $3->name);
$$.type = T_INT;
}
| LPAREN strict_type RPAREN expr %prec UMINUS {
$$.id = new char[strlen($4.id)+strlen($2->name)+3];
sprintf($$.id,"(%s)%s",$2->name,$4.id);
$$.type = $2->type;
}
| ID {
$$.id = lookup_symvalue($1);
if ($$.id == (char *) 0)
$$.id = $1;
else {
$$.id = new char[strlen($$.id)+3];
sprintf($$.id,"(%s)",lookup_symvalue($1));
}
temp_typeptr = lookup_symtype($1);
if (temp_typeptr) $$.type = temp_typeptr->type;
else $$.type = T_INT;
}
| ID DCOLON ID {
$$.id = new char[strlen($1)+strlen($3)+3];
sprintf($$.id,"%s::%s",$1,$3);
$$.type = T_INT;
delete $1;
delete $3;
}
| expr PLUS expr {
E_BINARY($$.id,$1.id,$3.id,"+");
$$.type = promote($1.type,$3.type);
delete $1.id;
delete $3.id;
}
| expr MINUS expr {
E_BINARY($$.id,$1.id,$3.id,"-");
$$.type = promote($1.type,$3.type);
delete $1.id;
delete $3.id;
}
| expr STAR expr {
E_BINARY($$.id,$1.id,$3.id,"*");
$$.type = promote($1.type,$3.type);
delete $1.id;
delete $3.id;
}
| expr SLASH expr {
E_BINARY($$.id,$1.id,$3.id,"/");
$$.type = promote($1.type,$3.type);
delete $1.id;
delete $3.id;
}
| expr AND expr {
E_BINARY($$.id,$1.id,$3.id,"&");
$$.type = promote($1.type,$3.type);
if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
delete $1.id;
delete $3.id;
}
| expr OR expr {
E_BINARY($$.id,$1.id,$3.id,"|");
$$.type = promote($1.type,$3.type);
if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
$$.type = T_INT;
delete $1.id;
delete $3.id;
}
| expr XOR expr {
E_BINARY($$.id,$1.id,$3.id,"^");
$$.type = promote($1.type,$3.type);
if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
$$.type = T_INT;
delete $1.id;
delete $3.id;
}
| expr LSHIFT expr {
E_BINARY($$.id,$1.id,$3.id,"<<");
$$.type = promote($1.type,$3.type);
if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
$$.type = T_INT;
delete $1.id;
delete $3.id;
}
| expr RSHIFT expr {
E_BINARY($$.id,$1.id,$3.id,">>");
$$.type = promote($1.type,$3.type);
if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
$$.type = T_INT;
delete $1.id;
delete $3.id;
}
| MINUS expr %prec UMINUS {
$$.id = new char[strlen($2.id)+2];
sprintf($$.id,"-%s",$2.id);
$$.type = $2.type;
delete $2.id;
}
| NOT expr {
$$.id = new char[strlen($2.id)+2];
sprintf($$.id,"~%s",$2.id);
if ($2.type == T_DOUBLE) {
fprintf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number);
FatalError();
}
$$.type = $2.type;
delete $2.id;
}
| LPAREN expr RPAREN {
$$.id = new char[strlen($2.id)+3];
sprintf($$.id,"(%s)", $2.id);
$$.type = $2.type;
delete $2.id;
}
;
/****************************************************************/
/* C++ Support */
/****************************************************************/
cpp : cpp_class { }
| cpp_other {}
;
cpp_class :
/* A class/struct/union definition */
extern cpptype ID inherit LBRACE {
char *iname;
if (allow) {
init_language();
DataType::new_scope();
sprintf(temp_name,"CPP_CLASS:%s\n",$3);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3);
FatalError();
}
if ((!CPlusPlus) && (strcmp($2,"class") == 0))
fprintf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number);
iname = make_name($3);
doc_entry = new DocClass(iname, doc_parent());
if (iname == $3)
cplus_open_class($3, 0, $2);
else
cplus_open_class($3, iname, $2);
if (strcmp($2,"class") == 0)
cplus_mode = CPLUS_PRIVATE;
else
cplus_mode = CPLUS_PUBLIC;
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
nested_list = 0;
// Merge in scope from base classes
cplus_inherit_scope($4.count,$4.names);
}
} cpp_members RBRACE {
if (allow) {
if ($4.names) {
if (strcmp($2,"union") != 0)
cplus_inherit($4.count, $4.names);
else {
fprintf(stderr,"%s : Line %d. Inheritance not allowed for unions.\n",input_file, line_number);
FatalError();
}
}
// Clean up the inheritance list
if ($4.names) {
int j;
for (j = 0; j < $4.count; j++) {
if ($4.names[j]) delete [] $4.names[j];
}
delete [] $4.names;
}
// Dumped nested declarations (if applicable)
dump_nested($3);
// Save and collapse current scope
cplus_register_scope(DataType::collapse_scope($3));
// Restore the original doc entry for this class
doc_entry = doc_stack[doc_stack_top];
cplus_class_close((char *) 0);
doc_entry = 0;
// Bump the documentation stack back down
doc_stack_top--;
cplus_mode = CPLUS_PUBLIC;
}
}
/* Class with a typedef */
| TYPEDEF cpptype ID inherit LBRACE {
if (allow) {
char *iname;
init_language();
DataType::new_scope();
sprintf(temp_name,"CPP_CLASS:%s\n",$3);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3);
FatalError();
}
if ((!CPlusPlus) && (strcmp($2,"class") == 0))
fprintf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number);
iname = make_name($3);
doc_entry = new DocClass(iname, doc_parent());
if ($3 == iname)
cplus_open_class($3, 0, $2);
else
cplus_open_class($3, iname, $2);
if (strcmp($2,"class") == 0)
cplus_mode = CPLUS_PRIVATE;
else
cplus_mode = CPLUS_PUBLIC;
// Create a documentation entry for the class
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
nested_list = 0;
// Merge in scope from base classes
cplus_inherit_scope($4.count,$4.names);
}
} cpp_members RBRACE declaration {
if (allow) {
if ($4.names) {
if (strcmp($2,"union") != 0)
cplus_inherit($4.count, $4.names);
else {
fprintf(stderr,"%s : Line %d. Inheritance not allowed for unions.\n",input_file, line_number);
FatalError();
}
}
// Create a datatype for correctly processing the typedef
Active_typedef = new DataType();
Active_typedef->type = T_USER;
sprintf(Active_typedef->name,"%s %s", $2,$3);
Active_typedef->is_pointer = 0;
Active_typedef->implicit_ptr = 0;
// Clean up the inheritance list
if ($4.names) {
int j;
for (j = 0; j < $4.count; j++) {
if ($4.names[j]) delete [] $4.names[j];
}
delete [] $4.names;
}
if ($9.is_pointer > 0) {
fprintf(stderr,"%s : Line %d. typedef struct { } *id not supported properly. Winging it...\n", input_file, line_number);
}
// Create dump nested class code
if ($9.is_pointer > 0) {
dump_nested($3);
} else {
dump_nested($9.id);
}
// Collapse any datatypes created in the the class
cplus_register_scope(DataType::collapse_scope($3));
doc_entry = doc_stack[doc_stack_top];
if ($9.is_pointer > 0) {
cplus_class_close($3);
} else {
cplus_class_close($9.id);
}
doc_stack_top--;
doc_entry = 0;
// Create a typedef in global scope
if ($9.is_pointer == 0)
Active_typedef->typedef_add($9.id);
else {
DataType *t = new DataType(Active_typedef);
t->is_pointer += $9.is_pointer;
t->typedef_add($9.id);
cplus_register_type($9.id);
delete t;
}
cplus_mode = CPLUS_PUBLIC;
}
} typedeflist { };
/* An unnamed struct with a typedef */
| TYPEDEF cpptype LBRACE {
char *iname;
if (allow) {
init_language();
DataType::new_scope();
if ((!CPlusPlus) && (strcmp($2,"class") == 0))
fprintf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number);
iname = make_name("");
doc_entry = new DocClass(iname,doc_parent());
if (strlen(iname))
cplus_open_class("", iname, $2);
else
cplus_open_class("",0,$2);
if (strcmp($2,"class") == 0)
cplus_mode = CPLUS_PRIVATE;
else
cplus_mode = CPLUS_PUBLIC;
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
nested_list = 0;
}
} cpp_members RBRACE declaration {
if (allow) {
if ($7.is_pointer > 0) {
fprintf(stderr,"%s : Line %d. typedef %s {} *%s not supported correctly. Will be ignored.\n", input_file, line_number, $2, $7.id);
cplus_abort();
} else {
sprintf(temp_name,"CPP_CLASS:%s\n",$7.id);
if (add_symbol(temp_name, (DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $7.id);
FatalError();
}
}
// Create a datatype for correctly processing the typedef
Active_typedef = new DataType();
Active_typedef->type = T_USER;
sprintf(Active_typedef->name,"%s",$7.id);
Active_typedef->is_pointer = 0;
Active_typedef->implicit_ptr = 0;
// Dump nested classes
if ($7.is_pointer == 0)
dump_nested($7.id);
// Go back to previous scope
cplus_register_scope(DataType::collapse_scope((char *) 0));
doc_entry = doc_stack[doc_stack_top];
// Change name of doc_entry
doc_entry->name = copy_string($7.id);
if ($7.is_pointer == 0)
cplus_class_close($7.id);
doc_entry = 0;
doc_stack_top--;
cplus_mode = CPLUS_PUBLIC;
}
} typedeflist { }
;
cpp_other :/* A dummy class name */
extern cpptype ID SEMI {
char *iname;
if (allow) {
init_language();
iname = make_name($3);
lang->cpp_class_decl($3,iname,$2);
}
}
/* A static C++ member function (declared out of scope) */
| extern type declaration DCOLON ID LPAREN parms RPAREN SEMI {
if (allow) {
init_language();
if (!CPlusPlus)
fprintf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number);
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
// Fix up the function name
sprintf(temp_name,"%s::%s",$3.id,$5);
if (!Rename_true) {
Rename_true = 1;
sprintf(yy_rename,"%s_%s",$3.id,$5);
}
create_function($1, temp_name, $2, $7);
}
delete $2;
delete $7;
}
/* A static C++ member data */
| extern type declaration DCOLON ID SEMI {
if (allow) {
init_language();
if (!CPlusPlus)
fprintf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number);
$2->is_pointer += $3.is_pointer;
// Fix up the function name
sprintf(temp_name,"%s::%s",$3.id,$5);
if (!Rename_true) {
Rename_true = 1;
sprintf(yy_rename,"%s_%s",$3.id,$5);
}
create_variable($1,temp_name, $2);
}
delete $2;
}
/* Operator overloading catch */
| extern type declaration DCOLON OPERATOR {
fprintf(stderr,"%s : Line %d. Operator overloading not supported (ignored).\n", input_file, line_number);
skip_decl();
delete $2;
}
/* Template catch */
| TEMPLATE {
fprintf(stderr,"%s : Line %d. Templates not currently supported (ignored).\n",
input_file, line_number);
skip_decl();
}
/* %addmethods directive used outside of a class definition */
| ADDMETHODS ID LBRACE {
cplus_mode = CPLUS_PUBLIC;
doc_entry = cplus_set_class($2);
if (!doc_entry) {
doc_entry = new DocClass($2,doc_parent());
};
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
AddMethods = 1;
} added_members RBRACE {
cplus_unset_class();
doc_entry = 0;
doc_stack_top--;
AddMethods = 0;
}
;
added_members : cpp_member cpp_members { }
| objc_method objc_methods { }
| empty { }
;
cpp_members : cpp_member cpp_members {}
| ADDMETHODS LBRACE {
AddMethods = 1;
} cpp_members RBRACE {
AddMethods = 0;
} cpp_members { }
| error {
skip_decl();
{
static int last_error_line = -1;
if (last_error_line != line_number) {
fprintf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number);
FatalError();
last_error_line = line_number;
}
}
} cpp_members { }
| empty { }
;
cpp_member : type declaration LPAREN parms RPAREN cpp_end {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
Stat_func++;
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
if (Verbose) {
fprintf(stderr,"Wrapping member function : %s\n",$2.id);
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_member_func($2.id, iname, $1,$4,0);
}
scanner_clear_start();
}
delete $1;
delete $4;
}
/* Virtual member function */
| VIRTUAL type declaration LPAREN parms RPAREN cpp_vend {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
Stat_func++;
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
if (Verbose) {
fprintf(stderr,"Wrapping virtual member function : %s\n",$3.id);
}
iname = make_name($3.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3.id) iname = 0;
cplus_member_func($3.id,iname,$2,$5,1);
}
scanner_clear_start();
}
delete $2;
delete $5;
}
/* Possibly a constructor */
| ID LPAREN parms RPAREN ctor_end {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
Stat_func++;
if (Verbose) {
fprintf(stderr,"Wrapping C++ constructor %s\n", $1);
}
iname = make_name($1);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $1) iname = 0;
cplus_constructor($1,iname, $3);
}
scanner_clear_start();
}
delete $3;
}
/* A destructor (hopefully) */
| NOT ID LPAREN parms RPAREN cpp_end {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
Stat_func++;
if (Verbose) {
fprintf(stderr,"Wrapping C++ destructor %s\n", $2);
}
iname = make_name($2);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2) iname = 0;
cplus_destructor($2,iname);
}
}
scanner_clear_start();
}
/* A virtual destructor */
| VIRTUAL NOT ID LPAREN RPAREN cpp_end {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
Stat_func++;
if (Verbose) {
fprintf(stderr,"Wrapping C++ destructor %s\n", $3);
}
iname = make_name($3);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3) iname = 0;
cplus_destructor($3,iname);
}
}
scanner_clear_start();
}
/* Member data */
| type declaration def_args {
if (allow) {
char *iname;
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
if (Active_type) delete Active_type;
Active_type = new DataType($1);
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
if ($1->qualifier) {
if ((strcmp($1->qualifier,"const") == 0) && ($1->is_pointer == 0)) {
// Okay. This is really some sort of C++ constant here.
if ($3.type != T_ERROR) {
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_declare_const($2.id,iname, $1, $3.id);
}
} else {
int oldstatus = Status;
char *tm;
if ($1->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,$1,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,$1);
Status = oldstatus;
}
} else {
char *tm = 0;
int oldstatus = Status;
if ($1->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,$1,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,$1);
Status = oldstatus;
if (Verbose) {
fprintf(stderr,"Wrapping member data %s\n", $2.id);
}
}
}
scanner_clear_start();
}
delete $1;
} cpp_tail { }
| type declaration array def_args {
char *iname;
if (allow) {
int oldstatus = Status;
char *tm = 0;
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
if (Active_type) delete Active_type;
Active_type = new DataType($1);
$1->is_pointer += $2.is_pointer + 1;
$1->is_reference = $2.is_reference;
$1->arraystr = copy_string(ArrayString);
if (!(tm = typemap_lookup("memberin",typemap_lang,$1,$2.id,"","")))
Status = STAT_READONLY;
iname = make_name($2.id);
doc_entry = new DocDecl(iname, doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,$1);
Status = oldstatus;
if (!tm)
fprintf(stderr,"%s : Line %d. Warning. Array member will be read-only.\n",input_file,line_number);
}
scanner_clear_start();
}
delete $1;
}
/* Static Member data */
| STATIC type declaration {
char *iname;
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
$2->is_pointer += $3.is_pointer;
iname = make_name($3.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3.id) iname = 0;
cplus_static_var($3.id,iname,$2);
if (Active_type) delete Active_type;
Active_type = new DataType($2);
if (Verbose) {
fprintf(stderr,"Wrapping static member data %s\n", $3.id);
}
}
scanner_clear_start();
}
delete $2;
} cpp_tail { }
/* Static member function */
| STATIC type declaration LPAREN parms RPAREN cpp_end {
char *iname;
if (allow) {
$2->is_pointer += $3.is_pointer;
$2->is_reference = $3.is_reference;
if (cplus_mode == CPLUS_PUBLIC) {
iname = make_name($3.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3.id) iname = 0;
cplus_static_func($3.id, iname, $2, $5);
if (Verbose)
fprintf(stderr,"Wrapping static member function %s\n",$3.id);
}
scanner_clear_start();
}
delete $2;
delete $5;
}
/* Turn on public: mode */
| PUBLIC COLON {
if (allow) {
cplus_mode = CPLUS_PUBLIC;
if (Verbose)
fprintf(stderr,"Public mode\n");
scanner_clear_start();
}
}
/* Turn on private: mode */
| PRIVATE COLON {
if (allow) {
cplus_mode = CPLUS_PRIVATE;
if (Verbose)
fprintf(stderr,"Private mode\n");
scanner_clear_start();
}
}
/* Turn on protected mode */
| PROTECTED COLON {
if (allow) {
cplus_mode = CPLUS_PROTECTED;
if (Verbose)
fprintf(stderr,"Protected mode\n");
scanner_clear_start();
}
}
/* This is the new style rename */
| NAME LPAREN ID RPAREN {
if (allow) {
strcpy(yy_rename,$3);
Rename_true = 1;
}
}
/* New mode */
| NEW {
NewObject = 1;
} cpp_member {
NewObject = 0;
}
/* C++ Enum */
| ENUM ename LBRACE {scanner_clear_start();} cpp_enumlist RBRACE SEMI {
// if ename was supplied. Install it as a new integer datatype.
if (allow) {
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
if ($2) {
cplus_register_type($2);
temp_type.type = T_INT;
temp_type.is_pointer = 0;
temp_type.implicit_ptr = 0;
sprintf(temp_type.name,"int");
temp_type.typedef_add($2,1);
}
}
}
}
| READONLY {
if (allow)
Status = Status | STAT_READONLY;
scanner_clear_start();
}
| READWRITE {
if (allow)
Status = Status & ~(STAT_READONLY);
scanner_clear_start();
}
/* A friend : Illegal */
| FRIEND {
if (allow)
fprintf(stderr,"%s : Line %d. Friends are not allowed--members only! (ignored)\n", input_file, line_number);
skip_decl();
scanner_clear_start();
}
/* An operator: Illegal */
| type type_extra OPERATOR {
if (allow)
fprintf(stderr,"%s : Line %d. Operator overloading not supported (ignored).\n", input_file, line_number);
skip_decl();
scanner_clear_start();
}
| cond_compile {
scanner_clear_start();
}
/* A typedef inside a class */
| typedef_decl { }
/* Pragma directive */
| cpp_pragma {
scanner_clear_start();
}
cpp_pragma : PRAGMA ID stylearg {
if (allow && (!WrapExtern)) { }
}
| PRAGMA LPAREN ID RPAREN ID stylearg {
if (allow && (!WrapExtern))
cplus_add_pragma($3,$5,$6);
}
;
/* ----------------------------------------------------------------------
Nested structure. This is a big ugly "hack". If we encounter
a nested structure, we're going to grab the text of its definition and
feed it back into the scanner. In the meantime, we need to grab
variable declaration information and generate the associated wrapper
code later. Yikes!
This really only works in a limited sense. Since we use the
code attached to the nested class to generate both C/C++ code,
it can't have any SWIG directives in it. It also needs to be parsable
by SWIG or this whole thing is going to puke.
---------------------------------------------------------------------- */
/* A struct sname { } id; declaration */
| cpptype ID LBRACE { start_line = line_number; skip_brace();
} nested_decl SEMI {
if (cplus_mode == CPLUS_PUBLIC) {
cplus_register_type($2);
if ($5.id) {
if (strcmp($1,"class") == 0) {
fprintf(stderr,"%s : Line %d. Warning. Nested classes not currently supported (ignored).\n", input_file, line_number);
/* Generate some code for a new class */
} else {
Nested *n = new Nested;
n->code << "typedef " << $1 << " "
<< CCode.get() << " $classname_" << $5.id << ";\n";
n->name = copy_string($5.id);
n->line = start_line;
n->type = new DataType;
n->type->type = T_USER;
n->type->is_pointer = $5.is_pointer;
n->type->is_reference = $5.is_reference;
n->next = 0;
add_nested(n);
}
}
}
}
/* An unnamed structure definition */
| cpptype LBRACE { start_line = line_number; skip_brace();
} declaration SEMI {
if (cplus_mode == CPLUS_PUBLIC) {
if (strcmp($1,"class") == 0) {
fprintf(stderr,"%s : Line %d. Warning. Nested classes not currently supported (ignored)\n", input_file, line_number);
/* Generate some code for a new class */
} else {
/* Generate some code for a new class */
Nested *n = new Nested;
n->code << "typedef " << $1 << " "
<< CCode.get() << " $classname_" << $4.id << ";\n";
n->name = copy_string($4.id);
n->line = start_line;
n->type = new DataType;
n->type->type = T_USER;
n->type->is_pointer = $4.is_pointer;
n->type->is_reference = $4.is_reference;
n->next = 0;
add_nested(n);
}
}
}
/* An empty class declaration */
| cpptype ID SEMI {
if (cplus_mode == CPLUS_PUBLIC) {
cplus_register_type($2);
}
}
/* Other miscellaneous errors */
| type stars LPAREN {
skip_decl();
fprintf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number);
}
| strict_type LPAREN STAR {
skip_decl();
fprintf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number);
}
| ID LPAREN STAR {
skip_decl();
fprintf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number);
}
| doc_enable { }
| SEMI { }
;
nested_decl : declaration { $$ = $1;}
| empty { $$.id = 0; }
;
type_extra : stars {}
| AND {}
| empty {}
;
cpp_tail : SEMI { }
| COMMA declaration def_args {
if (allow) {
int oldstatus = Status;
char *tm;
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
temp_typeptr = new DataType(Active_type);
temp_typeptr->is_pointer += $2.is_pointer;
if (Verbose) {
fprintf(stderr,"Wrapping member variable : %s\n",$2.id);
}
Stat_var++;
doc_entry = new DocDecl($2.id,doc_stack[doc_stack_top]);
if (temp_typeptr->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,temp_typeptr,$2.id,"","")))
Status = Status | STAT_READONLY;
}
cplus_variable($2.id,(char *) 0,temp_typeptr);
Status = oldstatus;
delete temp_typeptr;
}
scanner_clear_start();
}
} cpp_tail { }
| COMMA declaration array def_args {
if (allow) {
int oldstatus = Status;
char *tm;
init_language();
if (cplus_mode == CPLUS_PUBLIC) {
temp_typeptr = new DataType(Active_type);
temp_typeptr->is_pointer += $2.is_pointer;
if (Verbose) {
fprintf(stderr,"Wrapping member variable : %s\n",$2.id);
}
Stat_var++;
if (!(tm = typemap_lookup("memberin",typemap_lang,temp_typeptr,$2.id,"","")))
Status = Status | STAT_READONLY;
doc_entry = new DocDecl($2.id,doc_stack[doc_stack_top]);
if (temp_typeptr->status & STAT_READONLY) Status = Status | STAT_READONLY;
cplus_variable($2.id,(char *) 0,temp_typeptr);
Status = oldstatus;
if (!tm)
fprintf(stderr,"%s : Line %d. Warning. Array member will be read-only.\n",input_file,line_number);
delete temp_typeptr;
}
scanner_clear_start();
}
} cpp_tail { }
;
cpp_end : cpp_const SEMI {
CCode = "";
}
| cpp_const LBRACE { skip_brace(); }
;
cpp_vend : cpp_const SEMI { CCode = ""; }
| cpp_const EQUAL definetype SEMI { CCode = ""; }
| cpp_const LBRACE { skip_brace(); }
;
cpp_enumlist : cpp_enumlist COMMA cpp_edecl {}
| cpp_edecl {}
;
cpp_edecl : ID {
if (allow) {
if (cplus_mode == CPLUS_PUBLIC) {
if (Verbose) {
fprintf(stderr,"Creating enum value %s\n", $1);
}
Stat_const++;
temp_typeptr = new DataType(T_INT);
doc_entry = new DocDecl($1,doc_stack[doc_stack_top]);
cplus_declare_const($1, (char *) 0, temp_typeptr, (char *) 0);
delete temp_typeptr;
scanner_clear_start();
}
}
}
| ID EQUAL etype {
if (allow) {
if (cplus_mode == CPLUS_PUBLIC) {
if (Verbose) {
fprintf(stderr, "Creating enum value %s = %s\n", $1, $3.id);
}
Stat_const++;
temp_typeptr = new DataType(T_INT);
doc_entry = new DocDecl($1,doc_stack[doc_stack_top]);
cplus_declare_const($1,(char *) 0, temp_typeptr,(char *) 0);
// OLD : Bug with value cplus_declare_const($1,(char *) 0, temp_typeptr,$3.id);
delete temp_typeptr;
scanner_clear_start();
}
}
}
| NAME LPAREN ID RPAREN ID {
if (allow) {
if (cplus_mode == CPLUS_PUBLIC) {
if (Verbose) {
fprintf(stderr,"Creating enum value %s\n", $5);
}
Stat_const++;
temp_typeptr = new DataType(T_INT);
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
cplus_declare_const($5, $3, temp_typeptr, (char *) 0);
delete temp_typeptr;
scanner_clear_start();
}
}
}
| NAME LPAREN ID RPAREN ID EQUAL etype {
if (allow) {
if (cplus_mode == CPLUS_PUBLIC) {
if (Verbose) {
fprintf(stderr, "Creating enum value %s = %s\n", $5, $7.id);
}
Stat_const++;
temp_typeptr = new DataType(T_INT);
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
cplus_declare_const($5,$3, temp_typeptr, (char *) 0);
// Old : bug with value cplus_declare_const($5,$3, temp_typeptr,$7.id);
delete temp_typeptr;
scanner_clear_start();
}
}
}
| cond_compile cpp_edecl { }
| empty { }
;
inherit : COLON base_list {
$$ = $2;
}
| empty {
$$.names = (char **) 0;
$$.count = 0;
}
;
base_list : base_specifier {
int i;
$$.names = new char *[NI_NAMES];
$$.count = 0;
for (i = 0; i < NI_NAMES; i++){
$$.names[i] = (char *) 0;
}
if ($1) {
$$.names[$$.count] = copy_string($1);
$$.count++;
}
}
| base_list COMMA base_specifier {
$$ = $1;
if ($3) {
$$.names[$$.count] = copy_string($3);
$$.count++;
}
}
;
base_specifier : ID {
fprintf(stderr,"%s : Line %d. No access specifier given for base class %s (ignored).\n",
input_file,line_number,$1);
$$ = (char *) 0;
}
| VIRTUAL ID {
fprintf(stderr,"%s : Line %d. No access specifier given for base class %s (ignored).\n",
input_file,line_number,$2);
$$ = (char *) 0;
}
| VIRTUAL access_specifier ID {
if (strcmp($2,"public") == 0) {
$$ = $3;
} else {
fprintf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n",
input_file,line_number,$2);
$$ = (char *) 0;
}
}
| access_specifier ID {
if (strcmp($1,"public") == 0) {
$$ = $2;
} else {
fprintf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n",
input_file,line_number,$1);
$$ = (char *) 0;
}
}
| access_specifier VIRTUAL ID {
if (strcmp($1,"public") == 0) {
$$ = $3;
} else {
fprintf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n",
input_file,line_number,$1);
$$ = (char *) 0;
}
}
;
access_specifier : PUBLIC { $$ = "public"; }
| PRIVATE { $$ = "private"; }
| PROTECTED { $$ = "protected"; }
;
cpptype : CLASS { $$ = "class"; }
| STRUCT { $$ = "struct"; }
| UNION {$$ = "union"; }
;
cpp_const : CONST {}
| THROW LPAREN parms RPAREN { delete $3;}
| empty {}
;
/* Constructor initializer */
ctor_end : cpp_const ctor_initializer SEMI {
CCode = "";
}
| cpp_const ctor_initializer LBRACE { skip_brace(); }
;
ctor_initializer : COLON mem_initializer_list {}
| empty {}
;
mem_initializer_list : mem_initializer { }
| mem_initializer_list COMMA mem_initializer { }
;
mem_initializer : ID LPAREN expr_list RPAREN { }
| ID LPAREN RPAREN { }
;
expr_list : expr { }
| expr_list COMMA expr { }
;
/**************************************************************/
/* Objective-C parsing */
/**************************************************************/
objective_c : OC_INTERFACE ID objc_inherit {
ObjCClass = 1;
init_language();
cplus_mode = CPLUS_PROTECTED;
sprintf(temp_name,"CPP_CLASS:%s\n",$2);
if (add_symbol(temp_name,(DataType *) 0, (char *) 0)) {
fprintf(stderr,"%s : Line %d. @interface %s is multiple defined.\n",
input_file,line_number,$2);
FatalError();
}
// Create a new documentation entry
doc_entry = new DocClass($2,doc_parent());
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
cplus_open_class($2, (char *) 0, ""); // Open up a new C++ class
} LBRACE objc_data RBRACE objc_methods OC_END {
if ($3) {
char *inames[1];
inames[0] = $3;
cplus_inherit(1,inames);
}
// Restore original doc entry for this class
doc_entry = doc_stack[doc_stack_top];
cplus_class_close($2);
doc_entry = 0;
doc_stack_top--;
cplus_mode = CPLUS_PUBLIC;
ObjCClass = 0;
delete $2;
delete $3;
}
/* An obj-c category declaration */
| OC_INTERFACE ID LPAREN ID RPAREN objc_protolist {
ObjCClass = 1;
init_language();
cplus_mode = CPLUS_PROTECTED;
doc_entry = cplus_set_class($2);
if (!doc_entry) {
doc_entry = new DocClass($2,doc_parent());
}
doc_stack_top++;
doc_stack[doc_stack_top] = doc_entry;
scanner_clear_start();
} objc_methods OC_END {
cplus_unset_class();
doc_entry = 0;
doc_stack_top--;
}
| OC_IMPLEMENT { skip_to_end(); }
| OC_PROTOCOL { skip_to_end(); }
| OC_CLASS ID initlist SEMI {
char *iname = make_name($2);
init_language();
lang->cpp_class_decl($2,iname,"");
for (int i = 0; i <$3.count; i++) {
if ($3.names[i]) {
iname = make_name($3.names[i]);
lang->cpp_class_decl($3.names[i],iname,"");
delete [] $3.names[i];
}
}
delete [] $3.names;
}
;
objc_inherit : COLON ID objc_protolist { $$ = $2;}
| objc_protolist empty { $$ = 0; }
;
objc_protolist : LESSTHAN { skip_template();
CCode.strip(); // Strip whitespace
CCode.replace("<","< ");
CCode.replace(">"," >");
$$ = CCode.get();
}
| empty {
$$ = "";
}
;
objc_data : objc_vars objc_data { }
| OC_PUBLIC {
cplus_mode = CPLUS_PUBLIC;
} objc_data { }
| OC_PRIVATE {
cplus_mode = CPLUS_PRIVATE;
} objc_data { }
| OC_PROTECTED {
cplus_mode = CPLUS_PROTECTED;
} objc_data { }
| error {
if (!Error) {
skip_decl();
{
static int last_error_line = -1;
if (last_error_line != line_number) {
fprintf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number);
FatalError();
last_error_line = line_number;
}
Error = 1;
}
}
} objc_data { }
| empty { }
;
objc_vars : objc_var objc_vartail SEMI {
}
;
/* An objective-C member variable */
objc_var : type declaration {
if (cplus_mode == CPLUS_PUBLIC) {
int oldstatus = Status;
char *tm;
char *iname;
if (Active_type) delete Active_type;
Active_type = new DataType($1);
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
if ($1->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,$1,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,$1);
Status = oldstatus;
}
scanner_clear_start();
delete $1;
}
| type declaration array {
if (cplus_mode == CPLUS_PUBLIC) {
int oldstatus = Status;
char *tm, *iname;
if (Active_type) delete Active_type;
Active_type = new DataType($1);
$1->is_pointer += $2.is_pointer;
$1->is_reference = $2.is_reference;
$1->arraystr = copy_string(ArrayString);
if ($1->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,$1,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,$1);
Status = oldstatus;
}
scanner_clear_start();
delete $1;
}
| NAME LPAREN ID RPAREN {
strcpy(yy_rename,$3);
Rename_true = 1;
} objc_var { };
objc_vartail : COMMA declaration objc_vartail {
if (cplus_mode == CPLUS_PUBLIC) {
int oldstatus = Status;
char *tm, *iname;
DataType *t = new DataType (Active_type);
t->is_pointer += $2.is_pointer;
t->is_reference = $2.is_reference;
if (t->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,t,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,t);
Status = oldstatus;
delete t;
}
scanner_clear_start();
}
| COMMA declaration array objc_vartail {
char *iname;
if (cplus_mode == CPLUS_PUBLIC) {
int oldstatus = Status;
char *tm;
DataType *t = new DataType (Active_type);
t->is_pointer += $2.is_pointer;
t->is_reference = $2.is_reference;
t->arraystr = copy_string(ArrayString);
if (t->status & STAT_READONLY) {
if (!(tm = typemap_lookup("memberin",typemap_lang,t,$2.id,"","")))
Status = Status | STAT_READONLY;
}
iname = make_name($2.id);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $2.id) iname = 0;
cplus_variable($2.id,iname,t);
Status = oldstatus;
delete t;
}
scanner_clear_start();
}
| empty { }
;
objc_methods : objc_method objc_methods { };
| ADDMETHODS LBRACE {
AddMethods = 1;
} objc_methods RBRACE {
AddMethods = 0;
}
| NAME LPAREN ID RPAREN {
strcpy(yy_rename,$3);
Rename_true = 1;
} objc_methods { }
| error {
skip_decl();
if (!Error) {
{
static int last_error_line = -1;
if (last_error_line != line_number) {
fprintf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number);
FatalError();
last_error_line = line_number;
}
Error = 1;
}
}
} objc_methods { }
| empty { }
;
objc_method : MINUS objc_ret_type ID objc_args objc_end {
char *iname;
// An objective-C instance function
// This is like a C++ member function
if (strcmp($3,objc_destruct) == 0) {
// This is an objective C destructor
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
cplus_destructor($3,(char *) 0);
} else {
iname = make_name($3);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3) iname = 0;
cplus_member_func($3,iname,$2,$4,0);
scanner_clear_start();
delete $2;
delete $3;
delete $4;
}
}
| PLUS objc_ret_type ID objc_args objc_end {
char *iname;
// An objective-C class function
// This is like a c++ static member function
if (strcmp($3,objc_construct) == 0) {
// This is an objective C constructor
doc_entry = new DocDecl($3,doc_stack[doc_stack_top]);
cplus_constructor($3,0,$4);
} else {
iname = make_name($3);
doc_entry = new DocDecl(iname,doc_stack[doc_stack_top]);
if (iname == $3) iname = 0;
cplus_static_func($3,iname,$2,$4);
}
scanner_clear_start();
delete $2;
delete $3;
delete $4;
}
;
objc_end : SEMI { CCode = ""; }
| LBRACE { skip_brace(); }
;
objc_ret_type : LPAREN type RPAREN {
$$ = $2;
}
| LPAREN type stars RPAREN {
$$ = $2;
$$->is_pointer += $3;
}
| empty { /* Empty type means "id" type */
$$ = new DataType(T_VOID);
sprintf($$->name,"id");
$$->is_pointer = 1;
$$->implicit_ptr = 1;
}
;
objc_arg_type : LPAREN parm RPAREN {
$$ = new DataType($2->t);
delete $2;
}
| empty {
$$ = new DataType(T_VOID);
sprintf($$->name,"id");
$$->is_pointer = 1;
$$->implicit_ptr = 1;
}
;
objc_args : objc_args objc_separator objc_arg_type ID {
Parm *p= new Parm($3,$4);
p->objc_separator = $2;
$$ = $1;
$$->append(p);
}
| empty {
$$ = new ParmList;
}
;
objc_separator : COLON { $$ = copy_string(":"); }
| ID COLON { $$ = new char[strlen($1)+2];
strcpy($$,$1);
strcat($$,":");
delete $1;
}
;
/* Miscellaneous stuff */
/* Documentation style list */
stylelist : ID stylearg styletail {
$$ = $3;
$$.names[$$.count] = copy_string($1);
$$.values[$$.count] = copy_string($2);
format_string($$.values[$$.count]);
$$.count++;
}
;
styletail : styletail COMMA ID stylearg {
$$ = $1;
$$.names[$$.count] = copy_string($3);
$$.values[$$.count] = copy_string($4);
format_string($$.values[$$.count]);
$$.count++;
}
| empty {
$$.names = new char *[NI_NAMES];
$$.values = new char *[NI_NAMES];
$$.count = 0;
}
;
stylearg : EQUAL NUM_INT {
$$ = $2;
}
| EQUAL STRING {
$$ = $2;
}
| empty {
$$ = 0;
}
;
/* --------------------------------------------------------------
* Type-map parameters
* -------------------------------------------------------------- */
tm_method : ID {
$$ = $1;
}
| CONST {
$$ = copy_string("const");
}
;
tm_list : typemap_parm tm_tail {
$$ = $1;
$$->next = $2;
}
;
tm_tail : COMMA typemap_parm tm_tail {
$$ = $2;
$$->next = $3;
}
| empty { $$ = 0;}
;
typemap_parm : type typemap_name {
if (InArray) {
$1->is_pointer++;
$1->arraystr = copy_string(ArrayString);
}
$$ = new TMParm;
$$->p = new Parm($1,$2);
$$->p->call_type = 0;
$$->args = tm_parm;
delete $1;
delete $2;
}
| type stars typemap_name {
$$ = new TMParm;
$$->p = new Parm($1,$3);
$$->p->t->is_pointer += $2;
$$->p->call_type = 0;
if (InArray) {
$$->p->t->is_pointer++;
$$->p->t->arraystr = copy_string(ArrayString);
}
$$->args = tm_parm;
delete $1;
delete $3;
}
| type AND typemap_name {
$$ = new TMParm;
$$->p = new Parm($1,$3);
$$->p->t->is_reference = 1;
$$->p->call_type = 0;
$$->p->t->is_pointer++;
if (!CPlusPlus) {
fprintf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number);
}
$$->args = tm_parm;
delete $1;
delete $3;
}
| type LPAREN stars typemap_name RPAREN LPAREN parms RPAREN {
fprintf(stderr,"%s : Line %d. Error. Function pointer not allowed (remap with typedef).\n", input_file, line_number);
FatalError();
$$ = new TMParm;
$$->p = new Parm($1,$4);
$$->p->t->type = T_ERROR;
$$->p->name = copy_string($4);
strcpy($$->p->t->name,"<function ptr>");
$$->args = tm_parm;
delete $1;
delete $4;
delete $7;
}
;
typemap_name : ID typemap_args {
$$ = $1;
InArray = 0;
}
| ID array {
ArrayBackup = "";
ArrayBackup << ArrayString;
} typemap_args {
$$ = $1;
InArray = $2;
ArrayString = "";
ArrayString << ArrayBackup;
}
| array {
ArrayBackup = "";
ArrayBackup << ArrayString;
} typemap_args {
$$ = new char[1];
$$[0] = 0;
InArray = $1;
ArrayString = "";
ArrayString << ArrayBackup;
}
| typemap_args { $$ = new char[1];
$$[0] = 0;
InArray = 0;
}
;
typemap_args : LPAREN parms RPAREN {
tm_parm = $2;
}
| empty {
tm_parm = 0;
}
;
idstring : ID {$$ = $1;}
| STRING { $$ = $1;}
;
/* User defined directive */
user_directive : USERDIRECTIVE LPAREN parms RPAREN uservalue { }
| USERDIRECTIVE uservalue { }
;
uservalue : ID SEMI { }
| STRING SEMI { }
| LBRACE RBRACE { }
;
/* Parsing of expressions, but only for throw away code */
/* Might need someday
dummyexpr : NUM_INT { }
| NUM_FLOAT { }
| NUM_UNSIGNED { }
| NUM_LONG { }
| NUM_ULONG { }
| SIZEOF LPAREN type RPAREN { }
| ID { }
| dummyexpr PLUS dummyexpr { }
| dummyexpr MINUS dummyexpr { }
| dummyexpr STAR dummyexpr { }
| dummyexpr SLASH dummyexpr { }
| dummyexpr AND dummyexpr { }
| dummyexpr OR dummyexpr { }
| dummyexpr XOR dummyexpr { }
| dummyexpr LSHIFT dummyexpr { }
| dummyexpr RSHIFT dummyexpr { }
| MINUS dummyexpr %prec UMINUS { }
| NOT dummyexpr { }
| LPAREN dummyexpr RPAREN { }
;
*/
empty : ;
%%
void error_recover() {
int c;
c = yylex();
while ((c > 0) && (c != SEMI))
c = yylex();
}
/* Called by the parser (yyparse) when an error is found.*/
void yyerror (char *) {
// Fprintf(stderr,"%s : Line %d. Syntax error.\n", input_file, line_number);
// error_recover();
}
|