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
|
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* lang.cxx
*
* Language base class functions. Default C++ handling is also implemented here.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
/* default mode settings */
static int director_mode = 0;
static int director_protected_mode = 1;
static int all_protected_mode = 0;
static int naturalvar_mode = 0;
Language *Language::this_ = 0;
/* Set director_protected_mode */
void Wrapper_director_mode_set(int flag) {
director_mode = flag;
}
void Wrapper_director_protected_mode_set(int flag) {
director_protected_mode = flag;
}
void Wrapper_all_protected_mode_set(int flag) {
all_protected_mode = flag;
}
void Wrapper_naturalvar_mode_set(int flag) {
naturalvar_mode = flag;
}
extern "C" {
int Swig_director_mode() {
return director_mode;
}
int Swig_director_protected_mode() {
return director_protected_mode;
}
int Swig_all_protected_mode() {
return all_protected_mode;
}
void Language_replace_special_variables(String *method, String *tm, Parm *parm) {
Language::instance()->replaceSpecialVariables(method, tm, parm);
}
}
/* Some status variables used during parsing */
static int InClass = 0; /* Parsing C++ or not */
static String *ClassName = 0; /* This is the real name of the current class */
static String *EnumClassName = 0; /* Enum class name */
static String *ClassPrefix = 0; /* Class prefix */
static String *EnumClassPrefix = 0; /* Prefix for strongly typed enums (including ClassPrefix) */
static String *NSpace = 0; /* Namespace for the nspace feature */
static String *ClassType = 0; /* Fully qualified type name to use */
static String *DirectorClassName = 0; /* Director name of the current class */
int Abstract = 0;
int ImportMode = 0;
int IsVirtual = 0;
static String *AttributeFunctionGet = 0;
static String *AttributeFunctionSet = 0;
static Node *CurrentClass = 0;
int line_number = 0;
String *input_file = 0;
int SmartPointer = 0;
static Hash *classhash;
extern int GenerateDefault;
extern int ForceExtern;
extern int AddExtern;
/* import modes */
#define IMPORT_MODE 1
#define IMPORT_MODULE 2
/* ----------------------------------------------------------------------
* Dispatcher::emit_one()
*
* Dispatch a single node
* ---------------------------------------------------------------------- */
int Dispatcher::emit_one(Node *n) {
int ret = SWIG_OK;
char *tag = Char(nodeType(n));
if (!tag) {
/* Printf(stderr,"SWIG: Fatal internal error. Malformed parse tree
node!\n"); */
return SWIG_OK;
}
/* Do not proceed if marked with an error */
if (Getattr(n, "error"))
return SWIG_OK;
/* Look for warnings */
String *wrn = Getattr(n, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
/* ============================================================
* C/C++ parsing
* ============================================================ */
if (strcmp(tag, "extern") == 0) {
ret = externDeclaration(n);
} else if (strcmp(tag, "cdecl") == 0) {
ret = cDeclaration(n);
} else if (strcmp(tag, "enum") == 0) {
ret = enumDeclaration(n);
} else if (strcmp(tag, "enumitem") == 0) {
ret = enumvalueDeclaration(n);
} else if (strcmp(tag, "enumforward") == 0) {
ret = enumforwardDeclaration(n);
} else if (strcmp(tag, "class") == 0) {
ret = classDeclaration(n);
} else if (strcmp(tag, "classforward") == 0) {
ret = classforwardDeclaration(n);
} else if (strcmp(tag, "constructor") == 0) {
ret = constructorDeclaration(n);
} else if (strcmp(tag, "destructor") == 0) {
ret = destructorDeclaration(n);
} else if (strcmp(tag, "access") == 0) {
ret = accessDeclaration(n);
} else if (strcmp(tag, "using") == 0) {
ret = usingDeclaration(n);
} else if (strcmp(tag, "namespace") == 0) {
ret = namespaceDeclaration(n);
} else if (strcmp(tag, "template") == 0) {
ret = templateDeclaration(n);
} else if (strcmp(tag, "lambda") == 0) {
ret = lambdaDeclaration(n);
}
/* ===============================================================
* SWIG directives
* =============================================================== */
else if (strcmp(tag, "top") == 0) {
ret = top(n);
} else if (strcmp(tag, "extend") == 0) {
ret = extendDirective(n);
} else if (strcmp(tag, "apply") == 0) {
ret = applyDirective(n);
} else if (strcmp(tag, "clear") == 0) {
ret = clearDirective(n);
} else if (strcmp(tag, "constant") == 0) {
ret = constantDirective(n);
} else if (strcmp(tag, "fragment") == 0) {
ret = fragmentDirective(n);
} else if (strcmp(tag, "import") == 0) {
ret = importDirective(n);
} else if (strcmp(tag, "include") == 0) {
ret = includeDirective(n);
} else if (strcmp(tag, "insert") == 0) {
ret = insertDirective(n);
} else if (strcmp(tag, "module") == 0) {
ret = moduleDirective(n);
} else if (strcmp(tag, "native") == 0) {
ret = nativeDirective(n);
} else if (strcmp(tag, "pragma") == 0) {
ret = pragmaDirective(n);
} else if (strcmp(tag, "typemap") == 0) {
ret = typemapDirective(n);
} else if (strcmp(tag, "typemapcopy") == 0) {
ret = typemapcopyDirective(n);
} else if (strcmp(tag, "typemapitem") == 0) {
ret = typemapitemDirective(n);
} else if (strcmp(tag, "types") == 0) {
ret = typesDirective(n);
} else {
Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag);
ret = SWIG_ERROR;
}
if (wrn)
Swig_warnfilter(wrn, 0);
return ret;
}
/* ----------------------------------------------------------------------
* Dispatcher::emit_children()
*
* Emit all children that match the given type. type = 0 means all types.
* ---------------------------------------------------------------------- */
int Dispatcher::emit_children(Node *n) {
Node *c;
char *eo = Char(Getattr(n, "feature:emitonlychildren"));
for (c = firstChild(n); c; c = nextSibling(c)) {
if (eo) {
const char *tag = Char(nodeType(c));
if (strcmp(tag, "cdecl") == 0) {
if (checkAttribute(c, "storage", "typedef"))
tag = "typedef";
}
if (strstr(eo, tag) == 0) {
continue;
}
}
emit_one(c);
}
return SWIG_OK;
}
/* Stubs for dispatcher class. We don't do anything by default---up to derived class
to fill in traversal code */
int Dispatcher::defaultHandler(Node *) {
return SWIG_OK;
}
int Dispatcher::extendDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::applyDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::clearDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::constantDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::fragmentDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::importDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::includeDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::insertDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::moduleDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::nativeDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::pragmaDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapitemDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapcopyDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typesDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::cDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::externDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumvalueDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumforwardDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::classDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::templateDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::lambdaDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::classforwardDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::constructorDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::destructorDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::accessDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::usingDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::namespaceDeclaration(Node *n) {
return defaultHandler(n);
}
/* Allocators */
Language::Language():
none_comparison(NewString("$arg != 0")),
director_ctor_code(NewString("")),
director_prot_ctor_code(0),
symtabs(NewHash()),
classtypes(NewHash()),
enumtypes(NewHash()),
overloading(0),
multiinput(0),
cplus_runtime(0),
directors(0) {
symbolAddScope(""); // create top level/global symbol table scope
argc_template_string = NewString("argc");
argv_template_string = NewString("argv[%d]");
/* Default director constructor code, passed to Swig_ConstructorToFunction */
Printv(director_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", "} else {\n", " $nondirector_new \n", "}\n", NIL);
/*
Default director 'protected' constructor code, disabled by
default. Each language that needs it, has to define it.
*/
director_prot_ctor_code = 0;
director_multiple_inheritance = 1;
director_language = 0;
assert(!this_);
this_ = this;
}
Language::~Language() {
Delete(symtabs);
Delete(classtypes);
Delete(enumtypes);
Delete(director_ctor_code);
Delete(none_comparison);
this_ = 0;
}
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *Language::directorClassName(Node *n) {
String *dirclassname;
String *nspace = NewString(Getattr(n, "sym:nspace"));
const char *attrib = "director:classname";
String *classname = getClassPrefix();
Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
if (Len(nspace) > 0)
dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname);
else
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
Delete(nspace);
return dirclassname;
}
/* ----------------------------------------------------------------------
emit_one()
---------------------------------------------------------------------- */
int Language::emit_one(Node *n) {
int ret;
int oldext;
if (!n)
return SWIG_OK;
if (GetFlag(n, "feature:ignore")
&& !Getattr(n, "feature:onlychildren"))
return SWIG_OK;
oldext = Extend;
if (Getattr(n, "feature:extend"))
Extend = 1;
line_number = Getline(n);
input_file = Getfile(n);
/*
symtab = Getattr(n,"symtab");
if (symtab) {
symtab = Swig_symbol_setscope(symtab);
}
*/
ret = Dispatcher::emit_one(n);
/*
if (symtab) {
Swig_symbol_setscope(symtab);
}
*/
Extend = oldext;
return ret;
}
static Parm *nonvoid_parms(Parm *p) {
if (p) {
SwigType *t = Getattr(p, "type");
if (SwigType_type(t) == T_VOID)
return 0;
}
return p;
}
/* -----------------------------------------------------------------------------
* cplus_value_type()
*
* Returns the alternative value type needed in C++ for class value
* types. When swig is not sure about using a plain $ltype value,
* since the class doesn't have a default constructor, or it can't be
* assigned, you will get back 'SwigValueWrapper<type >'.
*
* ----------------------------------------------------------------------------- */
SwigType *cplus_value_type(SwigType *t) {
return SwigType_alttype(t, 0);
}
static Node *first_nontemplate(Node *n) {
while (n) {
if (Strcmp(nodeType(n), "template") != 0)
return n;
n = Getattr(n, "sym:nextSibling");
}
return n;
}
/* --------------------------------------------------------------------------
* swig_pragma()
*
* Handle swig pragma directives.
* -------------------------------------------------------------------------- */
void swig_pragma(char *lang, char *name, char *value) {
if (strcmp(lang, "swig") == 0) {
if ((strcmp(name, "make_default") == 0) || ((strcmp(name, "makedefault") == 0))) {
GenerateDefault = 1;
} else if ((strcmp(name, "no_default") == 0) || ((strcmp(name, "nodefault") == 0))) {
Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use %%nodefaultctor, %%nodefaultdtor instead.\n");
GenerateDefault = 0;
} else if (strcmp(name, "attributefunction") == 0) {
String *nvalue = NewString(value);
char *s = strchr(Char(nvalue), ':');
if (!s) {
Swig_error(input_file, line_number, "Bad value for attributefunction. Expected \"fmtget:fmtset\".\n");
} else {
*s = 0;
AttributeFunctionGet = NewString(Char(nvalue));
AttributeFunctionSet = NewString(s + 1);
}
Delete(nvalue);
} else if (strcmp(name, "noattributefunction") == 0) {
AttributeFunctionGet = 0;
AttributeFunctionSet = 0;
}
}
}
/* --------------------------------------------------------------------------
* Language::use_naturalvar_mode()
*
* Determine whether to use const ref typemaps instead of pointer typemaps
* for variable access.
* -------------------------------------------------------------------------- */
int Language::use_naturalvar_mode(Node *n) const {
if (Getattr(n, "unnamed"))
return 0;
// The naturalvar feature can be attached to either the variable name or the variable's type
// naturalvar on the variable name is more specific and overrides naturalvar on the variable's type
String *naturalvar = Getattr(n, "feature:naturalvar");
bool explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0;
int nvar = GetFlag(n, "feature:naturalvar");
if (!explicitly_off && !nvar) {
/* look for feature in the class */
SwigType *ty = Getattr(n, "type");
SwigType *fullty = SwigType_typedef_resolve_all(ty);
if (SwigType_isclass(fullty)) {
SwigType *tys = SwigType_strip_qualifiers(fullty);
if (!CPlusPlus) {
Replaceall(tys, "struct ", "");
Replaceall(tys, "union ", "");
Replaceall(tys, "class ", "");
}
Node *typenode = Swig_symbol_clookup(tys, 0);
if (typenode) {
naturalvar = Getattr(typenode, "feature:naturalvar");
explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0;
nvar = nvar || GetFlag(typenode, "feature:naturalvar");
}
Delete(tys);
}
Delete(fullty);
}
nvar = nvar || naturalvar_mode;
return explicitly_off ? 0 : nvar ? CWRAP_NATURAL_VAR : 0;
}
/* ----------------------------------------------------------------------
* Language::top() - Top of parsing tree
* ---------------------------------------------------------------------- */
int Language::top(Node *n) {
Node *mod = Getattr(n, "module");
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
if (Getattr(options, "naturalvar")) {
naturalvar_mode = 1;
}
}
}
classhash = Getattr(n, "classes");
return emit_children(n);
}
/* ----------------------------------------------------------------------
* Language::extendDirective()
* ---------------------------------------------------------------------- */
int Language::extendDirective(Node *n) {
save_value<int> oldam(Extend, CWRAP_EXTEND);
save_value<AccessMode> oldmode(cplus_mode, PUBLIC);
emit_children(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::applyDirective()
* ---------------------------------------------------------------------- */
int Language::applyDirective(Node *n) {
Parm *pattern = Getattr(n, "pattern");
Node *c = firstChild(n);
while (c) {
Parm *apattern = Getattr(c, "pattern");
if (ParmList_len(pattern) != ParmList_len(apattern)) {
Swig_error(input_file, line_number, "Can't apply (%s) to (%s). Number of arguments don't match.\n", ParmList_str(pattern), ParmList_str(apattern));
} else {
if (!Swig_typemap_apply(pattern, apattern)) {
Swig_warning(WARN_TYPEMAP_APPLY_UNDEF, input_file, line_number, "Can't apply (%s). No typemaps are defined.\n", ParmList_str(pattern));
}
}
c = nextSibling(c);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::clearDirective()
* ---------------------------------------------------------------------- */
int Language::clearDirective(Node *n) {
Node *p;
for (p = firstChild(n); p; p = nextSibling(p)) {
ParmList *pattern = Getattr(p, "pattern");
Swig_typemap_clear_apply(pattern);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::constantDirective()
* ---------------------------------------------------------------------- */
int Language::constantDirective(Node *n) {
if (CurrentClass && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
if (!GetFlag(n, "feature:allowexcept")) {
UnsetFlag(n, "feature:except");
}
if (Getattr(n, "feature:exceptvar")) {
Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
}
if (!ImportMode) {
Swig_require("constantDirective", n, "name", "?value", NIL);
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
if (!value) {
value = Copy(name);
} else {
/* if (checkAttribute(n,"type","char")) {
value = NewString(value);
} else {
value = NewStringf("%(escape)s", value);
}
*/
Setattr(n, "rawvalue", value);
value = NewStringf("%(escape)s", value);
if (!Len(value))
Append(value, "\\0");
/* Printf(stdout,"'%s' = '%s'\n", name, value); */
}
Setattr(n, "value", value);
this->constantWrapper(n);
Swig_restore(n);
return SWIG_OK;
}
return SWIG_NOWRAP;
}
/* ----------------------------------------------------------------------
* Language::fragmentDirective()
* ---------------------------------------------------------------------- */
int Language::fragmentDirective(Node *n) {
Swig_fragment_register(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::importDirective()
* ---------------------------------------------------------------------- */
int Language::importDirective(Node *n) {
int oldim = ImportMode;
ImportMode = IMPORT_MODE;
emit_children(n);
ImportMode = oldim;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::includeDirective()
* ---------------------------------------------------------------------- */
int Language::includeDirective(Node *n) {
emit_children(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::insertDirective()
* ---------------------------------------------------------------------- */
int Language::insertDirective(Node *n) {
/* %insert directive */
if ((!ImportMode) || Getattr(n, "generated")) {
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
File *f = 0;
if (!section) { /* %{ ... %} */
f = Swig_filebyname("header");
} else {
f = Swig_filebyname(section);
}
if (f) {
Printf(f, "%s\n", code);
} else {
Swig_error(input_file, line_number, "Unknown target '%s' for %%insert directive.\n", section);
}
return SWIG_OK;
} else {
return SWIG_NOWRAP;
}
}
/* ----------------------------------------------------------------------
* Language::moduleDirective()
* ---------------------------------------------------------------------- */
int Language::moduleDirective(Node *n) {
(void) n;
/* %module directive */
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::nativeDirective()
* ---------------------------------------------------------------------- */
int Language::nativeDirective(Node *n) {
if (!ImportMode) {
return nativeWrapper(n);
} else {
return SWIG_NOWRAP;
}
}
/* ----------------------------------------------------------------------
* Language::pragmaDirective()
* ---------------------------------------------------------------------- */
int Language::pragmaDirective(Node *n) {
/* %pragma directive */
if (!ImportMode) {
String *lan = Getattr(n, "lang");
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
swig_pragma(Char(lan), Char(name), Char(value));
/* pragma(Char(lan),Char(name),Char(value)); */
return SWIG_OK;
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typemapDirective()
* ---------------------------------------------------------------------- */
int Language::typemapDirective(Node *n) {
/* %typemap directive */
String *method = Getattr(n, "method");
String *code = Getattr(n, "code");
Parm *kwargs = Getattr(n, "kwargs");
Node *items = firstChild(n);
static int namewarn = 0;
if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n");
if (!namewarn) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\
For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\
$source by $input and $target by $1. For typemaps related to return values (out,\n\
argout,ret,except), replace $source by $1 and $target by $result. See the file\n\
Doc/Manual/Typemaps.html for complete details.\n");
namewarn = 1;
}
}
if (Strcmp(method, "except") == 0) {
Swig_warning(WARN_DEPRECATED_EXCEPT_TM, Getfile(n), Getline(n), "%%typemap(except) is deprecated. Use the %%exception directive.\n");
}
if (Strcmp(method, "in") == 0) {
Hash *k;
k = kwargs;
while (k) {
if (checkAttribute(k, "name", "numinputs")) {
if (!multiinput && (GetInt(k, "value") > 1)) {
Swig_error(Getfile(n), Getline(n), "Multiple-input typemaps (numinputs > 1) not supported by this target language module.\n");
return SWIG_ERROR;
}
break;
}
k = nextSibling(k);
}
if (!k) {
k = NewHash();
Setattr(k, "name", "numinputs");
Setattr(k, "value", "1");
set_nextSibling(k, kwargs);
Setattr(n, "kwargs", k);
kwargs = k;
}
}
if (Strcmp(method, "ignore") == 0) {
Swig_warning(WARN_DEPRECATED_IGNORE_TM, Getfile(n), Getline(n), "%%typemap(ignore) has been replaced by %%typemap(in,numinputs=0).\n");
Clear(method);
Append(method, "in");
Hash *k = NewHash();
Setattr(k, "name", "numinputs");
Setattr(k, "value", "0");
set_nextSibling(k, kwargs);
Setattr(n, "kwargs", k);
kwargs = k;
}
/* Replace $descriptor() macros */
if (code) {
Setfile(code, Getfile(n));
Setline(code, Getline(n));
Swig_cparse_replace_descriptor(code);
}
while (items) {
Parm *pattern = Getattr(items, "pattern");
Parm *parms = Getattr(items, "parms");
if (code) {
Swig_typemap_register(method, pattern, code, parms, kwargs);
} else {
Swig_typemap_clear(method, pattern);
}
items = nextSibling(items);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typemapcopyDirective()
* ---------------------------------------------------------------------- */
int Language::typemapcopyDirective(Node *n) {
String *method = Getattr(n, "method");
Parm *pattern = Getattr(n, "pattern");
Node *items = firstChild(n);
int nsrc = 0;
nsrc = ParmList_len(pattern);
while (items) {
ParmList *npattern = Getattr(items, "pattern");
if (nsrc != ParmList_len(npattern)) {
Swig_error(input_file, line_number, "Can't copy typemap. Number of types differ.\n");
} else {
if (Swig_typemap_copy(method, pattern, npattern) < 0) {
Swig_error(input_file, line_number, "Can't copy typemap (%s) %s = %s\n", method, ParmList_str(pattern), ParmList_str(npattern));
}
}
items = nextSibling(items);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typesDirective()
* ---------------------------------------------------------------------- */
int Language::typesDirective(Node *n) {
Parm *parms = Getattr(n, "parms");
String *convcode = Getattr(n, "convcode"); /* optional user supplied conversion code for custom casting */
while (parms) {
SwigType *t = Getattr(parms, "type");
String *v = Getattr(parms, "value");
if (!v) {
SwigType_remember(t);
} else {
if (SwigType_issimple(t)) {
SwigType_inherit(t, v, 0, convcode);
}
}
parms = nextSibling(parms);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::cDeclaration()
* ---------------------------------------------------------------------- */
int Language::cDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *decl = Getattr(n, "decl");
String *storage = Getattr(n, "storage");
Node *over;
File *f_header = 0;
SwigType *ty, *fullty;
if (Getattr(n, "feature:onlychildren")) {
if (GetFlag(n, "feature:ignore")) {
return SWIG_NOWRAP;
} else {
// Found an unignored templated method that has an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0 && Cmp(storage, "typedef") != 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
return SWIG_NOWRAP;
}
}
}
/* discards nodes following the access control rules */
if (cplus_mode != PUBLIC || !is_public(n)) {
/* except for friends, they are not affected by access control */
int isfriend = Cmp(storage, "friend") == 0;
if (!isfriend) {
/* Check what the director needs. If the method is pure virtual, it is always needed.
* Also wrap non-virtual protected members if asked for (allprotected mode). */
if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || isNonVirtualProtectedAccess(n)))) {
return SWIG_NOWRAP;
}
// Prevent wrapping protected overloaded director methods more than once -
// This bit of code is only needed due to the cDeclaration call in classHandler()
String *wrapname = NewStringf("nonpublic_%s%s", symname, Getattr(n, "sym:overname"));
if (Getattr(CurrentClass, wrapname)) {
Delete(wrapname);
return SWIG_NOWRAP;
}
SetFlag(CurrentClass, wrapname);
Delete(wrapname);
}
}
if (Cmp(storage, "typedef") == 0) {
Swig_save("cDeclaration", n, "type", NIL);
SwigType *t = Copy(type);
if (t) {
SwigType_push(t, decl);
Setattr(n, "type", t);
typedefHandler(n);
}
Swig_restore(n);
return SWIG_OK;
}
/* If in import mode, we proceed no further */
if (ImportMode)
return SWIG_NOWRAP;
/* If we're in extend mode and there is code, replace the $descriptor macros */
if (Extend) {
String *code = Getattr(n, "code");
if (code) {
Setfile(code, Getfile(n));
Setline(code, Getline(n));
Swig_cparse_replace_descriptor(code);
}
}
/* Overloaded symbol check */
over = Swig_symbol_isoverloaded(n);
if (!overloading) {
if (over)
over = first_nontemplate(over);
if (over && (over != n)) {
Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", Swig_name_decl(n));
Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", Swig_name_decl(over));
return SWIG_NOWRAP;
}
}
if (!validIdentifier(symname)) {
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", SwigType_namestr(symname));
return SWIG_NOWRAP;
}
ty = NewString(type);
SwigType_push(ty, decl);
fullty = SwigType_typedef_resolve_all(ty);
if (SwigType_isfunction(fullty)) {
if (!SwigType_isfunction(ty)) {
Delete(ty);
ty = fullty;
fullty = 0;
ParmList *parms = SwigType_function_parms(ty, n);
Setattr(n, "parms", parms);
}
/* Transform the node into a 'function' node and emit */
if (!CurrentClass) {
f_header = Swig_filebyname("header");
if (AddExtern) {
if (f_header) {
if (Swig_storage_isextern(n) || (ForceExtern && !storage)) {
/* we don't need the 'extern' part in the C/C++ declaration,
and it produces some problems when namespace and SUN
Studio is used.
Printf(f_header,"extern %s", SwigType_str(ty,name));
In fact generating extern declarations is quite error prone and is
no longer the default. Getting it right seems impossible with namespaces
and default arguments and when a method is declared with the various Windows
calling conventions - SWIG doesn't understand Windows (non standard) calling
conventions in the first place, so can't regenerate them.
*/
String *str = SwigType_str(ty, name);
Printf(f_header, "%s", str);
Delete(str);
{
DOH *t = Getattr(n, "throws");
if (t) {
Printf(f_header, " throw(");
while (t) {
Printf(f_header, "%s", Getattr(t, "type"));
t = nextSibling(t);
if (t)
Printf(f_header, ",");
}
Printf(f_header, ")");
}
}
Printf(f_header, ";\n");
} else if (Swig_storage_isexternc(n)) {
/* here 'extern "C"' is needed */
String *str = SwigType_str(ty, name);
Printf(f_header, "extern \"C\" %s;\n", str);
Delete(str);
}
}
}
}
/* This needs to check qualifiers */
if (SwigType_isqualifier(ty)) {
SwigType *qual = SwigType_pop(ty);
Setattr(n, "qualifier", qual);
Delete(qual);
}
Delete(SwigType_pop_function(ty));
DohIncref(type);
Setattr(n, "type", ty);
functionHandler(n);
Setattr(n, "type", type);
Delete(ty);
Delete(type);
return SWIG_OK;
} else {
/* Some kind of variable declaration */
String *declaration = Copy(decl);
Delattr(n, "decl");
if (!CurrentClass) {
if (Swig_storage_isextern(n) || ForceExtern) {
if (AddExtern) {
f_header = Swig_filebyname("header");
if (f_header) {
String *str = SwigType_str(ty, name);
Printf(f_header, "%s %s;\n", Getattr(n, "storage"), str);
Delete(str);
}
}
}
}
if (!SwigType_ismutable(ty)) {
SetFlag(n, "feature:immutable");
}
/* If an array and elements are const, then read-only */
if (SwigType_isarray(ty)) {
SwigType *tya = SwigType_array_type(ty);
if (SwigType_isconst(tya)) {
SetFlag(n, "feature:immutable");
}
Delete(tya);
}
DohIncref(type);
Setattr(n, "type", ty);
variableHandler(n);
Setattr(n, "type", type);
Setattr(n, "decl", declaration);
Delete(ty);
Delete(type);
Delete(fullty);
return SWIG_OK;
}
}
/* ----------------------------------------------------------------------
* Language::functionHandler()
* ---------------------------------------------------------------------- */
int Language::functionHandler(Node *n) {
String *storage = Getattr(n, "storage");
int isfriend = CurrentClass && Cmp(storage, "friend") == 0;
int isstatic = CurrentClass && Swig_storage_isstatic(n) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"));
Parm *p = Getattr(n, "parms");
if (GetFlag(n, "feature:del")) {
/* the method acts like a delete operator, ie, we need to disown the parameter */
if (CurrentClass && !isstatic && !isfriend) {
SetFlag(n, "feature:self:disown");
} else {
if (p)
SetFlag(p, "wrap:disown");
}
}
if (!CurrentClass) {
globalfunctionHandler(n);
} else {
if (isstatic) {
staticmemberfunctionHandler(n);
} else if (isfriend) {
int oldInClass = InClass;
InClass = 0;
globalfunctionHandler(n);
InClass = oldInClass;
} else {
Node *explicit_n = 0;
if (directorsEnabled() && is_member_director(CurrentClass, n) && !extraDirectorProtectedCPPMethodsRequired()) {
bool virtual_but_not_pure_virtual = (!(Cmp(storage, "virtual")) && (Cmp(Getattr(n, "value"), "0") != 0));
if (virtual_but_not_pure_virtual) {
// Add additional wrapper which makes an explicit call to the virtual method (ie not a virtual call)
explicit_n = Copy(n);
String *new_symname = Copy(Getattr(n, "sym:name"));
String *suffix = Getattr(parentNode(n), "sym:name");
Printv(new_symname, "SwigExplicit", suffix, NIL);
Setattr(explicit_n, "sym:name", new_symname);
Delattr(explicit_n, "storage");
Delattr(explicit_n, "override");
Delattr(explicit_n, "hides");
SetFlag(explicit_n, "explicitcall");
Setattr(n, "explicitcallnode", explicit_n);
}
}
memberfunctionHandler(n);
if (explicit_n) {
memberfunctionHandler(explicit_n);
Delattr(explicit_n, "explicitcall");
Delete(explicit_n);
}
}
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::globalfunctionHandler()
* ---------------------------------------------------------------------- */
int Language::globalfunctionHandler(Node *n) {
Swig_require("globalfunctionHandler", n, "name", "sym:name", "type", "?parms", NIL);
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
/* Check for callback mode */
String *cb = GetFlagAttr(n, "feature:callback");
if (cb) {
String *cbname = Getattr(n, "feature:callback:name");
if (!cbname) {
cbname = NewStringf(cb, symname);
Setattr(n, "feature:callback:name", cbname);
}
callbackfunctionHandler(n);
if (Cmp(cbname, symname) == 0) {
Delete(cbname);
Swig_restore(n);
return SWIG_NOWRAP;
}
Delete(cbname);
}
Setattr(n, "parms", nonvoid_parms(parms));
String *extendname = Getattr(n, "extendname");
String *call = Swig_cfunction_call(extendname ? extendname : name, parms);
String *cres = Swig_cresult(type, Swig_cresult_name(), call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
functionWrapper(n);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::callbackfunctionHandler()
* ---------------------------------------------------------------------- */
int Language::callbackfunctionHandler(Node *n) {
Swig_require("callbackfunctionHandler", n, "name", "*sym:name", "*type", "?value", NIL);
String *type = Getattr(n, "type");
String *name = Getattr(n, "name");
String *parms = Getattr(n, "parms");
String *cbname = Getattr(n, "feature:callback:name");
String *calltype = NewStringf("(%s (*)(%s))(%s)", SwigType_str(type, 0), ParmList_str(parms), SwigType_namestr(name));
SwigType *cbty = Copy(type);
SwigType_add_function(cbty, parms);
SwigType_add_pointer(cbty);
Setattr(n, "sym:name", cbname);
Setattr(n, "type", cbty);
Setattr(n, "value", calltype);
Node *ns = symbolLookup(cbname);
if (!ns)
constantWrapper(n);
Delete(cbty);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::memberfunctionHandler()
* ---------------------------------------------------------------------- */
int Language::memberfunctionHandler(Node *n) {
Swig_require("memberfunctionHandler", n, "*name", "*sym:name", "*type", "?parms", "?value", NIL);
String *storage = Getattr(n, "storage");
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
ParmList *parms = Getattr(n, "parms");
String *cb = GetFlagAttr(n, "feature:callback");
if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) {
IsVirtual = PURE_VIRTUAL;
} else {
IsVirtual = PLAIN_VIRTUAL;
}
} else {
IsVirtual = 0;
}
if (cb) {
Node *cbn = NewHash();
String *cbname = Getattr(n, "feature:callback:name");
if (!cbname) {
cbname = NewStringf(cb, symname);
}
SwigType *cbty = Copy(type);
SwigType_add_function(cbty, parms);
SwigType_add_memberpointer(cbty, ClassName);
String *cbvalue = NewStringf("&%s::%s", ClassName, name);
Setattr(cbn, "sym:name", cbname);
Setattr(cbn, "type", cbty);
Setattr(cbn, "value", cbvalue);
Setattr(cbn, "name", name);
Setfile(cbn, Getfile(n));
Setline(cbn, Getline(n));
memberconstantHandler(cbn);
Setattr(n, "feature:callback:name", Swig_name_member(NSpace, ClassPrefix, cbname));
Delete(cb);
Delete(cbn);
Delete(cbvalue);
Delete(cbty);
Delete(cbname);
if (Cmp(cbname, symname) == 0) {
Swig_restore(n);
return SWIG_NOWRAP;
}
}
String *fname = Swig_name_member(NSpace, ClassPrefix, symname);
if (Extend && SmartPointer) {
if (!Getattr(n, "extendsmartclassname")) {
Setattr(n, "extendsmartclassname", Getattr(CurrentClass, "allocate:smartpointerpointeeclassname"));
}
}
// Set up the type for the cast to this class for use when wrapping const director (virtual) methods.
// Note: protected director methods or when allprotected mode turned on.
String *director_type = 0;
if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || isNonVirtualProtectedAccess(n))) {
director_type = Copy(DirectorClassName);
String *qualifier = Getattr(n, "qualifier");
if (qualifier)
SwigType_push(director_type, qualifier);
SwigType_add_pointer(director_type);
}
int DirectorExtraCall = 0;
if (directorsEnabled() && is_member_director(CurrentClass, n) && !SmartPointer)
if (extraDirectorProtectedCPPMethodsRequired())
DirectorExtraCall = CWRAP_DIRECTOR_TWO_CALLS;
if (GetFlag(n, "explicitcall"))
DirectorExtraCall = CWRAP_DIRECTOR_ONE_CALL;
int extendmember = GetFlag(n, "isextendmember") ? Extend : 0;
int flags = Getattr(n, "template") ? extendmember | SmartPointer : Extend | SmartPointer | DirectorExtraCall;
Swig_MethodToFunction(n, NSpace, ClassType, flags, director_type, is_member_director(CurrentClass, n));
Setattr(n, "sym:name", fname);
functionWrapper(n);
Delete(director_type);
Delete(fname);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::staticmemberfunctionHandler()
* ---------------------------------------------------------------------- */
int Language::staticmemberfunctionHandler(Node *n) {
Swig_require("staticmemberfunctionHandler", n, "*name", "*sym:name", "*type", NIL);
Swig_save("staticmemberfunctionHandler", n, "storage", NIL);
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
String *cb = GetFlagAttr(n, "feature:callback");
String *cname, *mrename;
if (!Extend) {
Node *sb = Getattr(n, "cplus:staticbase");
String *sname = Getattr(sb, "name");
if (isNonVirtualProtectedAccess(n))
cname = NewStringf("%s::%s", DirectorClassName, name);
else
cname = NewStringf("%s::%s", sname, name);
} else {
String *mname = Swig_name_mangle(ClassName);
cname = Swig_name_member(NSpace, mname, name);
Delete(mname);
}
mrename = Swig_name_member(NSpace, ClassPrefix, symname);
if (Extend) {
String *code = Getattr(n, "code");
String *defaultargs = Getattr(n, "defaultargs");
String *mangled = Swig_name_mangle(mrename);
Delete(mrename);
mrename = mangled;
if (Getattr(n, "sym:overloaded") && code) {
Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
}
if (!defaultargs && code) {
/* Hmmm. An added static member. We have to create a little wrapper for this */
String *mangled_cname = Swig_name_mangle(cname);
Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0);
Setattr(n, "extendname", mangled_cname);
Delete(mangled_cname);
}
}
Setattr(n, "name", cname);
Setattr(n, "sym:name", mrename);
if (cb) {
String *cbname = NewStringf(cb, symname);
Setattr(n, "feature:callback:name", Swig_name_member(NSpace, ClassPrefix, cbname));
Setattr(n, "feature:callback:staticname", name);
}
Delattr(n, "storage");
globalfunctionHandler(n);
Delete(cname);
Delete(mrename);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::variableHandler()
* ---------------------------------------------------------------------- */
int Language::variableHandler(Node *n) {
/* If not a smart-pointer access or added method. We clear
feature:except. There is no way C++ or C would throw
an exception merely for accessing a member data.
Caveat: Some compilers seem to route attribute access through
methods which can generate exceptions. The feature:allowexcept
allows this. Also, the feature:exceptvar can be used to match
only variables.
*/
if (!(Extend | SmartPointer)) {
if (!GetFlag(n, "feature:allowexcept")) {
UnsetFlag(n, "feature:except");
}
if (Getattr(n, "feature:exceptvar")) {
Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
}
}
if (!CurrentClass) {
globalvariableHandler(n);
} else {
Swig_save("variableHandler", n, "feature:immutable", NIL);
if (SmartPointer) {
/* If a smart-pointer and it's a constant access, we have to set immutable */
if (!Getattr(CurrentClass, "allocate:smartpointermutable")) {
SetFlag(n, "feature:immutable");
}
}
if (Swig_storage_isstatic(n) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"))) {
staticmembervariableHandler(n);
} else {
membervariableHandler(n);
}
Swig_restore(n);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::globalvariableHandler()
* ---------------------------------------------------------------------- */
int Language::globalvariableHandler(Node *n) {
variableWrapper(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::membervariableHandler()
* ---------------------------------------------------------------------- */
int Language::membervariableHandler(Node *n) {
Swig_require("membervariableHandler", n, "*name", "*sym:name", "*type", NIL);
Swig_save("membervariableHandler", n, "parms", NIL);
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
if (!AttributeFunctionGet) {
String *mname = Swig_name_member(0, ClassPrefix, symname);
String *mrename_get = Swig_name_get(NSpace, mname);
String *mrename_set = Swig_name_set(NSpace, mname);
Delete(mname);
/* Create a function to set the value of the variable */
int assignable = is_assignable(n);
if (SmartPointer) {
if (!Getattr(CurrentClass, "allocate:smartpointermutable")) {
assignable = 0;
}
}
if (assignable) {
int make_set_wrapper = 1;
String *tm = 0;
String *target = 0;
if (!Extend) {
if (SmartPointer) {
if (Swig_storage_isstatic(n)) {
Node *sn = Getattr(n, "cplus:staticbase");
String *base = Getattr(sn, "name");
target = NewStringf("%s::%s", base, name);
} else {
String *pname = Swig_cparm_name(0, 0);
target = NewStringf("(*%s)->%s", pname, name);
Delete(pname);
}
} else {
String *pname = isNonVirtualProtectedAccess(n) ? NewString("darg") : Swig_cparm_name(0, 0);
target = NewStringf("%s->%s", pname, name);
Delete(pname);
}
// This is an input type typemap lookup and so it should not use Node n
// otherwise qualification is done on the parameter name for the setter function
Parm *nin = NewParm(type, name, n);
tm = Swig_typemap_lookup("memberin", nin, target, 0);
Delete(nin);
}
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (isNonVirtualProtectedAccess(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
Swig_MembersetToFunction(n, ClassType, flags);
Setattr(n, "memberset", "1");
if (!Extend) {
/* Check for a member in typemap here */
if (!tm) {
if (SwigType_isarray(type)) {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
make_set_wrapper = 0;
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
String *pname1 = Swig_cparm_name(0, 1);
Replace(tm, "$source", pname1, DOH_REPLACE_ANY);
Replace(tm, "$target", target, DOH_REPLACE_ANY);
Replace(tm, "$input", pname1, DOH_REPLACE_ANY);
Replace(tm, "$self", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);
Delete(pname0);
Delete(pname1);
}
Delete(target);
}
if (make_set_wrapper) {
Setattr(n, "sym:name", mrename_set);
functionWrapper(n);
} else {
SetFlag(n, "feature:immutable");
}
/* Restore parameters */
Setattr(n, "type", type);
Setattr(n, "name", name);
Setattr(n, "sym:name", symname);
Delattr(n, "memberset");
/* Delete all attached typemaps and typemap attributes */
Iterator ki;
for (ki = First(n); ki.key; ki = Next(ki)) {
if (Strncmp(ki.key, "tmap:", 5) == 0)
Delattr(n, ki.key);
}
}
/* Emit get function */
{
int flags = Extend | SmartPointer | use_naturalvar_mode(n);
if (isNonVirtualProtectedAccess(n))
flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
Swig_MembergetToFunction(n, ClassType, flags);
Setattr(n, "sym:name", mrename_get);
Setattr(n, "memberget", "1");
functionWrapper(n);
Delattr(n, "memberget");
}
Delete(mrename_get);
Delete(mrename_set);
} else {
/* This code is used to support the attributefunction directive
where member variables are converted automagically to
accessor functions */
#if 0
Parm *p;
String *gname;
SwigType *vty;
p = NewParm(type, 0, n);
gname = NewStringf(AttributeFunctionGet, symname);
if (!Extend) {
ActionFunc = Copy(Swig_cmemberget_call(name, type));
cpp_member_func(Char(gname), Char(gname), type, 0);
Delete(ActionFunc);
} else {
String *cname = Swig_name_get(NSpace, name);
cpp_member_func(Char(cname), Char(gname), type, 0);
Delete(cname);
}
Delete(gname);
if (!GetFlag(n, "feature:immutable")) {
gname = NewStringf(AttributeFunctionSet, symname);
vty = NewString("void");
if (!Extend) {
ActionFunc = Copy(Swig_cmemberset_call(name, type));
cpp_member_func(Char(gname), Char(gname), vty, p);
Delete(ActionFunc);
} else {
String *cname = Swig_name_set(NSpace, name);
cpp_member_func(Char(cname), Char(gname), vty, p);
Delete(cname);
}
Delete(gname);
}
ActionFunc = 0;
#endif
}
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::staticmembervariableHandler()
* ---------------------------------------------------------------------- */
int Language::staticmembervariableHandler(Node *n) {
Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL);
String *value = Getattr(n, "value");
String *classname = !SmartPointer ? (isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerpointeeclassname");
if (!value || !Getattr(n, "hasconsttype")) {
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
String *cname, *mrename;
/* Create the variable name */
mrename = Swig_name_member(0, ClassPrefix, symname);
cname = NewStringf("%s::%s", classname, name);
Setattr(n, "sym:name", mrename);
Setattr(n, "name", cname);
/* Wrap as an ordinary global variable */
variableWrapper(n);
Delete(mrename);
Delete(cname);
} else {
/* This is a C++ static member declaration with an initializer and it's const.
Certain C++ compilers optimize this out so that there is no linkage to a
memory address. Example:
class Foo {
public:
static const int x = 3;
};
Some discussion of this in section 9.4 of the C++ draft standard.
Also, we have to manage the case:
class Foo {
public:
%extend {
static const int x = 3;
}
};
in which there's no actual Foo::x variable to refer to. In this case,
the best we can do is to wrap the given value verbatim.
*/
String *name = Getattr(n, "name");
String *cname = NewStringf("%s::%s", classname, name);
if (Extend) {
/* the variable is a synthesized one.
There's nothing we can do; we just keep the given value */
} else {
/* we refer to the value as Foo::x */
String *value = SwigType_namestr(cname);
Setattr(n, "value", value);
}
SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n, "type"));
SwigType *t2 = SwigType_strip_qualifiers(t1);
Setattr(n, "type", t2);
Delete(t1);
Delete(t2);
SetFlag(n, "wrappedasconstant");
memberconstantHandler(n);
Delete(cname);
}
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::externDeclaration()
* ---------------------------------------------------------------------- */
int Language::externDeclaration(Node *n) {
return emit_children(n);
}
/* ----------------------------------------------------------------------
* Language::enumDeclaration()
* ---------------------------------------------------------------------- */
int Language::enumDeclaration(Node *n) {
if (CurrentClass && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
String *oldNSpace = NSpace;
NSpace = Getattr(n, "sym:nspace");
String *oldEnumClassPrefix = EnumClassPrefix;
if (GetFlag(n, "scopedenum")) {
assert(Getattr(n, "sym:name"));
assert(Getattr(n, "name"));
EnumClassPrefix = ClassPrefix ? NewStringf("%s_", ClassPrefix) : NewString("");
Printv(EnumClassPrefix, Getattr(n, "sym:name"), NIL);
EnumClassName = Copy(Getattr(n, "name"));
}
if (!ImportMode) {
emit_children(n);
}
if (GetFlag(n, "scopedenum")) {
Delete(EnumClassName);
EnumClassName = 0;
Delete(EnumClassPrefix);
EnumClassPrefix = oldEnumClassPrefix;
}
NSpace = oldNSpace;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::enumvalueDeclaration()
* ---------------------------------------------------------------------- */
int Language::enumvalueDeclaration(Node *n) {
if (CurrentClass && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
Swig_require("enumvalueDeclaration", n, "*name", "*sym:name", "?value", NIL);
String *value = Getattr(n, "value");
String *name = Getattr(n, "name");
String *tmpValue;
if (value)
tmpValue = NewString(value);
else
tmpValue = NewString(name);
Setattr(n, "value", tmpValue);
Node *parent = parentNode(n);
if (GetFlag(parent, "scopedenum")) {
String *symname = Swig_name_member(0, Getattr(parent, "sym:name"), Getattr(n, "sym:name"));
Setattr(n, "sym:name", symname);
Delete(symname);
}
if (!CurrentClass || !cparse_cplusplus) {
Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */
constantWrapper(n);
} else {
memberconstantHandler(n);
}
Delete(tmpValue);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::enumforwardDeclaration()
* ---------------------------------------------------------------------- */
int Language::enumforwardDeclaration(Node *n) {
(void) n;
if (GetFlag(n, "enumMissing"))
enumDeclaration(n); // Generate an empty enum in target language
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Language::memberconstantHandler()
* ----------------------------------------------------------------------------- */
int Language::memberconstantHandler(Node *n) {
Swig_require("memberconstantHandler", n, "*name", "*sym:name", "value", NIL);
if (!GetFlag(n, "feature:allowexcept")) {
UnsetFlag(n, "feature:except");
}
if (Getattr(n, "feature:exceptvar")) {
Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
}
String *enumvalue_symname = Getattr(n, "enumvalueDeclaration:sym:name"); // Only set if a strongly typed enum
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
String *value = Getattr(n, "value");
String *mrename = Swig_name_member(0, EnumClassPrefix, enumvalue_symname ? enumvalue_symname : symname);
Setattr(n, "sym:name", mrename);
String *new_name = 0;
if (Extend)
new_name = Copy(value);
else if (EnumClassName)
new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : EnumClassName, name);
else
new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName, name);
Setattr(n, "name", new_name);
constantWrapper(n);
Delete(mrename);
Delete(new_name);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typedefHandler()
* ---------------------------------------------------------------------- */
int Language::typedefHandler(Node *n) {
/* since this is a recurring issue, we are going to remember the
typedef pointer, if already it is not a pointer or reference, as
in
typedef void NT;
int func(NT *p);
see director_basic.i for example.
*/
SwigType *name = Getattr(n, "name");
SwigType *decl = Getattr(n, "decl");
if (!SwigType_ispointer(decl) && !SwigType_isreference(decl)) {
SwigType *pname = Copy(name);
SwigType_add_pointer(pname);
SwigType_remember(pname);
Delete(pname);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorMethod()
* ---------------------------------------------------------------------- */
int Language::classDirectorMethod(Node *n, Node *parent, String *super) {
(void) n;
(void) parent;
(void) super;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorConstructor()
* ---------------------------------------------------------------------- */
int Language::classDirectorConstructor(Node *n) {
(void) n;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorDefaultConstructor()
* ---------------------------------------------------------------------- */
int Language::classDirectorDefaultConstructor(Node *n) {
(void) n;
return SWIG_OK;
}
static String *vtable_method_id(Node *n) {
String *nodeType = Getattr(n, "nodeType");
int is_destructor = (Cmp(nodeType, "destructor") == 0);
if (is_destructor)
return 0;
String *name = Getattr(n, "name");
String *decl = Getattr(n, "decl");
String *local_decl = SwigType_typedef_resolve_all(decl);
String *tmp = SwigType_pop_function(local_decl);
Delete(local_decl);
local_decl = tmp;
Node *method_id = NewStringf("%s|%s", name, local_decl);
Delete(local_decl);
return method_id;
}
/* ----------------------------------------------------------------------
* Language::unrollVirtualMethods()
* ---------------------------------------------------------------------- */
int Language::unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase) {
Node *ni;
String *nodeType;
String *classname;
String *decl;
bool first_base = false;
// recurse through all base classes to build the vtable
List *bl = Getattr(n, "bases");
if (bl) {
Iterator bi;
for (bi = First(bl); bi.item; bi = Next(bi)) {
if (first_base && !director_multiple_inheritance)
break;
unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor);
first_base = true;
}
}
// recurse through all protected base classes to build the vtable, as needed
bl = Getattr(n, "protectedbases");
if (bl) {
Iterator bi;
for (bi = First(bl); bi.item; bi = Next(bi)) {
if (first_base && !director_multiple_inheritance)
break;
unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor, 1);
first_base = true;
}
}
// find the methods that need directors
classname = Getattr(n, "name");
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
/* we only need to check the virtual members */
nodeType = Getattr(ni, "nodeType");
int is_using = (Cmp(nodeType, "using") == 0);
Node *nn = is_using ? firstChild(ni) : ni; /* assume there is only one child node for "using" nodes */
if (is_using) {
if (nn)
nodeType = Getattr(nn, "nodeType");
else
continue; // A private "using" node
}
if (!checkAttribute(nn, "storage", "virtual"))
continue;
/* we need to add methods(cdecl) and destructor (to check for throw decl) */
int is_destructor = (Cmp(nodeType, "destructor") == 0);
if ((Cmp(nodeType, "cdecl") == 0) || is_destructor) {
decl = Getattr(nn, "decl");
/* extra check for function type and proper access */
if (SwigType_isfunction(decl) && (((!protectedbase || dirprot_mode()) && is_public(nn)) || need_nonpublic_member(nn))) {
String *name = Getattr(nn, "name");
Node *method_id = is_destructor ? NewStringf("~destructor") : vtable_method_id(nn);
/* Make sure that the new method overwrites the existing: */
int len = Len(vm);
const int DO_NOT_REPLACE = -1;
int replace = DO_NOT_REPLACE;
for (int i = 0; i < len; i++) {
Node *item = Getitem(vm, i);
String *check_vmid = Getattr(item, "vmid");
if (Strcmp(method_id, check_vmid) == 0) {
replace = i;
break;
}
}
/* filling a new method item */
String *fqdname = NewStringf("%s::%s", classname, name);
Hash *item = NewHash();
Setattr(item, "fqdname", fqdname);
Node *m = Copy(nn);
/* Store the complete return type - needed for non-simple return types (pointers, references etc.) */
SwigType *ty = NewString(Getattr(m, "type"));
SwigType_push(ty, decl);
if (SwigType_isqualifier(ty)) {
Delete(SwigType_pop(ty));
}
Delete(SwigType_pop_function(ty));
Setattr(m, "returntype", ty);
String *mname = NewStringf("%s::%s", Getattr(parent, "name"), name);
/* apply the features of the original method found in the base class */
Swig_features_get(Swig_cparse_features(), 0, mname, Getattr(m, "decl"), m);
Setattr(item, "methodNode", m);
Setattr(item, "vmid", method_id);
if (replace == DO_NOT_REPLACE)
Append(vm, item);
else
Setitem(vm, replace, item);
Setattr(nn, "directorNode", m);
Delete(mname);
}
if (is_destructor) {
virtual_destructor = 1;
}
}
}
/*
We delete all the nodirector methods. This prevents the
generation of 'empty' director classes.
But this has to be done outside the previous 'for'
an the recursive loop!.
*/
if (n == parent) {
int len = Len(vm);
for (int i = 0; i < len; i++) {
Node *item = Getitem(vm, i);
Node *m = Getattr(item, "methodNode");
/* retrieve the director features */
int mdir = GetFlag(m, "feature:director");
int mndir = GetFlag(m, "feature:nodirector");
/* 'nodirector' has precedence over 'director' */
int dir = (mdir || mndir) ? (mdir && !mndir) : 1;
/* check if the method was found only in a base class */
Node *p = Getattr(m, "parentNode");
if (p != n) {
Node *c = Copy(m);
Setattr(c, "parentNode", n);
int cdir = GetFlag(c, "feature:director");
int cndir = GetFlag(c, "feature:nodirector");
dir = (cdir || cndir) ? (cdir && !cndir) : dir;
Delete(c);
}
if (dir) {
/* be sure the 'nodirector' feature is disabled */
if (mndir)
Delattr(m, "feature:nodirector");
} else {
/* or just delete from the vm, since is not a director method */
Delitem(vm, i);
len--;
i--;
}
}
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorDisown()
* ---------------------------------------------------------------------- */
int Language::classDirectorDisown(Node *n) {
Node *disown = NewHash();
String *mrename;
String *symname = Getattr(n, "sym:name");
mrename = Swig_name_disown(NSpace, symname);
String *type = NewString(ClassType);
String *name = NewString("self");
SwigType_add_pointer(type);
Parm *p = NewParm(type, name, n);
Delete(name);
Delete(type);
type = NewString("void");
String *action = NewString("");
Printv(action, "{\n", "Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL);
Setfile(disown, Getfile(n));
Setline(disown, Getline(n));
Setattr(disown, "wrap:action", action);
Setattr(disown, "name", mrename);
Setattr(disown, "sym:name", mrename);
Setattr(disown, "type", type);
Setattr(disown, "parms", p);
Delete(action);
Delete(mrename);
Delete(type);
Delete(p);
functionWrapper(disown);
Delete(disown);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorConstructors()
* ---------------------------------------------------------------------- */
int Language::classDirectorConstructors(Node *n) {
Node *ni;
String *nodeType;
Node *parent = Swig_methodclass(n);
int default_ctor = Getattr(parent, "allocate:default_constructor") ? 1 : 0;
int protected_ctor = 0;
int constructor = 0;
/* emit constructors */
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
nodeType = Getattr(ni, "nodeType");
if (Cmp(nodeType, "constructor") == 0) {
if (GetFlag(ni, "feature:ignore"))
continue;
Parm *parms = Getattr(ni, "parms");
if (is_public(ni)) {
/* emit public constructor */
classDirectorConstructor(ni);
constructor = 1;
if (default_ctor)
default_ctor = !ParmList_numrequired(parms);
} else {
/* emit protected constructor if needed */
if (need_nonpublic_ctor(ni)) {
classDirectorConstructor(ni);
constructor = 1;
protected_ctor = 1;
if (default_ctor)
default_ctor = !ParmList_numrequired(parms);
}
}
}
}
/* emit default constructor if needed */
if (!constructor) {
if (!default_ctor) {
/* we get here because the class has no public, protected or
default constructor, therefore, the director class can't be
created, ie, is kind of abstract. */
Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n), "Director class '%s' can't be constructed\n", SwigType_namestr(Getattr(n, "name")));
return SWIG_OK;
}
classDirectorDefaultConstructor(n);
default_ctor = 1;
}
/* this is just to support old java behavior, ie, the default
constructor is always emitted, even when protected, and not
needed, since there is a public constructor already defined.
(scottm) This code is needed here to make the director_abstract +
test generate compilable code (Example2 in director_abastract.i).
(mmatus) This is very strange, since swig compiled with gcc3.2.3
doesn't need it here....
*/
if (!default_ctor && !protected_ctor) {
if (Getattr(parent, "allocate:default_base_constructor")) {
classDirectorDefaultConstructor(n);
}
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorMethods()
* ---------------------------------------------------------------------- */
int Language::classDirectorMethods(Node *n) {
Node *vtable = Getattr(n, "vtable");
int len = Len(vtable);
for (int i = 0; i < len; i++) {
Node *item = Getitem(vtable, i);
String *method = Getattr(item, "methodNode");
String *fqdname = Getattr(item, "fqdname");
if (GetFlag(method, "feature:nodirector"))
continue;
String *wrn = Getattr(method, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
String *type = Getattr(method, "nodeType");
if (!Cmp(type, "destructor")) {
classDirectorDestructor(method);
} else {
Swig_require("classDirectorMethods", method, "*type", NIL);
assert(Getattr(method, "returntype"));
Setattr(method, "type", Getattr(method, "returntype"));
if (classDirectorMethod(method, n, fqdname) == SWIG_OK)
SetFlag(item, "director");
Swig_restore(method);
}
if (wrn)
Swig_warnfilter(wrn, 0);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorInit()
* ---------------------------------------------------------------------- */
int Language::classDirectorInit(Node *n) {
(void) n;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorDestructor()
* ---------------------------------------------------------------------- */
int Language::classDirectorDestructor(Node *n) {
/*
Always emit the virtual destructor in the declaration and in the
compilation unit. Been explicit here can't make any damage, and
can solve some nasty C++ compiler problems.
*/
File *f_directors = Swig_filebyname("director");
File *f_directors_h = Swig_filebyname("director_h");
if (Getattr(n, "throw")) {
Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() throw () {\n}\n\n", DirectorClassName, DirectorClassName);
} else {
Printf(f_directors_h, " virtual ~%s();\n", DirectorClassName);
Printf(f_directors, "%s::~%s() {\n}\n\n", DirectorClassName, DirectorClassName);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirectorEnd()
* ---------------------------------------------------------------------- */
int Language::classDirectorEnd(Node *n) {
(void) n;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDirector()
* ---------------------------------------------------------------------- */
int Language::classDirector(Node *n) {
Node *module = Getattr(n, "module");
String *classtype = Getattr(n, "classtype");
Hash *directormap = 0;
if (module) {
directormap = Getattr(module, "wrap:directormap");
if (directormap == 0) {
directormap = NewHash();
Setattr(module, "wrap:directormap", directormap);
}
}
List *vtable = NewList();
int virtual_destructor = 0;
unrollVirtualMethods(n, n, vtable, 0, virtual_destructor);
// Emit all the using base::member statements for non virtual members (allprotected mode)
Node *ni;
String *using_protected_members_code = NewString("");
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
Node *nodeType = Getattr(ni, "nodeType");
bool cdeclaration = (Cmp(nodeType, "cdecl") == 0);
if (cdeclaration && !GetFlag(ni, "feature:ignore")) {
if (isNonVirtualProtectedAccess(ni)) {
Node *overloaded = Getattr(ni, "sym:overloaded");
// emit the using base::member statement (but only once if the method is overloaded)
if (!overloaded || (overloaded && (overloaded == ni)))
Printf(using_protected_members_code, " using %s::%s;\n", SwigType_namestr(ClassName), Getattr(ni, "name"));
}
}
}
if (virtual_destructor || Len(vtable) > 0) {
if (!virtual_destructor) {
String *classtype = Getattr(n, "classtype");
Swig_warning(WARN_LANG_DIRECTOR_VDESTRUCT, input_file, line_number, "Director base class %s has no virtual destructor.\n", classtype);
}
Setattr(n, "vtable", vtable);
if (directormap != 0) {
Setattr(directormap, classtype, n);
}
classDirectorInit(n);
classDirectorConstructors(n);
classDirectorMethods(n);
File *f_directors_h = Swig_filebyname("director_h");
Printv(f_directors_h, using_protected_members_code, NIL);
classDirectorEnd(n);
}
Delete(vtable);
Delete(using_protected_members_code);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classDeclaration()
* ---------------------------------------------------------------------- */
static void addCopyConstructor(Node *n) {
Node *cn = NewHash();
set_nodeType(cn, "constructor");
Setattr(cn, "access", "public");
Setfile(cn, Getfile(n));
Setline(cn, Getline(n));
String *cname = Getattr(n, "name");
SwigType *type = Copy(cname);
String *name = Swig_scopename_last(cname);
String *cc = NewStringf("r.q(const).%s", type);
String *decl = NewStringf("f(%s).", cc);
String *oldname = Getattr(n, "sym:name");
if (Getattr(n, "allocate:has_constructor")) {
// to work properly with '%rename Class', we must look
// for any other constructor in the class, which has not been
// renamed, and use its name as oldname.
Node *c;
for (c = firstChild(n); c; c = nextSibling(c)) {
const char *tag = Char(nodeType(c));
if (strcmp(tag, "constructor") == 0) {
String *cname = Getattr(c, "name");
String *csname = Getattr(c, "sym:name");
String *clast = Swig_scopename_last(cname);
if (Equal(csname, clast)) {
oldname = csname;
break;
}
}
}
}
String *symname = Swig_name_make(cn, cname, name, decl, oldname);
if (Strcmp(symname, "$ignore") != 0) {
Parm *p = NewParm(cc, "other", n);
Setattr(cn, "name", name);
Setattr(cn, "sym:name", symname);
SetFlag(cn, "feature:new");
Setattr(cn, "decl", decl);
Setattr(cn, "parentNode", n);
Setattr(cn, "parms", p);
Setattr(cn, "copy_constructor", "1");
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
if (on == cn) {
Node *access = NewHash();
set_nodeType(access, "access");
Setattr(access, "kind", "public");
appendChild(n, access);
appendChild(n, cn);
Setattr(n, "has_copy_constructor", "1");
Setattr(n, "copy_constructor_decl", decl);
Setattr(n, "allocate:copy_constructor", "1");
Delete(access);
}
}
Delete(cn);
Delete(name);
Delete(decl);
Delete(symname);
}
static void addDefaultConstructor(Node *n) {
Node *cn = NewHash();
set_nodeType(cn, "constructor");
Setattr(cn, "access", "public");
Setfile(cn, Getfile(n));
Setline(cn, Getline(n));
String *cname = Getattr(n, "name");
String *name = Swig_scopename_last(cname);
String *decl = NewString("f().");
String *oldname = Getattr(n, "sym:name");
String *symname = Swig_name_make(cn, cname, name, decl, oldname);
if (Strcmp(symname, "$ignore") != 0) {
Setattr(cn, "name", name);
Setattr(cn, "sym:name", symname);
SetFlag(cn, "feature:new");
Setattr(cn, "decl", decl);
Setattr(cn, "parentNode", n);
Setattr(cn, "default_constructor", "1");
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
if (on == cn) {
Node *access = NewHash();
set_nodeType(access, "access");
Setattr(access, "kind", "public");
appendChild(n, access);
appendChild(n, cn);
Setattr(n, "has_default_constructor", "1");
Setattr(n, "allocate:default_constructor", "1");
Delete(access);
}
}
Delete(cn);
Delete(name);
Delete(decl);
Delete(symname);
}
static void addDestructor(Node *n) {
Node *cn = NewHash();
set_nodeType(cn, "destructor");
Setattr(cn, "access", "public");
Setfile(cn, Getfile(n));
Setline(cn, Getline(n));
String *cname = Getattr(n, "name");
String *name = Swig_scopename_last(cname);
Insert(name, 0, "~");
String *decl = NewString("f().");
String *symname = Swig_name_make(cn, cname, name, decl, 0);
if (Strcmp(symname, "$ignore") != 0) {
String *possible_nonstandard_symname = NewStringf("~%s", Getattr(n, "sym:name"));
Setattr(cn, "name", name);
Setattr(cn, "sym:name", symname);
Setattr(cn, "decl", "f().");
Setattr(cn, "parentNode", n);
Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
Node *nonstandard_destructor = Equal(possible_nonstandard_symname, symname) ? 0 : Swig_symbol_clookup(possible_nonstandard_symname, 0);
Node *on = Swig_symbol_add(symname, cn);
Swig_features_get(Swig_cparse_features(), Swig_symbol_qualifiedscopename(0), name, decl, cn);
Swig_symbol_setscope(oldscope);
if (on == cn) {
// SWIG accepts a non-standard named destructor in %extend that uses a typedef for the destructor name
// For example: typedef struct X {} XX; %extend X { ~XX() {...} }
// Don't add another destructor if a nonstandard one has been declared
if (!nonstandard_destructor) {
Node *access = NewHash();
set_nodeType(access, "access");
Setattr(access, "kind", "public");
appendChild(n, access);
appendChild(n, cn);
Setattr(n, "has_destructor", "1");
Setattr(n, "allocate:destructor", "1");
Delete(access);
}
}
Delete(possible_nonstandard_symname);
}
Delete(cn);
Delete(name);
Delete(decl);
Delete(symname);
}
int Language::classDeclaration(Node *n) {
String *ochildren = Getattr(n, "feature:onlychildren");
if (ochildren) {
Setattr(n, "feature:emitonlychildren", ochildren);
emit_children(n);
Delattr(n, "feature:emitonlychildren");
SetFlag(n, "feature:ignore");
return SWIG_NOWRAP;
}
// save class local variables for nested classes support
int oldInClass = InClass;
String *oldClassType = ClassType;
String *oldClassPrefix = ClassPrefix;
String *oldEnumClassPrefix = EnumClassPrefix;
String *oldClassName = ClassName;
String *oldDirectorClassName = DirectorClassName;
String *oldNSpace = NSpace;
Node *oldCurrentClass = CurrentClass;
int dir = 0;
String *kind = Getattr(n, "kind");
String *name = Getattr(n, "name");
String *tdname = Getattr(n, "tdname");
String *unnamed = Getattr(n, "unnamed");
String *symname = Getattr(n, "sym:name");
int strip = CPlusPlus ? 1 : unnamed && tdname;
if (cplus_mode != PUBLIC)
return SWIG_NOWRAP;
if (!name) {
Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n");
return SWIG_NOWRAP;
}
/* Check symbol name for template. If not renamed. Issue a warning */
if (!validIdentifier(symname)) {
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", SwigType_namestr(symname));
return SWIG_NOWRAP;
}
AccessMode oldAccessMode = cplus_mode;
Node *outerClass = Getattr(n, "nested:outer");
if (outerClass && oldAccessMode != PUBLIC)
return SWIG_NOWRAP;
ClassName = Copy(name);
ClassPrefix = Copy(symname);
if (Cmp(kind, "class") == 0) {
cplus_mode = PRIVATE;
} else {
cplus_mode = PUBLIC;
}
for (; outerClass; outerClass = Getattr(outerClass, "nested:outer")) {
Push(ClassPrefix, "_");
Push(ClassPrefix, Getattr(outerClass, "sym:name"));
}
EnumClassPrefix = Copy(ClassPrefix);
if (strip) {
ClassType = Copy(name);
} else {
ClassType = NewStringf("%s %s", kind, name);
}
Setattr(n, "classtypeobj", Copy(ClassType));
Setattr(n, "classtype", SwigType_namestr(ClassType));
InClass = 1;
CurrentClass = n;
NSpace = Getattr(n, "sym:nspace");
int oldAbstract = Abstract;
/* Call classHandler() here */
if (!ImportMode) {
if (directorsEnabled()) {
int ndir = GetFlag(n, "feature:director");
int nndir = GetFlag(n, "feature:nodirector");
/* 'nodirector' has precedence over 'director' */
dir = (ndir || nndir) ? (ndir && !nndir) : 0;
}
int abstract = !dir && abstractClassTest(n);
int odefault = (GenerateDefault && !GetFlag(n, "feature:nodefault"));
/* default constructor */
if (!abstract && !GetFlag(n, "feature:nodefaultctor") && odefault) {
if (!Getattr(n, "has_constructor") && !Getattr(n, "allocate:has_constructor") && (Getattr(n, "allocate:default_constructor"))) {
addDefaultConstructor(n);
}
}
/* copy constructor */
if (CPlusPlus && !abstract && GetFlag(n, "feature:copyctor")) {
if (!Getattr(n, "has_copy_constructor") && !Getattr(n, "allocate:has_copy_constructor")
&& (Getattr(n, "allocate:copy_constructor"))
&& (!GetFlag(n, "feature:ignore"))) {
addCopyConstructor(n);
}
}
/* default destructor */
if (!GetFlag(n, "feature:nodefaultdtor") && odefault) {
if (!Getattr(n, "has_destructor") && (!Getattr(n, "allocate:has_destructor"))
&& (Getattr(n, "allocate:default_destructor"))
&& (!GetFlag(n, "feature:ignore"))) {
addDestructor(n);
}
}
if (dir) {
DirectorClassName = directorClassName(n);
classDirector(n);
}
/* check for abstract after resolving directors */
Abstract = abstractClassTest(n);
classHandler(n);
} else {
Abstract = abstractClassTest(n);
Language::classHandler(n);
}
Abstract = oldAbstract;
cplus_mode = oldAccessMode;
NSpace = oldNSpace;
InClass = oldInClass;
CurrentClass = oldCurrentClass;
Delete(ClassType);
ClassType = oldClassType;
Delete(EnumClassPrefix);
EnumClassPrefix = oldEnumClassPrefix;
Delete(ClassPrefix);
ClassPrefix = oldClassPrefix;
Delete(ClassName);
ClassName = oldClassName;
if (dir) {
Delete(DirectorClassName);
}
DirectorClassName = oldDirectorClassName;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classHandler()
* ---------------------------------------------------------------------- */
int Language::classHandler(Node *n) {
save_value<int> oldExtend(Extend);
if (Getattr(n, "template"))
Extend = 0;
bool hasDirector = Swig_directorclass(n) ? true : false;
/* Emit all of the class members */
emit_children(n);
/* Look for smart pointer handling */
if (Getattr(n, "allocate:smartpointer")) {
List *methods = Getattr(n, "allocate:smartpointer");
cplus_mode = PUBLIC;
SmartPointer = CWRAP_SMART_POINTER;
if (Getattr(n, "allocate:smartpointerconst") && Getattr(n, "allocate:smartpointermutable")) {
SmartPointer |= CWRAP_SMART_POINTER_OVERLOAD;
}
Iterator c;
for (c = First(methods); c.item; c = Next(c)) {
emit_one(c.item);
}
SmartPointer = 0;
}
cplus_mode = PUBLIC;
/* emit director disown method */
if (hasDirector) {
classDirectorDisown(n);
/* Emit additional protected virtual methods - only needed if the language module
* codes logic in the C++ layer instead of the director proxy class method - primarily
* to catch public use of protected methods by the scripting languages. */
if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) {
Node *vtable = Getattr(n, "vtable");
String *symname = Getattr(n, "sym:name");
save_value<AccessMode> old_mode(cplus_mode);
cplus_mode = PROTECTED;
int len = Len(vtable);
for (int i = 0; i < len; i++) {
Node *item = Getitem(vtable, i);
Node *method = Getattr(item, "methodNode");
SwigType *type = Getattr(method, "nodeType");
if (Strcmp(type, "cdecl") != 0)
continue;
if (GetFlag(method, "feature:ignore"))
continue;
String *methodname = Getattr(method, "sym:name");
String *wrapname = NewStringf("%s_%s", symname, methodname);
if (!symbolLookup(wrapname, "") && (!is_public(method))) {
Node *m = Copy(method);
Setattr(m, "director", "1");
Setattr(m, "parentNode", n);
/*
* There is a bug that needs fixing still...
* This area of code is creating methods which have not been overridden in a derived class (director methods that are protected in the base)
* If the method is overloaded, then Swig_overload_dispatch() incorrectly generates a call to the base wrapper, _wrap_xxx method
* See director_protected_overloaded.i - Possibly sym:overname needs correcting here.
Printf(stdout, "new method: %s::%s(%s)\n", Getattr(parentNode(m), "name"), Getattr(m, "name"), ParmList_str_defaultargs(Getattr(m, "parms")));
*/
cDeclaration(m);
Delete(m);
}
Delete(wrapname);
}
}
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::classforwardDeclaration()
* ---------------------------------------------------------------------- */
int Language::classforwardDeclaration(Node *n) {
(void) n;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::constructorDeclaration()
* ---------------------------------------------------------------------- */
int Language::constructorDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
if (!symname)
return SWIG_NOWRAP;
if (!CurrentClass)
return SWIG_NOWRAP;
if (ImportMode)
return SWIG_NOWRAP;
if (Extend) {
/* extend default constructor can be safely ignored if there is already one */
int num_required = ParmList_numrequired(Getattr(n, "parms"));
if ((num_required == 0) && Getattr(CurrentClass, "has_default_constructor")) {
return SWIG_NOWRAP;
}
if ((num_required == 1) && Getattr(CurrentClass, "has_copy_constructor")) {
String *ccdecl = Getattr(CurrentClass, "copy_constructor_decl");
if (ccdecl && (Strcmp(ccdecl, Getattr(n, "decl")) == 0)) {
return SWIG_NOWRAP;
}
}
}
/* clean protected overloaded constructors, in case they are not needed anymore */
Node *over = Swig_symbol_isoverloaded(n);
if (over && !Getattr(CurrentClass, "sym:cleanconstructor")) {
int dirclass = Swig_directorclass(CurrentClass);
Node *nn = over;
while (nn) {
if (!is_public(nn)) {
if (!dirclass || !need_nonpublic_ctor(nn)) {
SetFlag(nn, "feature:ignore");
}
}
nn = Getattr(nn, "sym:nextSibling");
}
clean_overloaded(over);
Setattr(CurrentClass, "sym:cleanconstructor", "1");
}
if ((cplus_mode != PUBLIC)) {
/* check only for director classes */
if (!Swig_directorclass(CurrentClass) || !need_nonpublic_ctor(n))
return SWIG_NOWRAP;
}
/* Name adjustment for %name */
Swig_save("constructorDeclaration", n, "sym:name", NIL);
{
String *base = Swig_scopename_last(name);
if ((Strcmp(base, symname) == 0) && (Strcmp(symname, ClassPrefix) != 0)) {
Setattr(n, "sym:name", ClassPrefix);
}
Delete(base);
}
/* Only create a constructor if the class is not abstract */
if (!Abstract) {
Node *over;
over = Swig_symbol_isoverloaded(n);
if (over)
over = first_nontemplate(over);
if ((over) && (!overloading)) {
/* If the symbol is overloaded. We check to see if it is a copy constructor. If so,
we invoke copyconstructorHandler() as a special case. */
if (Getattr(n, "copy_constructor") && (!Getattr(CurrentClass, "has_copy_constructor"))) {
copyconstructorHandler(n);
Setattr(CurrentClass, "has_copy_constructor", "1");
} else {
if (Getattr(over, "copy_constructor"))
over = Getattr(over, "sym:nextSibling");
if (over != n) {
Swig_warning(WARN_LANG_OVERLOAD_CONSTRUCT, input_file, line_number,
"Overloaded constructor ignored. %s\n", Swig_name_decl(n));
Swig_warning(WARN_LANG_OVERLOAD_CONSTRUCT, Getfile(over), Getline(over),
"Previous declaration is %s\n", Swig_name_decl(over));
} else {
constructorHandler(n);
}
}
} else {
String *expected_name = ClassName;
String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0;
String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name);
Delete(scope);
if (!Equal(actual_name, expected_name) && !SwigType_istemplate(expected_name) && !SwigType_istemplate(actual_name)) {
// Checking templates is skipped but they ought to be checked... they are just somewhat more tricky to check correctly
bool illegal_name = true;
if (Extend) {
// Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_CONSTRUCTOR, input_file, line_number, "Use of an illegal constructor name '%s' in %%extend is deprecated, the constructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
if (illegal_name) {
Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", Swig_name_decl(n));
Swig_restore(n);
return SWIG_NOWRAP;
}
}
constructorHandler(n);
}
}
Setattr(CurrentClass, "has_constructor", "1");
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* get_director_ctor_code()
* ---------------------------------------------------------------------- */
static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstracts) {
String *director_ctor = director_ctor_code;
int use_director = Swig_directorclass(n);
if (use_director) {
Node *pn = Swig_methodclass(n);
abstracts = Getattr(pn, "abstracts");
if (director_prot_ctor_code) {
int is_notabstract = GetFlag(pn, "feature:notabstract");
int is_abstract = abstracts && !is_notabstract;
if (is_protected(n) || is_abstract) {
director_ctor = director_prot_ctor_code;
abstracts = Copy(abstracts);
Delattr(pn, "abstracts");
} else {
if (is_notabstract) {
abstracts = Copy(abstracts);
Delattr(pn, "abstracts");
} else {
abstracts = 0;
}
}
}
}
return director_ctor;
}
/* ----------------------------------------------------------------------
* Language::constructorHandler()
* ---------------------------------------------------------------------- */
int Language::constructorHandler(Node *n) {
Swig_require("constructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL);
String *symname = Getattr(n, "sym:name");
String *mrename = Swig_name_construct(NSpace, symname);
String *nodeType = Getattr(n, "nodeType");
int constructor = (!Cmp(nodeType, "constructor"));
List *abstracts = 0;
String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code,
abstracts);
if (!constructor) {
/* if not originally a constructor, still handle it as one */
Setattr(n, "handled_as_constructor", "1");
}
int extendmember = GetFlag(n, "isextendmember") ? Extend : 0;
int flags = Getattr(n, "template") ? extendmember : Extend;
Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, flags, DirectorClassName);
Setattr(n, "sym:name", mrename);
functionWrapper(n);
Delete(mrename);
Swig_restore(n);
if (abstracts)
Setattr(Swig_methodclass(n), "abstracts", abstracts);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::copyconstructorHandler()
* ---------------------------------------------------------------------- */
int Language::copyconstructorHandler(Node *n) {
Swig_require("copyconstructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL);
String *symname = Getattr(n, "sym:name");
String *mrename = Swig_name_copyconstructor(NSpace, symname);
List *abstracts = 0;
String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code,
abstracts);
Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend, DirectorClassName);
Setattr(n, "sym:name", mrename);
functionWrapper(n);
Delete(mrename);
Swig_restore(n);
if (abstracts)
Setattr(Swig_methodclass(n), "abstracts", abstracts);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::destructorDeclaration()
* ---------------------------------------------------------------------- */
int Language::destructorDeclaration(Node *n) {
if (!CurrentClass)
return SWIG_NOWRAP;
if (cplus_mode != PUBLIC && !Getattr(CurrentClass, "feature:unref"))
return SWIG_NOWRAP;
if (ImportMode)
return SWIG_NOWRAP;
Swig_save("destructorDeclaration", n, "name", "sym:name", NIL);
char *c = GetChar(n, "sym:name");
if (c && (*c == '~')) {
Setattr(n, "sym:name", c + 1);
}
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
if ((Strcmp(name, symname) == 0) || (Strcmp(symname, ClassPrefix) != 0)) {
Setattr(n, "sym:name", ClassPrefix);
}
String *expected_name = ClassName;
String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0;
String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name);
Delete(scope);
Replace(actual_name, "~", "", DOH_REPLACE_FIRST);
if (!Equal(actual_name, expected_name) && !(Getattr(n, "template"))) {
bool illegal_name = true;
if (Extend) {
// Check for typedef names used as a destructor name in %extend. This is deprecated except for anonymous
// typedef structs which have had their symbol names adjusted to the typedef name in the parser.
SwigType *name_resolved = SwigType_typedef_resolve_all(actual_name);
SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name);
if (!CPlusPlus) {
if (Strncmp(name_resolved, "struct ", 7) == 0)
Replace(name_resolved, "struct ", "", DOH_REPLACE_FIRST);
else if (Strncmp(name_resolved, "union ", 6) == 0)
Replace(name_resolved, "union ", "", DOH_REPLACE_FIRST);
}
illegal_name = !Equal(name_resolved, expected_name_resolved);
if (!illegal_name)
Swig_warning(WARN_LANG_EXTEND_DESTRUCTOR, input_file, line_number, "Use of an illegal destructor name '%s' in %%extend is deprecated, the destructor name should be '%s'.\n",
SwigType_str(Swig_scopename_last(actual_name), 0), SwigType_str(Swig_scopename_last(expected_name), 0));
Delete(name_resolved);
Delete(expected_name_resolved);
}
if (illegal_name) {
Swig_warning(WARN_LANG_ILLEGAL_DESTRUCTOR, input_file, line_number, "Illegal destructor name %s. Ignored.\n", Swig_name_decl(n));
Swig_restore(n);
return SWIG_NOWRAP;
}
}
destructorHandler(n);
Setattr(CurrentClass, "has_destructor", "1");
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::destructorHandler()
* ---------------------------------------------------------------------- */
int Language::destructorHandler(Node *n) {
Swig_require("destructorHandler", n, "?name", "*sym:name", NIL);
Swig_save("destructorHandler", n, "type", "parms", NIL);
String *symname = Getattr(n, "sym:name");
String *mrename;
char *csymname = Char(symname);
if (*csymname == '~')
csymname += 1;
mrename = Swig_name_destroy(NSpace, csymname);
Swig_DestructorToFunction(n, NSpace, ClassType, CPlusPlus, Extend);
Setattr(n, "sym:name", mrename);
functionWrapper(n);
Delete(mrename);
Swig_restore(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::accessDeclaration()
* ---------------------------------------------------------------------- */
int Language::accessDeclaration(Node *n) {
String *kind = Getattr(n, "kind");
if (Cmp(kind, "public") == 0) {
cplus_mode = PUBLIC;
} else if (Cmp(kind, "private") == 0) {
cplus_mode = PRIVATE;
} else if (Cmp(kind, "protected") == 0) {
cplus_mode = PROTECTED;
}
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Language::namespaceDeclaration()
* ----------------------------------------------------------------------------- */
int Language::namespaceDeclaration(Node *n) {
if (Getattr(n, "alias"))
return SWIG_OK;
if (Getattr(n, "unnamed"))
return SWIG_OK;
emit_children(n);
return SWIG_OK;
}
int Language::validIdentifier(String *s) {
char *c = Char(s);
while (*c) {
if (!(isalnum(*c) || (*c == '_')))
return 0;
c++;
}
return 1;
}
/* -----------------------------------------------------------------------------
* Language::usingDeclaration()
* ----------------------------------------------------------------------------- */
int Language::usingDeclaration(Node *n) {
if ((cplus_mode == PUBLIC) || (!is_public(n) && dirprot_mode())) {
Node *np = Copy(n);
Node *c;
for (c = firstChild(np); c; c = nextSibling(c)) {
/* it seems for some cases this is needed, like A* A::boo() */
if (CurrentClass)
Setattr(c, "parentNode", CurrentClass);
emit_one(c);
}
Delete(np);
}
return SWIG_OK;
}
/* Stubs. Language modules need to implement these */
/* ----------------------------------------------------------------------
* Language::constantWrapper()
* ---------------------------------------------------------------------- */
int Language::constantWrapper(Node *n) {
String *name = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
String *str = SwigType_str(type, name);
Printf(stdout, "constantWrapper : %s = %s\n", str, value);
Delete(str);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::variableWrapper()
* ---------------------------------------------------------------------- */
int Language::variableWrapper(Node *n) {
Swig_require("variableWrapper", n, "*name", "*sym:name", "*type", "?parms", "?varset", "?varget", NIL);
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *name = Getattr(n, "name");
Delattr(n,"varset");
Delattr(n,"varget");
String *newsymname = 0;
if (!CurrentClass && EnumClassPrefix) {
newsymname = Swig_name_member(0, EnumClassPrefix, symname);
symname = newsymname;
}
/* If no way to set variables. We simply create functions */
int assignable = is_assignable(n);
int flags = use_naturalvar_mode(n);
if (!GetFlag(n, "wrappedasconstant"))
flags = flags | Extend;
if (assignable) {
int make_set_wrapper = 1;
String *tm = Swig_typemap_lookup("globalin", n, name, 0);
Swig_VarsetToFunction(n, flags);
String *sname = Swig_name_set(NSpace, symname);
Setattr(n, "sym:name", sname);
Delete(sname);
if (!tm) {
if (SwigType_isarray(type)) {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
make_set_wrapper = 0;
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
Replace(tm, "$source", pname0, DOH_REPLACE_ANY);
Replace(tm, "$target", name, DOH_REPLACE_ANY);
Replace(tm, "$input", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);
Delete(pname0);
}
if (make_set_wrapper) {
Setattr(n, "varset", "1");
functionWrapper(n);
} else {
SetFlag(n, "feature:immutable");
}
/* Restore parameters */
Setattr(n, "sym:name", symname);
Setattr(n, "type", type);
Setattr(n, "name", name);
Delattr(n, "varset");
/* Delete all attached typemaps and typemap attributes */
Iterator ki;
for (ki = First(n); ki.key; ki = Next(ki)) {
if (Strncmp(ki.key, "tmap:", 5) == 0)
Delattr(n, ki.key);
}
}
Swig_VargetToFunction(n, flags);
String *gname = Swig_name_get(NSpace, symname);
Setattr(n, "sym:name", gname);
Delete(gname);
Setattr(n, "varget", "1");
functionWrapper(n);
Delattr(n, "varget");
Swig_restore(n);
Delete(newsymname);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::functionWrapper()
* ---------------------------------------------------------------------- */
int Language::functionWrapper(Node *n) {
String *name = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
Printf(stdout, "functionWrapper : %s\n", SwigType_str(type, NewStringf("%s(%s)", name, ParmList_str_defaultargs(parms))));
Printf(stdout, " action : %s\n", Getattr(n, "wrap:action"));
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Language::nativeWrapper()
* ----------------------------------------------------------------------------- */
int Language::nativeWrapper(Node *n) {
(void) n;
return SWIG_OK;
}
void Language::main(int argc, char *argv[]) {
(void) argc;
(void) argv;
}
/* -----------------------------------------------------------------------------
* Language::addSymbol()
*
* Adds a symbol entry into the target language symbol tables.
* Returns 1 if the symbol is added successfully.
* Prints an error message and returns 0 if a conflict occurs.
* The scope is optional for target languages and if supplied must be a fully
* qualified scope and the symbol s must not contain any scope qualifiers.
* ----------------------------------------------------------------------------- */
int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
//Printf( stdout, "addSymbol: %s %s\n", s, scope );
Hash *symbols = Getattr(symtabs, scope ? scope : "");
if (!symbols) {
symbols = symbolAddScope(scope);
} else {
Node *c = Getattr(symbols, s);
if (c && (c != n)) {
if (scope && Len(scope) > 0)
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module in scope '%s'.\n", s, scope);
else
Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module.\n", s);
Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s);
return 0;
}
}
Setattr(symbols, s, n);
return 1;
}
/* -----------------------------------------------------------------------------
* Language::addInterfaceSymbol()
*
* Adds a symbol entry into the target language symbol tables - for the interface
* feature only.
* Returns 1 if the symbol is added successfully.
* The scope is as per addSymbol.
* ----------------------------------------------------------------------------- */
int Language::addInterfaceSymbol(const String *interface_name, Node *n, const_String_or_char_ptr scope) {
if (interface_name) {
Node *existing_symbol = symbolLookup(interface_name, scope);
if (existing_symbol) {
String *proxy_class_name = Getattr(n, "sym:name");
Swig_error(input_file, line_number, "The interface feature name '%s' for proxy class '%s' is already defined in the generated target language module in scope '%s'.\n",
interface_name, proxy_class_name, scope);
Swig_error(Getfile(existing_symbol), Getline(existing_symbol), "Previous declaration of '%s'\n", interface_name);
return 0;
}
if (!addSymbol(interface_name, n, scope))
return 0;
}
return 1;
}
/* -----------------------------------------------------------------------------
* Language::symbolAddScope()
*
* Creates a scope (symbols Hash) for given name. This method is auxiliary,
* you don't have to call it - addSymbols will lazily create scopes automatically.
* If scope with given name already exists, then do nothing.
* Returns newly created (or already existing) scope.
* ----------------------------------------------------------------------------- */
Hash* Language::symbolAddScope(const_String_or_char_ptr scope) {
Hash *symbols = symbolScopeLookup(scope);
if(!symbols) {
// The order in which the following code is executed is important. In the Language
// constructor addScope("") is called to create a top level scope.
// Thus we must first add a symbols hash to symtab and only then add pseudo
// symbols to the top-level scope.
// New scope which has not been added by the target language - lazily created.
symbols = NewHash();
Setattr(symtabs, scope, symbols);
// Add the new scope as a symbol in the top level scope.
// Alternatively the target language must add it in before attempting to add symbols into the scope.
const_String_or_char_ptr top_scope = "";
Hash *topscope_symbols = Getattr(symtabs, top_scope);
Hash *pseudo_symbol = NewHash();
Setattr(pseudo_symbol, "sym:scope", "1");
Setattr(topscope_symbols, scope, pseudo_symbol);
}
return symbols;
}
/* -----------------------------------------------------------------------------
* Language::symbolScopeLookup()
*
* Lookup and returns a symtable (hash) representing given scope. Hash contains
* all symbols in this scope.
* ----------------------------------------------------------------------------- */
Hash* Language::symbolScopeLookup( const_String_or_char_ptr scope ) {
Hash *symbols = Getattr(symtabs, scope ? scope : "");
return symbols;
}
/* -----------------------------------------------------------------------------
* Language::symbolScopePseudoSymbolLookup()
*
* For every scope there is a special pseudo-symbol in the top scope (""). It
* exists solely to detect name clashes. This pseudo symbol may contain a few properties,
* but more could be added. This is also true for the top level scope ("").
* It contains a pseudo symbol with name "" (empty). Pseudo symbol contains the
* following properties:
* sym:scope = "1" - a flag that this is a scope pseudo symbol
*
* Pseudo symbols are a Hash*, not a Node*.
* There is no difference from symbolLookup() method except for signature
* and return type.
* ----------------------------------------------------------------------------- */
Hash* Language::symbolScopePseudoSymbolLookup( const_String_or_char_ptr scope )
{
/* Getting top scope */
const_String_or_char_ptr top_scope = "";
Hash *symbols = Getattr(symtabs, top_scope);
return Getattr(symbols, scope);
}
/* -----------------------------------------------------------------------------
* Language::dumpSymbols()
* ----------------------------------------------------------------------------- */
void Language::dumpSymbols() {
Printf(stdout, "LANGUAGE SYMBOLS start =======================================\n");
Node *table = symtabs;
Iterator ki = First(table);
while (ki.key) {
String *k = ki.key;
Printf(stdout, "===================================================\n");
Printf(stdout, "%s -\n", k);
{
Symtab *symtab = Getattr(table, k);
Iterator it = First(symtab);
while (it.key) {
String *symname = it.key;
Printf(stdout, " %s\n", symname);
it = Next(it);
}
}
ki = Next(ki);
}
Printf(stdout, "LANGUAGE SYMBOLS finish =======================================\n");
}
/* -----------------------------------------------------------------------------
* Language::symbolLookup()
* ----------------------------------------------------------------------------- */
Node *Language::symbolLookup(const String *s, const_String_or_char_ptr scope) {
Hash *symbols = Getattr(symtabs, scope ? scope : "");
if (!symbols) {
return NULL;
}
return Getattr(symbols, s);
}
/* -----------------------------------------------------------------------------
* Language::classLookup()
*
* Tries to locate a class from a type definition
* ----------------------------------------------------------------------------- */
Node *Language::classLookup(const SwigType *s) const {
Node *n = 0;
/* Look in hash of cached values */
n = Getattr(classtypes, s);
if (!n) {
Symtab *stab = 0;
SwigType *ty1 = SwigType_typedef_resolve_all(s);
SwigType *ty2 = SwigType_strip_qualifiers(ty1);
String *base = SwigType_base(ty2);
Replaceall(base, "class ", "");
Replaceall(base, "struct ", "");
Replaceall(base, "union ", "");
if (strncmp(Char(base), "::", 2) == 0) {
String *oldbase = base;
base = NewString(Char(base) + 2);
Delete(oldbase);
}
String *prefix = SwigType_prefix(ty2);
/* Do a symbol table search on the base type */
while (!n) {
Hash *nstab;
n = Swig_symbol_clookup(base, stab);
if (!n)
break;
if (Strcmp(nodeType(n), "class") == 0)
break;
n = parentNode(n);
if (!n)
break;
nstab = Getattr(n, "sym:symtab");
n = 0;
if ((!nstab) || (nstab == stab)) {
break;
}
stab = nstab;
}
if (n) {
/* Found a match. Look at the prefix. We only allow
the cases where where we want a proxy class for the particular type */
bool acceptable_prefix =
(Len(prefix) == 0) || // simple type (pass by value)
(Strcmp(prefix, "p.") == 0) || // pointer
(Strcmp(prefix, "r.") == 0) || // reference
(Strcmp(prefix, "z.") == 0) || // rvalue reference
SwigType_prefix_is_simple_1D_array(prefix); // Simple 1D array (not arrays of pointers/references)
// Also accept pointer by const reference, not non-const pointer reference
if (!acceptable_prefix && (Strcmp(prefix, "r.p.") == 0)) {
Delete(prefix);
prefix = SwigType_prefix(ty1);
acceptable_prefix = (Strncmp(prefix, "r.q(const", 9) == 0);
}
if (acceptable_prefix) {
SwigType *cs = Copy(s);
Setattr(classtypes, cs, n);
Delete(cs);
} else {
n = 0;
}
}
Delete(prefix);
Delete(base);
Delete(ty2);
Delete(ty1);
}
if (n && (GetFlag(n, "feature:ignore") || Getattr(n, "feature:onlychildren"))) {
n = 0;
}
return n;
}
/* -----------------------------------------------------------------------------
* Language::enumLookup()
*
* Finds and returns the Node containing the enum declaration for the (enum)
* type passed in.
* ----------------------------------------------------------------------------- */
Node *Language::enumLookup(SwigType *s) {
Node *n = 0;
/* Look in hash of cached values */
n = Getattr(enumtypes, s);
if (!n) {
Symtab *stab = 0;
SwigType *lt = SwigType_ltype(s);
SwigType *ty1 = SwigType_typedef_resolve_all(lt);
SwigType *ty2 = SwigType_strip_qualifiers(ty1);
String *base = SwigType_base(ty2);
Replaceall(base, "enum ", "");
String *prefix = SwigType_prefix(ty2);
if (strncmp(Char(base), "::", 2) == 0) {
String *oldbase = base;
base = NewString(Char(base) + 2);
Delete(oldbase);
}
/* Look for type in symbol table */
while (!n) {
Hash *nstab;
n = Swig_symbol_clookup(base, stab);
if (!n)
break;
if (Equal(nodeType(n), "enum"))
break;
if (Equal(nodeType(n), "enumforward") && GetFlag(n, "enumMissing"))
break;
n = parentNode(n);
if (!n)
break;
nstab = Getattr(n, "sym:symtab");
n = 0;
if ((!nstab) || (nstab == stab)) {
break;
}
stab = nstab;
}
if (n) {
/* Found a match. Look at the prefix. We only allow simple types. */
if (Len(prefix) == 0) { /* Simple type */
Setattr(enumtypes, Copy(s), n);
} else {
n = 0;
}
}
Delete(prefix);
Delete(base);
Delete(ty2);
Delete(ty1);
Delete(lt);
}
if (n && (GetFlag(n, "feature:ignore"))) {
n = 0;
}
return n;
}
/* -----------------------------------------------------------------------------
* Language::allow_overloading()
* ----------------------------------------------------------------------------- */
void Language::allow_overloading(int val) {
overloading = val;
}
/* -----------------------------------------------------------------------------
* Language::allow_multiple_input()
* ----------------------------------------------------------------------------- */
void Language::allow_multiple_input(int val) {
multiinput = val;
}
/* -----------------------------------------------------------------------------
* Language::enable_cplus_runtime_mode()
* ----------------------------------------------------------------------------- */
void Language::enable_cplus_runtime_mode() {
cplus_runtime = 1;
}
/* -----------------------------------------------------------------------------
* Language::cplus_runtime_mode()
* ----------------------------------------------------------------------------- */
int Language::cplus_runtime_mode() {
return cplus_runtime;
}
/* -----------------------------------------------------------------------------
* Language::allow_directors()
* ----------------------------------------------------------------------------- */
void Language::allow_directors(int val) {
directors = val;
}
/* -----------------------------------------------------------------------------
* Language::directorsEnabled()
* ----------------------------------------------------------------------------- */
int Language::directorsEnabled() const {
return director_language && CPlusPlus && (directors || director_mode);
}
/* -----------------------------------------------------------------------------
* Language::allow_dirprot()
* ----------------------------------------------------------------------------- */
void Language::allow_dirprot(int val) {
director_protected_mode = val;
}
/* -----------------------------------------------------------------------------
* Language::allow_allprotected()
* ----------------------------------------------------------------------------- */
void Language::allow_allprotected(int val) {
all_protected_mode = val;
}
/* -----------------------------------------------------------------------------
* Language::dirprot_mode()
* ----------------------------------------------------------------------------- */
int Language::dirprot_mode() const {
return directorsEnabled() ? director_protected_mode : 0;
}
/* -----------------------------------------------------------------------------
* Language::need_nonpublic_ctor()
* ----------------------------------------------------------------------------- */
int Language::need_nonpublic_ctor(Node *n) {
/*
detects when a protected constructor is needed, which is always
the case if 'dirprot' mode is used. However, if that is not the
case, we will try to strictly emit what is minimal to don't break
the generated, while preserving compatibility with java, which
always try to emit the default constructor.
rules:
- when dirprot mode is used, the protected constructors are
always needed.
- the protected default constructor is always needed.
- if dirprot mode is not used, the protected constructors will be
needed only if:
- there is no any public constructor in the class, and
- there is no protected default constructor
In that case, all the declared protected constructors are
needed since we don't know which one to pick up.
Note: given all the complications here, I am always in favor to
always enable 'dirprot', since is the C++ idea of protected
members, and use %ignore for the method you don't whan to add in
the director class.
*/
if (directorsEnabled()) {
if (is_protected(n)) {
if (dirprot_mode()) {
/* when using dirprot mode, the protected constructors are
always needed */
return 1;
} else {
int is_default_ctor = !ParmList_numrequired(Getattr(n, "parms"));
if (is_default_ctor) {
/* the default protected constructor is always needed, for java compatibility */
return 1;
} else {
/* check if there is a public constructor */
Node *parent = Swig_methodclass(n);
int public_ctor = Getattr(parent, "allocate:default_constructor")
|| Getattr(parent, "allocate:public_constructor");
if (!public_ctor) {
/* if not, the protected constructor will be needed only
if there is no protected default constructor declared */
int no_prot_default_ctor = !Getattr(parent, "allocate:default_base_constructor");
return no_prot_default_ctor;
}
}
}
}
}
return 0;
}
/* -----------------------------------------------------------------------------
* Language::need_nonpublic_member()
* ----------------------------------------------------------------------------- */
int Language::need_nonpublic_member(Node *n) {
if (directorsEnabled() && DirectorClassName) {
if (is_protected(n)) {
if (dirprot_mode()) {
/* when using dirprot mode, the protected members are always needed. */
return 1;
} else {
/* if the method is pure virtual, we need it. */
int pure_virtual = (Cmp(Getattr(n, "value"), "0") == 0);
return pure_virtual;
}
}
}
return 0;
}
/* -----------------------------------------------------------------------------
* Language::is_smart_pointer()
* ----------------------------------------------------------------------------- */
int Language::is_smart_pointer() const {
return SmartPointer;
}
/* -----------------------------------------------------------------------------
* Language::makeParameterName()
*
* Inputs:
* n - Node
* p - parameter node
* arg_num - parameter argument number
* setter - set this flag when wrapping variables
* Return:
* arg - a unique parameter name
* ----------------------------------------------------------------------------- */
String *Language::makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const {
String *arg = 0;
String *pn = Getattr(p, "name");
// Use C parameter name unless it is a duplicate or an empty parameter name
int count = 0;
ParmList *plist = Getattr(n, "parms");
while (plist) {
if ((Cmp(pn, Getattr(plist, "name")) == 0))
count++;
plist = nextSibling(plist);
}
String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0;
arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn);
if (setter && Cmp(arg, "self") != 0) {
// Some languages (C#) insist on calling the input variable "value" while
// others (D, Java) could, in principle, use something different but this
// would require more work, and so we just use "value" for them too.
// For setters the parameter name sometimes includes C++ scope resolution which needs removing.
Delete(arg);
arg = NewString("value");
}
return arg;
}
/* -----------------------------------------------------------------------------
* Language::()
* ----------------------------------------------------------------------------- */
bool Language::isNonVirtualProtectedAccess(Node *n) const {
// Ideally is_non_virtual_protected_access() would contain all this logic, see
// comments therein about vtable.
return DirectorClassName && is_non_virtual_protected_access(n);
}
/* -----------------------------------------------------------------------------
* Language::extraDirectorProtectedCPPMethodsRequired()
* ----------------------------------------------------------------------------- */
bool Language::extraDirectorProtectedCPPMethodsRequired() const {
return true;
}
/* -----------------------------------------------------------------------------
* Language::nestedClassesSupport()
* ----------------------------------------------------------------------------- */
Language::NestedClassSupport Language::nestedClassesSupport() const {
return NCS_Unknown;
}
/* -----------------------------------------------------------------------------
* Language::kwargsSupport()
* ----------------------------------------------------------------------------- */
bool Language::kwargsSupport() const {
return false;
}
/* -----------------------------------------------------------------------------
* Language::is_wrapping_class()
* ----------------------------------------------------------------------------- */
int Language::is_wrapping_class() const {
return InClass;
}
/* -----------------------------------------------------------------------------
* Language::getCurrentClass()
* ----------------------------------------------------------------------------- */
Node *Language::getCurrentClass() const {
return CurrentClass;
}
/* -----------------------------------------------------------------------------
* Language::getNSpace()
* ----------------------------------------------------------------------------- */
String *Language::getNSpace() const {
return NSpace;
}
/* -----------------------------------------------------------------------------
* Language::getClassName()
* ----------------------------------------------------------------------------- */
String *Language::getClassName() const {
return ClassName;
}
/* -----------------------------------------------------------------------------
* Language::getClassPrefix()
* ----------------------------------------------------------------------------- */
String *Language::getClassPrefix() const {
return ClassPrefix;
}
/* -----------------------------------------------------------------------------
* Language::getEnumClassPrefix()
* ----------------------------------------------------------------------------- */
String *Language::getEnumClassPrefix() const {
return EnumClassPrefix;
}
/* -----------------------------------------------------------------------------
* Language::getClassType()
* ----------------------------------------------------------------------------- */
String *Language::getClassType() const {
return ClassType;
}
/* -----------------------------------------------------------------------------
* Language::abstractClassTest()
* ----------------------------------------------------------------------------- */
//#define SWIG_DEBUG
int Language::abstractClassTest(Node *n) {
/* check for non public operator new */
if (GetFlag(n, "feature:notabstract"))
return 0;
if (Getattr(n, "allocate:nonew"))
return 1;
// A class cannot be instantiated if one of its bases has a private destructor
// Note that if the above does not hold the class can be instantiated if its own destructor is private
List *bases = Getattr(n, "bases");
if (bases) {
for (int i = 0; i < Len(bases); i++) {
Node *b = Getitem(bases, i);
if (GetFlag(b, "allocate:private_destructor"))
return 1;
}
}
/* now check for the rest */
List *abstracts = Getattr(n, "abstracts");
if (!abstracts)
return 0;
int labs = Len(abstracts);
#ifdef SWIG_DEBUG
List *allbases = Getattr(n, "allbases");
Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(allbases));
#endif
if (!labs)
return 0; /*strange, but need to be fixed */
if (abstracts && !directorsEnabled())
return 1;
if (!GetFlag(n, "feature:director"))
return 1;
Node *dirabstract = 0;
Node *vtable = Getattr(n, "vtable");
if (vtable) {
#ifdef SWIG_DEBUG
Printf(stderr, "vtable %s %d %d\n", Getattr(n, "name"), Len(vtable), labs);
#endif
for (int i = 0; i < labs; i++) {
Node *ni = Getitem(abstracts, i);
Node *method_id = vtable_method_id(ni);
if (!method_id)
continue;
bool exists_item = false;
int len = Len(vtable);
for (int i = 0; i < len; i++) {
Node *item = Getitem(vtable, i);
String *check_item = Getattr(item, "vmid");
if (Strcmp(method_id, check_item) == 0) {
exists_item = true;
break;
}
}
#ifdef SWIG_DEBUG
Printf(stderr, "method %s %d\n", method_id, exists_item ? 1 : 0);
#endif
Delete(method_id);
if (!exists_item) {
dirabstract = ni;
break;
}
}
if (dirabstract) {
if (is_public(dirabstract)) {
Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n),
"Director class '%s' is abstract, abstract method '%s' is not accesible, maybe due to multiple inheritance or 'nodirector' feature\n",
SwigType_namestr(Getattr(n, "name")), Getattr(dirabstract, "name"));
} else {
Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n),
"Director class '%s' is abstract, abstract method '%s' is private\n", SwigType_namestr(Getattr(n, "name")), Getattr(dirabstract, "name"));
}
return 1;
}
} else {
return 1;
}
return 0;
}
void Language::setSubclassInstanceCheck(String *nc) {
none_comparison = nc;
}
void Language::setOverloadResolutionTemplates(String *argc, String *argv) {
Delete(argc_template_string);
argc_template_string = Copy(argc);
Delete(argv_template_string);
argv_template_string = Copy(argv);
}
int Language::is_assignable(Node *n) {
if (GetFlag(n, "feature:immutable"))
return 0;
SwigType *type = Getattr(n, "type");
Node *cn = 0;
SwigType *ftd = SwigType_typedef_resolve_all(type);
SwigType *td = SwigType_strip_qualifiers(ftd);
if (SwigType_type(td) == T_USER) {
cn = Swig_symbol_clookup(td, 0);
if (cn) {
if ((Strcmp(nodeType(cn), "class") == 0)) {
if (Getattr(cn, "allocate:noassign")) {
SetFlag(n, "feature:immutable");
Delete(ftd);
Delete(td);
return 0;
}
}
}
}
Delete(ftd);
Delete(td);
return 1;
}
String *Language::runtimeCode() {
return NewString("");
}
String *Language::defaultExternalRuntimeFilename() {
return 0;
}
/* -----------------------------------------------------------------------------
* Language::replaceSpecialVariables()
*
* Language modules should implement this if special variables are to be handled
* correctly in the $typemap(...) special variable macro.
* method - typemap method name
* tm - string containing typemap contents
* parm - a parameter describing the typemap type to be handled
* ----------------------------------------------------------------------------- */
void Language::replaceSpecialVariables(String *method, String *tm, Parm *parm) {
(void)method;
(void)tm;
(void)parm;
}
Language *Language::instance() {
return this_;
}
Hash *Language::getClassHash() const {
return classhash;
}
|