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
|
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* ruby.cxx
*
* Ruby language module for SWIG.
* ----------------------------------------------------------------------------- */
char cvsroot_ruby_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/ruby.cxx,v 1.123 2006/03/06 22:50:58 wsfulton Exp $";
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
#define SWIG_PROTECTED_TARGET_METHODS 1
#include <ctype.h>
#include <string.h>
#include <limits.h> /* for INT_MAX */
class RClass {
private:
String *temp;
public:
String *name; /* class name (renamed) */
String *cname; /* original C class/struct name */
String *mname; /* Mangled name */
/**
* The C variable name used in the SWIG-generated wrapper code to refer to
* this class; usually it is of the form "cClassName.klass", where cClassName
* is a swig_class struct instance and klass is a member of that struct.
*/
String *vname;
/**
* The C variable name used in the SWIG-generated wrapper code to refer to
* the module that implements this class's methods (when we're trying to
* support C++ multiple inheritance). Usually it is of the form
* "cClassName.mImpl", where cClassName is a swig_class struct instance
* and mImpl is a member of that struct.
*/
String *mImpl;
String *type;
String *prefix;
String *init;
int constructor_defined;
int destructor_defined;
RClass() {
temp = NewString("");
name = NewString("");
cname = NewString("");
mname = NewString("");
vname = NewString("");
mImpl = NewString("");
type = NewString("");
prefix = NewString("");
init = NewString("");
constructor_defined = 0;
destructor_defined = 0;
}
~RClass() {
Delete(name);
Delete(cname);
Delete(vname);
Delete(mImpl);
Delete(mname);
Delete(type);
Delete(prefix);
Delete(init);
Delete(temp);
}
void set_name(const String_or_char *cn, const String_or_char *rn, const String_or_char *valn) {
/* Original C/C++ class (or struct) name */
Clear(cname);
Append(cname,cn);
/* Mangled name */
Delete(mname);
mname = Swig_name_mangle(cname);
/* Renamed class name */
Clear(name);
Append(name,valn);
/* Variable name for the VALUE that refers to the Ruby Class object */
Clear(vname);
Printf(vname, "c%s.klass", name);
/* Variable name for the VALUE that refers to the Ruby Class object */
Clear(mImpl);
Printf(mImpl, "c%s.mImpl", name);
/* Prefix */
Clear(prefix);
Printv(prefix,(rn ? rn : cn), "_", NIL);
}
char *strip(const String_or_char *s) {
Clear(temp);
Append(temp, s);
if (Strncmp(s, prefix, Len(prefix)) == 0) {
Replaceall(temp,prefix,"");
}
return Char(temp);
}
};
static const char *
usage = "\
Ruby Options (available with -ruby)\n\
-globalmodule - Wrap everything into the global module\n\
-minherit - Attempt to support multiple inheritance\n\
-nocppcast - Disable C++ casting operators, useful for generating bugs\n\
-cppcast - Enable C++ casting operators\n\
-autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\
-noautorename - Disable renaming of classes and methods (default)\n\
-prefix <name> - Set a prefix <name> to be prepended to all names\n\
-feature <name> - Set feature name to <name> (used by `require')\n";
#define RCLASS(hash, name) (RClass*)(Getattr(hash, name) ? Data(Getattr(hash, name)) : 0)
#define SET_RCLASS(hash, name, klass) Setattr(hash, name, NewVoid(klass, 0))
class RUBY : public Language {
private:
String *module;
String *modvar;
String *feature;
String *prefix;
int current;
Hash *classes; /* key=cname val=RClass */
RClass *klass; /* Currently processing class */
Hash *special_methods; /* Python style special method name table */
File *f_directors;
File *f_directors_h;
File *f_runtime;
File *f_runtime_h;
File *f_header;
File *f_wrappers;
File *f_init;
File *f_initbeforefunc;
bool useGlobalModule;
bool multipleInheritance;
// Wrap modes
enum {
NO_CPP,
MEMBER_FUNC,
CONSTRUCTOR_ALLOCATE,
CONSTRUCTOR_INITIALIZE,
DESTRUCTOR,
MEMBER_VAR,
CLASS_CONST,
STATIC_FUNC,
STATIC_VAR
};
public:
/* ---------------------------------------------------------------------
* RUBY()
*
* Initialize member data
* --------------------------------------------------------------------- */
RUBY() {
module = 0;
modvar = 0;
feature = 0;
prefix = 0;
current = NO_CPP;
classes = 0;
klass = 0;
special_methods = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_initbeforefunc = 0;
useGlobalModule = false;
multipleInheritance = false;
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n",
" rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n",
" return Qnil;\n",
"}\n", NIL);
director_multiple_inheritance = 0;
director_language = 1;
}
/* ---------------------------------------------------------------------
* main()
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
int cppcast = 1;
int autorename = 0;
/* Set location of SWIG library */
SWIG_library_directory("ruby");
/* Look for certain command line options */
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-feature") == 0) {
if (argv[i+1]) {
char *name = argv[i+1];
feature = NewString(name);
Swig_mark_arg(i);
Swig_mark_arg(i+1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-globalmodule") == 0) {
useGlobalModule = true;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-minherit") == 0) {
multipleInheritance = true;
director_multiple_inheritance = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-cppcast") == 0) {
cppcast = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nocppcast") == 0) {
cppcast = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-autorename") == 0) {
autorename = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-noautorename") == 0) {
autorename = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-prefix") == 0) {
if (argv[i+1]) {
char *name = argv[i+1];
prefix = NewString(name);
Swig_mark_arg(i);
Swig_mark_arg(i+1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i],"-help") == 0) {
Printf(stdout,"%s\n", usage);
}
}
}
if (cppcast) {
/* Turn on cppcast mode */
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
}
if (autorename) {
/* Turn on the autorename mode */
Preprocessor_define((DOH *) "SWIG_RUBY_AUTORENAME", 0);
}
/* Add a symbol to the parser for conditional compilation */
Preprocessor_define("SWIGRUBY 1", 0);
/* Add typemap definitions */
SWIG_typemap_lang("ruby");
SWIG_config_file("ruby.swg");
allow_overloading();
}
/**
* Generate initialization code to define the Ruby module(s),
* accounting for nested modules as necessary.
*/
void defineRubyModule() {
List *modules = Split(module,':',INT_MAX);
if (modules != 0 && Len(modules) > 0) {
String *mv = 0;
Iterator m;
m = First(modules);
while (m.item) {
if (Len(m.item) > 0) {
if (mv != 0) {
Printv(f_init, tab4, modvar,
" = rb_define_module_under(", modvar, ", \"", m.item, "\");\n", NIL);
} else {
Printv(f_init, tab4, modvar,
" = rb_define_module(\"", m.item, "\");\n", NIL);
mv = NewString(modvar);
}
}
m = Next(m);
}
Delete(mv);
Delete(modules);
}
}
void registerMagicMethods() {
special_methods = NewHash();
/* Python style special method name. */
/* Basic */
Setattr(special_methods, "__repr__", "inspect");
Setattr(special_methods, "__str__", "to_s");
Setattr(special_methods, "__cmp__", "<=>");
Setattr(special_methods, "__hash__", "hash");
Setattr(special_methods, "__nonzero__", "nonzero?");
/* Callable */
Setattr(special_methods, "__call__", "call");
/* Collection */
Setattr(special_methods, "__len__", "length");
Setattr(special_methods, "__getitem__", "[]");
Setattr(special_methods, "__setitem__", "[]=");
/* Operators */
Setattr(special_methods, "__add__", "+");
Setattr(special_methods, "__pos__", "+@");
Setattr(special_methods, "__sub__", "-");
Setattr(special_methods, "__neg__", "-@");
Setattr(special_methods, "__mul__", "*");
Setattr(special_methods, "__div__", "/");
Setattr(special_methods, "__mod__", "%");
Setattr(special_methods, "__lshift__", "<<");
Setattr(special_methods, "__rshift__", ">>");
Setattr(special_methods, "__and__", "&");
Setattr(special_methods, "__or__", "|");
Setattr(special_methods, "__xor__", "^");
Setattr(special_methods, "__invert__", "~");
Setattr(special_methods, "__lt__", "<");
Setattr(special_methods, "__le__", "<=");
Setattr(special_methods, "__gt__", ">");
Setattr(special_methods, "__ge__", ">=");
Setattr(special_methods, "__eq__", "==");
/* Other numeric */
Setattr(special_methods, "__divmod__", "divmod");
Setattr(special_methods, "__pow__", "**");
Setattr(special_methods, "__abs__", "abs");
Setattr(special_methods, "__int__", "to_i");
Setattr(special_methods, "__float__", "to_f");
Setattr(special_methods, "__coerce__", "coerce");
}
/* ---------------------------------------------------------------------
* top()
* --------------------------------------------------------------------- */
virtual int top(Node *n) {
/**
* See if any Ruby module options have been specified as options
* to the %module directive.
*/
Node *swigModule = Getattr(n, "module");
if (swigModule) {
Node *options = Getattr(swigModule, "options");
if (options) {
if (Getattr(options, "directors")) {
allow_directors();
}
if (Getattr(options, "dirprot")) {
allow_dirprot();
}
if (Getattr(options, "ruby_globalmodule")) {
useGlobalModule = true;
}
if (Getattr(options, "ruby_minherit")) {
multipleInheritance = true;
director_multiple_inheritance = 1;
}
}
}
/* Set comparison with none for ConstructorToFunction */
setSubclassInstanceCheck(NewStringf("strcmp(rb_obj_classname(self), classname) != 0"));
// setSubclassInstanceCheck(NewString("CLASS_OF(self) != cFoo.klass"));
/* Initialize all of the output files */
String *outfile = Getattr(n,"outfile");
String *outfile_h = Getattr(n, "outfile_h");
f_runtime = NewFile(outfile,"w");
if (!f_runtime) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
if (directorsEnabled()) {
f_runtime_h = NewFile(outfile_h,"w");
if (!f_runtime_h) {
FileErrorDisplay(outfile_h);
SWIG_exit(EXIT_FAILURE);
}
}
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
f_directors_h = NewString("");
f_directors = NewString("");
f_initbeforefunc = NewString("");
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header",f_header);
Swig_register_filebyname("wrapper",f_wrappers);
Swig_register_filebyname("runtime",f_runtime);
Swig_register_filebyname("init",f_init);
Swig_register_filebyname("director",f_directors);
Swig_register_filebyname("director_h",f_directors_h);
Swig_register_filebyname("initbeforefunc", f_initbeforefunc);
modvar = 0;
current = NO_CPP;
klass = 0;
classes = NewHash();
registerMagicMethods();
Swig_banner(f_runtime);
Printf(f_runtime,"#define SWIGRUBY\n");
if (directorsEnabled()) {
Printf(f_runtime,"#define SWIG_DIRECTORS\n");
}
/* typedef void *VALUE */
SwigType *value = NewSwigType(T_VOID);
SwigType_add_pointer(value);
SwigType_typedef(value,(char*)"VALUE");
Delete(value);
/* Set module name */
set_module(Char(Getattr(n,"name")));
if (directorsEnabled()) {
Swig_banner(f_directors_h);
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module);
Printf(f_directors_h, "class Swig::Director;\n\n");
Swig_insert_file("director.swg", f_directors);
Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
}
Printf(f_header,"#define SWIG_init Init_%s\n", feature);
Printf(f_header,"#define SWIG_name \"%s\"\n\n", module);
Printf(f_header,"static VALUE %s;\n", modvar);
/* Start generating the initialization function */
Printv(f_init,
"\n",
"#ifdef __cplusplus\n",
"extern \"C\"\n",
"#endif\n",
"SWIGEXPORT void Init_", feature, "(void) {\n",
"size_t i;\n",
"\n",
NIL);
Printv(f_init, tab4, "SWIG_InitRuntime();\n", NIL);
if (!useGlobalModule)
defineRubyModule();
Printv(f_init,
"\n",
"SWIG_InitializeModule(0);\n",
"for (i = 0; i < swig_module.size; i++) {\n",
"SWIG_define_class(swig_module.types[i]);\n",
"}\n",
NIL);
Printf(f_init,"\n");
/* Initialize code to keep track of objects */
Printf(f_init,"SWIG_RubyInitializeTrackings();\n");
Language::top(n);
/* Finish off our init function */
Printf(f_init,"}\n");
SwigType_emit_type_table(f_runtime,f_wrappers);
/* Close all of the files */
Dump(f_header,f_runtime);
if (directorsEnabled()) {
Dump(f_directors, f_runtime);
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");
Printf(f_runtime_h, "#endif\n");
Close(f_runtime_h);
}
Dump(f_wrappers,f_runtime);
Dump(f_initbeforefunc, f_runtime);
Wrapper_pretty_print(f_init,f_runtime);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Delete(f_initbeforefunc);
Close(f_runtime);
Delete(f_runtime);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* importDirective()
* ----------------------------------------------------------------------------- */
virtual int importDirective(Node *n) {
String *modname = Getattr(n,"module");
if (modname) {
if (prefix) {
Insert(modname, 0, prefix);
}
List *modules = Split(modname,':',INT_MAX);
if (modules && Len(modules) > 0) {
modname = NewString("");
String *last = NULL;
Iterator m = First(modules);
while (m.item) {
if (Len(m.item) > 0) {
if (last) {
Append(modname, "/");
}
Append(modname, m.item);
last = m.item;
}
m = Next(m);
}
Printf(f_init,"rb_require(\"%s\");\n", modname);
Delete(modname);
}
Delete(modules);
}
return Language::importDirective(n);
}
/* ---------------------------------------------------------------------
* set_module(const char *mod_name)
*
* Sets the module name. Does nothing if it's already set (so it can
* be overridden as a command line option).
*---------------------------------------------------------------------- */
void set_module(const char *s) {
String *mod_name = NewString(s);
if (module == 0) {
/* Start with the empty string */
module = NewString("");
if (prefix) {
Insert(mod_name, 0, prefix);
}
/* Account for nested modules */
List *modules = Split(mod_name,':',INT_MAX);
if (modules != 0 && Len(modules) > 0) {
String *last = 0;
Iterator m = First(modules);
while (m.item) {
if (Len(m.item) > 0) {
String *cap = NewString(m.item);
(Char(cap))[0] = toupper((Char(cap))[0]);
if (last != 0) {
Append(module, "::");
}
Append(module, cap);
last = m.item;
}
m = Next(m);
}
if (feature == 0) {
feature = Copy(last);
}
(Char(last))[0] = toupper((Char(last))[0]);
modvar = NewStringf("m%s", last);
Delete(modules);
}
}
Delete(mod_name);
}
/* --------------------------------------------------------------------------
* nativeWrapper()
* -------------------------------------------------------------------------- */
virtual int nativeWrapper(Node *n) {
String *funcname = Getattr(n,"wrap:name");
Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number,
"Adding native function %s not supported (ignored).\n", funcname);
return SWIG_NOWRAP;
}
/**
* Process the comma-separated list of aliases (if any).
*/
void defineAliases(Node *n, const String_or_char *iname) {
String *aliasv = Getattr(n,"feature:alias");
if (aliasv) {
List *aliases = Split(aliasv,',',INT_MAX);
if (aliases && Len(aliases) > 0) {
Iterator alias = First(aliases);
while (alias.item) {
if (Len(alias.item) > 0) {
Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL);
}
alias = Next(alias);
}
}
Delete(aliases);
}
}
/* ---------------------------------------------------------------------
* create_command(Node *n, char *iname)
*
* Creates a new command from a C function.
* iname = Name of function in scripting language
*
* A note about what "protected" and "private" mean in Ruby:
*
* A private method is accessible only within the class or its subclasses,
* and it is callable only in "function form", with 'self' (implicit or
* explicit) as a receiver.
*
* A protected method is callable only from within its class, but unlike
* a private method, it can be called with a receiver other than self, such
* as another instance of the same class.
* --------------------------------------------------------------------- */
void create_command(Node *n, const String_or_char *iname) {
String *alloc_func = Swig_name_wrapper(iname);
String *wname = Swig_name_wrapper(iname);
if (CPlusPlus) {
Insert(wname,0,"VALUEFUNC(");
Append(wname,")");
}
if (current != NO_CPP)
iname = klass->strip(iname);
if (Getattr(special_methods, iname)) {
iname = GetChar(special_methods, iname);
}
String *s = NewString("");
String *temp = NewString("");
#ifdef SWIG_PROTECTED_TARGET_METHODS
const char* rb_define_method = is_public(n) ?
"rb_define_method" : "rb_define_protected_method" ;
#else
const char* rb_define_method = "rb_define_method";
#endif
switch (current) {
case MEMBER_FUNC:
{
if (multipleInheritance) {
Printv(klass->init, tab4, rb_define_method,"(", klass->mImpl, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
} else {
Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"",
iname, "\", ", wname, ", -1);\n", NIL);
}
}
break;
case CONSTRUCTOR_ALLOCATE:
Printv(s, tab4, "rb_define_alloc_func(", klass->vname, ", ", alloc_func, ");\n", NIL);
Replaceall(klass->init,"$allocator", s);
break;
case CONSTRUCTOR_INITIALIZE:
Printv(s, tab4, rb_define_method,"(", klass->vname,
", \"initialize\", ", wname, ", -1);\n", NIL);
Replaceall(klass->init,"$initializer", s);
break;
case MEMBER_VAR:
Append(temp,iname);
Replaceall(temp,"_set", "=");
Replaceall(temp,"_get", "");
if (multipleInheritance) {
Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"",
temp, "\", ", wname, ", -1);\n", NIL);
} else {
Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"",
temp, "\", ", wname, ", -1);\n", NIL);
}
break;
case STATIC_FUNC:
Printv(klass->init, tab4, "rb_define_singleton_method(", klass->vname,
", \"", iname, "\", ", wname, ", -1);\n", NIL);
break;
case NO_CPP:
if (!useGlobalModule) {
Printv(s, tab4, "rb_define_module_function(", modvar, ", \"",
iname, "\", ", wname, ", -1);\n",NIL);
Printv(f_init,s,NIL);
} else {
Printv(s, tab4, "rb_define_global_function(\"",
iname, "\", ", wname, ", -1);\n",NIL);
Printv(f_init,s,NIL);
}
break;
case DESTRUCTOR:
case CLASS_CONST:
case STATIC_VAR:
assert(false); // Should not have gotten here for these types
default:
assert(false);
}
defineAliases(n, iname);
Delete(temp);
Delete(s);
Delete(wname);
Delete(alloc_func);
}
/* ---------------------------------------------------------------------
* applyInputTypemap()
*
* Look up the appropriate "in" typemap for this parameter (p),
* substitute the correct strings for the $target and $input typemap
* parameters, and dump the resulting code to the wrapper file.
* --------------------------------------------------------------------- */
Parm *applyInputTypemap(Parm *p, String *ln, String *source, Wrapper *f, String *symname) {
String *tm;
SwigType *pt = Getattr(p,"type");
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$target",ln);
Replaceall(tm,"$source",source);
Replaceall(tm,"$input",source);
Replaceall(tm,"$symname", symname);
if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) {
Replaceall(tm,"$disown","SWIG_POINTER_DISOWN");
}
else {
Replaceall(tm,"$disown","0");
}
Setattr(p,"emit:input",Copy(source));
Printf(f->code,"%s\n", tm);
p = Getattr(p,"tmap:in:next");
} else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument.\n", SwigType_str(pt,0));
p = nextSibling(p);
}
return p;
}
Parm *skipIgnoredArgs(Parm *p) {
while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next");
}
return p;
}
/* ---------------------------------------------------------------------
* marshalInputArgs()
*
* Process all of the arguments passed into the scripting language
* method and convert them into C/C++ function arguments using the
* supplied typemaps.
* --------------------------------------------------------------------- */
void marshalInputArgs(Node *n, ParmList *l, int numarg, int numreq, String *kwargs, bool allow_kwargs, Wrapper *f) {
int i;
Parm *p;
String *tm;
String *source;
String *target;
source = NewString("");
target = NewString("");
bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
/**
* The 'start' value indicates which of the C/C++ function arguments
* produced here corresponds to the first value in Ruby's argv[] array.
* The value of start is either zero or one. If start is zero, then
* the first argument (with name arg1) is based on the value of argv[0].
* If start is one, then arg1 is based on the value of argv[1].
*/
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) ? 1 : 0;
int varargs = emit_isvarargs(l);
Printf(kwargs,"{ ");
for (i = 0, p = l; i < numarg; i++) {
p = skipIgnoredArgs(p);
String *pn = Getattr(p,"name");
String *ln = Getattr(p,"lname");
/* Produce string representation of source argument */
Clear(source);
/* First argument is a special case */
if (i == 0) {
Printv(source, (start == 0) ? "argv[0]" : "self", NIL);
} else {
Printf(source,"argv[%d]",i-start);
}
/* Produce string representation of target argument */
Clear(target);
Printf(target,"%s",Char(ln));
if (i >= (numreq)) { /* Check if parsing an optional argument */
Printf(f->code," if (argc > %d) {\n", i - start);
}
/* Record argument name for keyword argument handling */
if (Len(pn)) {
Printf(kwargs,"\"%s\",", pn);
} else {
Printf(kwargs,"\"arg%d\",", i+1);
}
/* Look for an input typemap */
p = applyInputTypemap(p, ln, source, f, Getattr(n,"name"));
if (i >= numreq) {
Printf(f->code,"}\n");
}
}
/* Finish argument marshalling */
Printf(kwargs," NULL }");
if (allow_kwargs) {
Printv(f->locals, tab4, "char *kwnames[] = ", kwargs, ";\n", NIL);
}
/* Trailing varargs */
if (varargs) {
if (p && (tm = Getattr(p,"tmap:in"))) {
Clear(source);
Printf(source,"argv[%d]",i-start);
Replaceall(tm,"$input",source);
Setattr(p,"emit:input",Copy(source));
Printf(f->code,"if (argc > %d) {\n", i-start);
Printv(f->code,tm,"\n",NIL);
Printf(f->code,"}\n");
}
}
Delete(source);
Delete(target);
}
/* ---------------------------------------------------------------------
* insertConstraintCheckingCode(ParmList *l, Wrapper *f)
*
* Checks each of the parameters in the parameter list for a "check"
* typemap and (if it finds one) inserts the typemapping code into
* the function wrapper.
* --------------------------------------------------------------------- */
void insertConstraintCheckingCode(ParmList *l, Wrapper *f) {
Parm *p;
String *tm;
for (p = l; p;) {
if ((tm = Getattr(p,"tmap:check"))) {
Replaceall(tm,"$target",Getattr(p,"lname"));
Printv(f->code,tm,"\n",NIL);
p = Getattr(p,"tmap:check:next");
} else {
p = nextSibling(p);
}
}
}
/* ---------------------------------------------------------------------
* insertCleanupCode(ParmList *l, String *cleanup)
*
* Checks each of the parameters in the parameter list for a "freearg"
* typemap and (if it finds one) inserts the typemapping code into
* the function wrapper.
* --------------------------------------------------------------------- */
void insertCleanupCode(ParmList *l, String *cleanup) {
String *tm;
for (Parm *p = l; p; ) {
// if (!checkAttribute(p,"tmap:in:numinputs","0") && (tm = Getattr(p,"tmap:freearg"))) {
if ((tm = Getattr(p,"tmap:freearg"))) {
if (Len(tm) != 0) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
}
p = Getattr(p,"tmap:freearg:next");
} else {
p = nextSibling(p);
}
}
}
/* ---------------------------------------------------------------------
* insertArgOutputCode(ParmList *l, String *outarg, int& need_result)
*
* Checks each of the parameters in the parameter list for a "argout"
* typemap and (if it finds one) inserts the typemapping code into
* the function wrapper.
* --------------------------------------------------------------------- */
void insertArgOutputCode(ParmList *l, String *outarg, int& need_result) {
String *tm;
for (Parm *p = l; p; ) {
if ((tm = Getattr(p,"tmap:argout"))) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Replaceall(tm,"$target","vresult");
Replaceall(tm,"$result","vresult");
Replaceall(tm,"$arg",Getattr(p,"emit:input"));
Replaceall(tm,"$input",Getattr(p,"emit:input"));
Printv(outarg,tm,"\n",NIL);
need_result = 1;
p = Getattr(p,"tmap:argout:next");
} else {
p = nextSibling(p);
}
}
}
/* ---------------------------------------------------------------------
* validIdentifier()
*
* Is this a valid identifier in the scripting language?
* Ruby method names can include any combination of letters, numbers
* and underscores. A Ruby method name may optionally end with
* a question mark ("?"), exclamation point ("!") or equals sign ("=").
*
* Methods whose names end with question marks are, by convention,
* predicate methods that return true or false (e.g. Array#empty?).
*
* Methods whose names end with exclamation points are, by convention,
* called bang methods that modify the instance in place (e.g. Array#sort!).
*
* Methods whose names end with an equals sign are attribute setters
* (e.g. Thread#critical=).
* --------------------------------------------------------------------- */
virtual int validIdentifier(String *s) {
char *c = Char(s);
while (*c) {
if ( !( isalnum(*c) || (*c == '_') || (*c == '?') || (*c == '!') || (*c == '=') ) ) return 0;
c++;
}
return 1;
}
/* ---------------------------------------------------------------------
* functionWrapper()
*
* Create a function declaration and register it with the interpreter.
* --------------------------------------------------------------------- */
virtual int functionWrapper(Node *n) {
String *nodeType;
bool constructor;
bool destructor;
String *storage;
bool isVirtual;
String *symname = Copy(Getattr(n,"sym:name"));
SwigType *t = Getattr(n,"type");
ParmList *l = Getattr(n,"parms");
int director_method = 0;
String *tm;
int need_result = 0;
/* Ruby needs no destructor wrapper */
if (current == DESTRUCTOR)
return SWIG_NOWRAP;
nodeType = Getattr(n, "nodeType");
constructor = (!Cmp(nodeType, "constructor"));
destructor = (!Cmp(nodeType, "destructor"));
storage = Getattr(n, "storage");
isVirtual = (Cmp(storage, "virtual") == 0);
/* If the C++ class constructor is overloaded, we only want to
* write out the "new" singleton method once since it is always
* the same. (It's the "initialize" method that will handle the
* overloading). */
if (current == CONSTRUCTOR_ALLOCATE &&
Swig_symbol_isoverloaded(n) &&
Getattr(n, "sym:nextSibling") != 0) return SWIG_OK;
String *overname = 0;
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
} else {
if (!addSymbol(symname, n))
return SWIG_ERROR;
}
String *cleanup = NewString("");
String *outarg = NewString("");
String *kwargs = NewString("");
Wrapper *f = NewWrapper();
/* Rename predicate methods */
if (GetFlag(n, "feature:predicate")) {
Append(symname, "?");
}
/* Rename bang methods */
if (GetFlag(n, "feature:bang")) {
Append(symname, "!");
}
/* Determine the name of the SWIG wrapper function */
String *wname = Swig_name_wrapper(symname);
if (overname && current != CONSTRUCTOR_ALLOCATE) {
Append(wname,overname);
}
/* Emit arguments */
if (current != CONSTRUCTOR_ALLOCATE) {
emit_args(t,l,f);
}
/* Attach standard typemaps */
if (current != CONSTRUCTOR_ALLOCATE) {
emit_attach_parmmaps(l, f);
}
Setattr(n, "wrap:parms", l);
/* Get number of arguments */
int numarg = emit_num_arguments(l);
int numreq = emit_num_required(l);
int varargs = emit_isvarargs(l);
bool allow_kwargs = GetFlag(n,"feature:kwargs") ? true : false;
bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) ? 1 : 0;
/* Now write the wrapper function itself */
if (current == CONSTRUCTOR_ALLOCATE) {
Printf(f->def, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n");
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(VALUE self) {", NIL);
Printf(f->def, "#else\n");
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL);
Printf(f->def, "#endif\n");
} else if (current == CONSTRUCTOR_INITIALIZE) {
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL);
if (!varargs) {
Printf(f->code,"if ((argc < %d) || (argc > %d)) ", numreq-start, numarg-start);
} else {
Printf(f->code,"if (argc < %d) ", numreq-start);
}
Printf(f->code,"{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n",numreq-start);
} else {
Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL);
if (!varargs) {
Printf(f->code,"if ((argc < %d) || (argc > %d)) ", numreq-start, numarg-start);
} else {
Printf(f->code,"if (argc < %d) ", numreq-start);
}
Printf(f->code,"{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n",numreq-start);
}
/* Now walk the function parameter list and generate code */
/* to get arguments */
if (current != CONSTRUCTOR_ALLOCATE) {
marshalInputArgs(n, l, numarg, numreq, kwargs, allow_kwargs, f);
}
// FIXME?
if (ctor_director) {
numarg--;
numreq--;
}
/* Insert constraint checking code */
insertConstraintCheckingCode(l, f);
/* Insert cleanup code */
insertCleanupCode(l, cleanup);
/* Insert argument output code */
insertArgOutputCode(l, outarg, need_result);
/* if the object is a director, and the method call originated from its
* underlying python object, resolve the call by going up the c++
* inheritance chain. otherwise try to resolve the method in python.
* without this check an infinite loop is set up between the director and
* shadow class method calls.
*/
// NOTE: this code should only be inserted if this class is the
// base class of a director class. however, in general we haven't
// yet analyzed all classes derived from this one to see if they are
// directors. furthermore, this class may be used as the base of
// a director class defined in a completely different module at a
// later time, so this test must be included whether or not directorbase
// is true. we do skip this code if directors have not been enabled
// at the command line to preserve source-level compatibility with
// non-polymorphic swig. also, if this wrapper is for a smart-pointer
// method, there is no need to perform the test since the calling object
// (the smart-pointer) and the director object (the "pointee") are
// distinct.
if (directorsEnabled()) {
if (!is_smart_pointer()) {
if (/*directorbase &&*/ !constructor && !destructor
&& isVirtual && !Getattr(n,"feature:nodirector")) {
director_method = 1;
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
Printf(f->code, "if (director && (director->swig_get_self() == self)) director->swig_set_up();\n");
}
}
}
/* Now write code to make the function call */
if (current != CONSTRUCTOR_ALLOCATE) {
if (current == CONSTRUCTOR_INITIALIZE) {
Node *pn = Swig_methodclass(n);
String *symname = Getattr(pn,"sym:name");
String *action = Getattr(n,"wrap:action");
if (directorsEnabled()) {
String *classname = NewStringf("const char *classname SWIGUNUSED = \"%s::%s\"", module, symname);
Wrapper_add_local(f, "classname", classname);
}
if (action) {
Append(action,"DATA_PTR(self) = result;\n");
if (GetFlag(pn,"feature:trackobjects")) {
Append(action,"SWIG_RubyAddTracking(result, self);\n");
}
}
}
/* Emit the function call */
if (director_method) {
Printf(f->code, "try {\n");
Printf(f->code, " Swig::UnknownExceptionHandler dh;\n");
}
emit_action(n,f);
if (director_method) {
Printf(f->code, "} catch (Swig::DirectorException& e) {\n");
Printf(f->code, " rb_exc_raise(e.getError());\n");
Printf(f->code, " SWIG_fail;\n");
Printf(f->code, "}\n");
}
}
/* Return value if necessary */
if (SwigType_type(t) != T_VOID && current != CONSTRUCTOR_ALLOCATE && current != CONSTRUCTOR_INITIALIZE) {
need_result = 1;
if (GetFlag(n, "feature:predicate")) {
Printv(f->code, tab4, "vresult = (result ? Qtrue : Qfalse);\n", NIL);
} else {
tm = Swig_typemap_lookup_new("out",n,"result",0);
if (tm) {
Replaceall(tm,"$result","vresult");
Replaceall(tm,"$source","result");
Replaceall(tm,"$target","vresult");
if (GetFlag(n, "feature:new"))
Replaceall(tm,"$owner", "SWIG_POINTER_OWN");
else
Replaceall(tm,"$owner", "0");
#if 1
// FIXME: this will not try to unwrap directors returned as non-director
// base class pointers!
/* New addition to unwrap director return values so that the original
* Ruby object is returned instead.
*/
bool unwrap = false;
String *decl = Getattr(n, "decl");
int is_pointer = SwigType_ispointer_return(decl);
int is_reference = SwigType_isreference_return(decl);
if (is_pointer || is_reference) {
String *type = Getattr(n, "type");
Node *parent = Getattr(n,"parentNode");
Node *modname = Getattr(parent, "module");
Node *target = Swig_directormap(modname, type);
if (target) unwrap = true;
}
if (unwrap) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = dynamic_cast<Swig::Director *>(result);\n");
Printf(f->code, "if (director) {\n");
Printf(f->code, " vresult = director->swig_get_self();\n");
Printf(f->code, "} else {\n");
Printf(f->code,"%s\n", tm);
Printf(f->code, "}\n");
director_method = 0;
} else {
Printf(f->code,"%s\n", tm);
}
#else
Printf(f->code,"%s\n", tm);
#endif
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s.\n", SwigType_str(t,0));
}
}
}
/* Extra code needed for new and initialize methods */
if (current == CONSTRUCTOR_ALLOCATE) {
need_result = 1;
Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(t)));
Printf(f->code, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n");
Printf(f->code, "rb_obj_call_init(vresult, argc, argv);\n");
Printf(f->code, "#endif\n");
} else if (current == CONSTRUCTOR_INITIALIZE) {
need_result = 1;
// Printf(f->code, "DATA_PTR(self) = result;\n");
}
/* Dump argument output code; */
Printv(f->code,outarg,NIL);
/* Dump the argument cleanup code */
int need_cleanup = (current != CONSTRUCTOR_ALLOCATE) && (Len(cleanup) != 0);
if (need_cleanup) {
Printv(f->code,cleanup,NIL);
}
/* Look for any remaining cleanup. This processes the %new directive */
if (current != CONSTRUCTOR_ALLOCATE && GetFlag(n, "feature:new")) {
tm = Swig_typemap_lookup_new("newfree",n,"result",0);
if (tm) {
Replaceall(tm,"$source","result");
Printv(f->code,tm, "\n",NIL);
Delete(tm);
}
}
/* Special processing on return value. */
tm = Swig_typemap_lookup_new("ret",n,"result",0);
if (tm) {
Replaceall(tm,"$source","result");
Printv(f->code,tm, NIL);
Delete(tm);
}
if (director_method) {
if ((tm = Swig_typemap_lookup_new("directorfree",n,"result",0))) {
Replaceall(tm,"$input","result");
Replaceall(tm,"$result","vresult");
Printf(f->code,"%s\n",tm);
}
}
/* Wrap things up (in a manner of speaking) */
if (need_result) {
if (current == CONSTRUCTOR_ALLOCATE) {
Printv(f->code, tab4, "return vresult;\n", NIL);
} else if (current == CONSTRUCTOR_INITIALIZE) {
Printv(f->code, tab4, "return self;\n", NIL);
Printv(f->code,"fail:\n",NIL);
if (need_cleanup) {
Printv(f->code,cleanup,NIL);
}
Printv(f->code, tab4, "return Qnil;\n", NIL);
} else {
Wrapper_add_local(f,"vresult","VALUE vresult = Qnil");
Printv(f->code, tab4, "return vresult;\n", NIL);
Printv(f->code,"fail:\n",NIL);
if (need_cleanup) {
Printv(f->code,cleanup,NIL);
}
Printv(f->code, tab4, "return Qnil;\n", NIL);
}
} else {
Printv(f->code, tab4, "return Qnil;\n", NIL);
Printv(f->code,"fail:\n",NIL);
if (need_cleanup) {
Printv(f->code,cleanup,NIL);
}
Printv(f->code, tab4, "return Qnil;\n", NIL);
}
Printf(f->code,"}\n");
/* Substitute the cleanup code */
Replaceall(f->code,"$cleanup",cleanup);
/* Emit the function */
Wrapper_print(f, f_wrappers);
/* Now register the function with the interpreter */
if (!Swig_symbol_isoverloaded(n)) {
create_command(n, symname);
} else {
if (current == CONSTRUCTOR_ALLOCATE) {
create_command(n, symname);
} else {
Setattr(n, "wrap:name", wname);
if (!Getattr(n, "sym:nextSibling"))
dispatchFunction(n);
}
}
Delete(kwargs);
Delete(cleanup);
Delete(outarg);
DelWrapper(f);
Delete(symname);
return SWIG_OK;
}
/* ------------------------------------------------------------
* dispatchFunction()
* ------------------------------------------------------------ */
void dispatchFunction(Node *n) {
/* Last node in overloaded chain */
int maxargs;
String *tmp = NewString("");
String *dispatch = Swig_overload_dispatch(n, "return %s(nargs, args, self);", &maxargs);
/* Generate a dispatch wrapper for all overloaded functions */
Wrapper *f = NewWrapper();
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
Printv(f->def,
"SWIGINTERN VALUE ", wname,
"(int nargs, VALUE *args, VALUE self) {",
NIL);
Wrapper_add_local(f, "argc", "int argc");
bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
if (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) {
Printf(tmp, "VALUE argv[%d]", maxargs+1);
} else {
Printf(tmp, "VALUE argv[%d]", maxargs);
}
Wrapper_add_local(f, "argv", tmp);
Wrapper_add_local(f, "ii", "int ii");
if (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) {
Printf(f->code, "argc = nargs + 1;\n");
Printf(f->code, "argv[0] = self;\n");
Printf(f->code, "if (argc > %d) SWIG_fail;\n", maxargs + 1);
Printf(f->code, "for (ii = 1; (ii < argc); ii++) {\n");
Printf(f->code, "argv[ii] = args[ii-1];\n");
Printf(f->code, "}\n");
} else {
Printf(f->code, "argc = nargs;\n");
Printf(f->code, "if (argc > %d) SWIG_fail;\n", maxargs);
Printf(f->code, "for (ii = 0; (ii < argc); ii++) {\n");
Printf(f->code, "argv[ii] = args[ii];\n");
Printf(f->code, "}\n");
}
Replaceall(dispatch, "$args", "nargs, args, self");
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code,"fail:\n");
Printf(f->code, "rb_raise(rb_eArgError, \"No matching function for overloaded '%s'\");\n", symname);
Printf(f->code,"return Qnil;\n");
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
create_command(n, Char(symname));
DelWrapper(f);
Delete(dispatch);
Delete(tmp);
Delete(wname);
}
/* ---------------------------------------------------------------------
* variableWrapper()
* --------------------------------------------------------------------- */
virtual int variableWrapper(Node *n) {
char *name = GetChar(n,"name");
char *iname = GetChar(n,"sym:name");
SwigType *t = Getattr(n,"type");
String *tm;
String *getfname, *setfname;
Wrapper *getf, *setf;
getf = NewWrapper();
setf = NewWrapper();
/* create getter */
int addfail = 0;
getfname = Swig_name_get(iname);
Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL);
Printf(getf->def, "VALUE self");
Printf(getf->def, ") {");
Wrapper_add_local(getf,"_val","VALUE _val");
tm = Swig_typemap_lookup_new("varout",n, name, 0);
if (tm) {
Replaceall(tm,"$result","_val");
Replaceall(tm,"$target","_val");
Replaceall(tm,"$source",name);
/* Printv(getf->code,tm, NIL); */
addfail = emit_action_code(n, getf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to read variable of type %s\n", SwigType_str(t,0));
}
Printv(getf->code, tab4, "return _val;\n", NIL);
if (addfail) {
Append(getf->code,"fail:\n");
Append(getf->code," return Qnil;\n");
}
Append(getf->code,"}\n");
Wrapper_print(getf,f_wrappers);
if (!is_assignable(n)) {
setfname = NewString("NULL");
} else {
/* create setter */
setfname = Swig_name_set(iname);
Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL);
Printf(setf->def, "VALUE _val) {");
tm = Swig_typemap_lookup_new("varin",n,name,0);
if (tm) {
Replaceall(tm,"$input","_val");
Replaceall(tm,"$source","_val");
Replaceall(tm,"$target",name);
/* Printv(setf->code,tm,"\n",NIL); */
emit_action_code(n, setf, tm);
} else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
"Unable to set variable of type %s\n", SwigType_str(t,0));
}
Printv(setf->code, tab4, "return _val;\n", NIL);
Printf(setf->code, "fail:\n");
Printv(setf->code, tab4, "return Qnil;\n", NIL);
Printf(setf->code,"}\n");
Wrapper_print(setf,f_wrappers);
}
/* define accessor method */
if (CPlusPlus) {
Insert(getfname,0,"VALUEFUNC(");
Append(getfname,")");
Insert(setfname,0,"VALUEFUNC(");
Append(setfname,")");
}
String *s = NewString("");
switch (current) {
case STATIC_VAR:
/* C++ class variable */
Printv(s,
tab4, "rb_define_singleton_method(", klass->vname, ", \"",
klass->strip(iname), "\", ", getfname, ", 0);\n",
NIL);
if (!GetFlag(n,"feature:immutable")) {
Printv(s,
tab4, "rb_define_singleton_method(", klass->vname, ", \"",
klass->strip(iname), "=\", ", setfname, ", 1);\n",
NIL);
}
Printv(klass->init,s,NIL);
break;
default:
/* C global variable */
/* wrapped in Ruby module attribute */
assert(current == NO_CPP);
if (!useGlobalModule) {
Printv(s,
tab4, "rb_define_singleton_method(", modvar, ", \"",
iname, "\", ", getfname, ", 0);\n",
NIL);
if (!GetFlag(n,"feature:immutable")) {
Printv(s,
tab4, "rb_define_singleton_method(", modvar, ", \"",
iname, "=\", ", setfname, ", 1);\n",
NIL);
}
} else {
Printv(s,
tab4, "rb_define_global_method(\"",
iname, "\", ", getfname, ", 0);\n",
NIL);
if (!GetFlag(n,"feature:immutable")) {
Printv(s,
tab4, "rb_define_global_method(\"",
iname, "=\", ", setfname, ", 1);\n",
NIL);
}
}
Printv(f_init,s,NIL);
Delete(s);
break;
}
Delete(getfname);
Delete(setfname);
DelWrapper(setf);
DelWrapper(getf);
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* validate_const_name(char *name)
*
* Validate constant name.
* --------------------------------------------------------------------- */
char *
validate_const_name(char *name, const char *reason) {
if (!name || name[0] == '\0')
return name;
if (isupper(name[0]))
return name;
if (islower(name[0])) {
name[0] = toupper(name[0]);
Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number,
"Wrong %s name (corrected to `%s')\n", reason, name);
return name;
}
Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number,
"Wrong %s name %s\n", reason, name);
return name;
}
/* ---------------------------------------------------------------------
* constantWrapper()
* --------------------------------------------------------------------- */
virtual int constantWrapper(Node *n) {
Swig_require("constantWrapper",n, "*sym:name", "type", "value", NIL);
char *iname = GetChar(n,"sym:name");
SwigType *type = Getattr(n,"type");
String *rawval = Getattr(n,"rawval");
String *value = rawval ? rawval : Getattr(n,"value");
if (current == CLASS_CONST) {
iname = klass->strip(iname);
}
validate_const_name(iname, "constant");
SetChar(n, "sym:name", iname);
/* Special hook for member pointer */
if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(iname);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
value = Char(wname);
}
String *tm = Swig_typemap_lookup_new("constant", n, value, 0);
if (!tm) tm = Swig_typemap_lookup_new("constcode", n, value, 0);
if (tm) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", iname);
Replaceall(tm, "$symname", iname);
Replaceall(tm, "$value", value);
if (current == CLASS_CONST) {
if (multipleInheritance) {
Replaceall(tm, "$module", klass->mImpl);
Printv(klass->init, tm, "\n", NIL);
} else {
Replaceall(tm, "$module", klass->vname);
Printv(klass->init, tm, "\n", NIL);
}
} else {
if (!useGlobalModule) {
Replaceall(tm, "$module", modvar);
} else {
Replaceall(tm, "$module", "rb_cObject");
}
Printf(f_init, "%s\n", tm);
}
} else {
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
"Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
}
Swig_restore(n);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* classDeclaration()
*
* Records information about classes---even classes that might be defined in
* other modules referenced by %import.
* ----------------------------------------------------------------------------- */
virtual int classDeclaration(Node *n) {
if (!Getattr(n,"feature:onlychildren")) {
String *name = Getattr(n,"name");
String *symname = Getattr(n,"sym:name");
String *tdname = Getattr(n,"tdname");
name = tdname ? tdname : name;
String *namestr = SwigType_namestr(name);
klass = RCLASS(classes, Char(namestr));
if (!klass) {
klass = new RClass();
String *valid_name = NewString(symname ? symname : namestr);
validate_const_name(Char(valid_name), "class");
klass->set_name(namestr, symname, valid_name);
SET_RCLASS(classes, Char(namestr), klass);
Delete(valid_name);
}
Delete(namestr);
}
return Language::classDeclaration(n);
}
/**
* Process the comma-separated list of mixed-in module names (if any).
*/
void includeRubyModules(Node *n) {
String *mixin = Getattr(n,"feature:mixin");
if (mixin) {
List *modules = Split(mixin,',',INT_MAX);
if (modules && Len(modules) > 0) {
Iterator mod = First(modules);
while (mod.item) {
if (Len(mod.item) > 0) {
Printf(klass->init, "rb_include_module(%s, rb_eval_string(\"%s\"));\n", klass->vname, mod.item);
}
mod = Next(mod);
}
}
Delete(modules);
}
}
void handleBaseClasses(Node *n) {
List *baselist = Getattr(n,"bases");
if (baselist && Len(baselist)) {
Iterator base = First(baselist);
while(base.item && GetFlag(base.item,"feature:ignore")) {
base = Next(base);
}
while (base.item) {
String *basename = Getattr(base.item,"name");
String *basenamestr = SwigType_namestr(basename);
RClass *super = RCLASS(classes, Char(basenamestr));
Delete(basenamestr);
if (super) {
SwigType *btype = NewString(basename);
SwigType_add_pointer(btype);
SwigType_remember(btype);
if (multipleInheritance) {
String *bmangle = SwigType_manglestr(btype);
Insert(bmangle,0,"((swig_class *) SWIGTYPE");
Append(bmangle,"->clientdata)->mImpl");
Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL);
Delete(bmangle);
} else {
String *bmangle = SwigType_manglestr(btype);
Insert(bmangle,0,"((swig_class *) SWIGTYPE");
Append(bmangle,"->clientdata)->klass");
Replaceall(klass->init,"$super",bmangle);
Delete(bmangle);
}
Delete(btype);
}
base = Next(base);
while(base.item && GetFlag(base.item,"feature:ignore")) {
base = Next(base);
}
if (!multipleInheritance) {
/* Warn about multiple inheritance for additional base class(es) */
while (base.item) {
if (GetFlag(base.item,"feature:ignore")) {
base = Next(base);
continue;
}
String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0);
String *baseclassname = SwigType_str(Getattr(base.item,"name"),0);
Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, input_file, line_number,
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname);
base = Next(base);
}
}
}
}
}
/**
* Check to see if a %markfunc was specified.
*/
void handleMarkFuncDirective(Node *n) {
String *markfunc = Getattr(n, "feature:markfunc");
if (markfunc) {
Printf(klass->init, "c%s.mark = (void (*)(void *)) %s;\n", klass->name, markfunc);
} else {
Printf(klass->init, "c%s.mark = 0;\n", klass->name);
}
}
/**
* Check to see if a %freefunc was specified.
*/
void handleFreeFuncDirective(Node *n) {
String *freefunc = Getattr(n, "feature:freefunc");
if (freefunc) {
Printf(klass->init, "c%s.destroy = (void (*)(void *)) %s;\n", klass->name, freefunc);
} else {
if (klass->destructor_defined) {
Printf(klass->init, "c%s.destroy = (void (*)(void *)) free_%s;\n", klass->name, klass->mname);
}
}
}
/**
* Check to see if tracking is enabled for this class.
*/
void handleTrackDirective(Node *n) {
int trackObjects = GetFlag(n, "feature:trackobjects");
if (trackObjects) {
Printf(klass->init, "c%s.trackObjects = 1;\n", klass->name);
} else {
Printf(klass->init, "c%s.trackObjects = 0;\n", klass->name);
}
}
/* ----------------------------------------------------------------------
* classHandler()
* ---------------------------------------------------------------------- */
virtual int classHandler(Node *n) {
String *name = Getattr(n,"name");
String *symname = Getattr(n,"sym:name");
String *namestr = SwigType_namestr(name); // does template expansion
klass = RCLASS(classes, Char(namestr));
assert(klass != 0);
Delete(namestr);
String *valid_name = NewString(symname);
validate_const_name(Char(valid_name), "class");
Clear(klass->type);
Printv(klass->type, Getattr(n,"classtype"), NIL);
Printv(f_wrappers, "swig_class c", valid_name, ";\n\n", NIL);
Printv(klass->init, "\n", tab4, NIL);
if (multipleInheritance) {
if (!useGlobalModule) {
Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar,
", \"", klass->name, "\", rb_cObject);\n", NIL);
} else {
Printv(klass->init, klass->vname, " = rb_define_class(\"",
klass->name, "\", rb_cObject);\n", NIL);
}
Printv(klass->init, klass->mImpl, " = rb_define_module_under(", klass->vname, ", \"Impl\");\n", NIL);
} else {
if (!useGlobalModule) {
Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar,
", \"", klass->name, "\", $super);\n", NIL);
} else {
Printv(klass->init, klass->vname, " = rb_define_class(\"",
klass->name, "\", $super);\n", NIL);
}
}
SwigType *tt = NewString(name);
SwigType_add_pointer(tt);
SwigType_remember(tt);
String *tm = SwigType_manglestr(tt);
Printf(klass->init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) &c%s);\n", tm, valid_name);
Delete(tm);
Delete(tt);
Delete(valid_name);
includeRubyModules(n);
Printv(klass->init, "$allocator",NIL);
Printv(klass->init, "$initializer",NIL);
Language::classHandler(n);
handleBaseClasses(n);
handleMarkFuncDirective(n);
handleFreeFuncDirective(n);
handleTrackDirective(n);
if (multipleInheritance) {
Printv(klass->init, "rb_include_module(", klass->vname, ", ", klass->mImpl, ");\n", NIL);
}
String *s = NewString("");
Printv(s, tab4, "rb_undef_alloc_func(", klass->vname, ");\n", NIL);
Replaceall(klass->init,"$allocator", s);
Replaceall(klass->init,"$initializer", "");
if (GetFlag(n,"feature:exceptionclass")) {
Replaceall(klass->init,"$super", "rb_eRuntimeError");
}
else {
Replaceall(klass->init,"$super", "rb_cObject");
}
Delete(s);
Printv(f_init,klass->init,NIL);
klass = 0;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* memberfunctionHandler()
*
* Method for adding C++ member function
*
* By default, we're going to create a function of the form :
*
* Foo_bar(this,args)
*
* Where Foo is the classname, bar is the member name and the this pointer
* is explicitly attached to the beginning.
*
* The renaming only applies to the member function part, not the full
* classname.
*
* --------------------------------------------------------------------- */
virtual int memberfunctionHandler(Node *n) {
current = MEMBER_FUNC;
Language::memberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* constructorHandler()
*
* Method for adding C++ member constructor
* -------------------------------------------------------------------- */
void set_director_ctor_code(Node *n)
{
/* director ctor code is specific for each class */
Delete(director_prot_ctor_code);
director_prot_ctor_code = NewString("");
Node *pn = Swig_methodclass(n);
String *symname = Getattr(pn,"sym:name");
String *name = Copy(symname);
char *cname = Char(name);
if(cname) cname[0] = toupper(cname[0]);
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n",
" rb_raise(rb_eNameError,\"accessing abstract class or protected constructor\"); \n",
" return Qnil;\n",
"}\n", NIL);
Delete(director_ctor_code);
director_ctor_code = NewString("");
Printv(director_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n",
" $nondirector_new \n",
"}\n", NIL);
Delete(name);
}
virtual int constructorHandler(Node *n) {
int use_director = Swig_directorclass(n);
if (use_director) {
set_director_ctor_code(n);
}
/* First wrap the allocate method */
current = CONSTRUCTOR_ALLOCATE;
Swig_name_register((String_or_char *) "construct", (String_or_char *) "%c_allocate");
Language::constructorHandler(n);
/*
* If we're wrapping the constructor of a C++ director class, prepend a new parameter
* to receive the scripting language object (e.g. 'self')
*
*/
Swig_save("ruby:constructorHandler",n,"parms",NIL);
if (use_director) {
Parm *parms = Getattr(n, "parms");
Parm *self;
String *name = NewString("self");
String *type = NewString("VALUE");
self = NewParm(type, name);
Delete(type);
Delete(name);
Setattr(self, "lname", "Qnil");
if (parms) set_nextSibling(self, parms);
Setattr(n, "parms", self);
Setattr(n, "wrap:self", "1");
Delete(self);
}
/* Now do the instance initialize method */
current = CONSTRUCTOR_INITIALIZE;
Swig_name_register((String_or_char *) "construct", (String_or_char *) "new_%c");
Language::constructorHandler(n);
/* Restore original parameter list */
Delattr(n, "wrap:self");
Swig_restore(n);
/* Done */
Swig_name_unregister((String_or_char *) "construct");
current = NO_CPP;
klass->constructor_defined = 1;
return SWIG_OK;
}
virtual int copyconstructorHandler(Node *n) {
int use_director = Swig_directorclass(n);
if (use_director) {
set_director_ctor_code(n);
}
/* First wrap the allocate method */
current = CONSTRUCTOR_ALLOCATE;
Swig_name_register((String_or_char *) "construct", (String_or_char *) "%c_allocate");
return Language::copyconstructorHandler(n);
}
/* ---------------------------------------------------------------------
* destructorHandler()
* -------------------------------------------------------------------- */
virtual int destructorHandler(Node *n) {
current = DESTRUCTOR;
Language::destructorHandler(n);
String *freefunc = NewString("");
String *freebody = NewString("");
String *pname0 = Swig_cparm_name(0,0);
Printv(freefunc, "free_", klass->mname, NIL);
Printv(freebody, "SWIGINTERN void\n",
freefunc, "(", klass->type, " *", pname0, ") {\n",
tab4, NIL);
/* Check to see if object tracking is activated for the class
that owns this destructor. */
Node *pn = Swig_methodclass(n);
if (GetFlag(pn,"feature:trackobjects")) {
Printf(freebody, "SWIG_RubyRemoveTracking(%s);\n", pname0);
Printv(freebody, tab4, NIL);
}
if (Extend) {
String *wrap = Getattr(n, "wrap:code");
if (wrap) {
Printv(f_wrappers, wrap, NIL);
}
/* Printv(freebody, Swig_name_destroy(name), "(", pname0, ")", NIL); */
Printv(freebody,Getattr(n,"wrap:action"), NIL);
} else {
String *action = Getattr(n,"wrap:action");
if (action) {
Printv(freebody, action, NIL);
} else {
/* In the case swig emits no destroy function. */
if (CPlusPlus)
Printf(freebody, "delete %s;\n", pname0);
else
Printf(freebody, "free((char*) %s);\n", pname0);
}
}
Printv(freebody, "}\n\n", NIL);
Printv(f_wrappers, freebody, NIL);
klass->destructor_defined = 1;
current = NO_CPP;
Delete(freefunc);
Delete(freebody);
Delete(pname0);
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* membervariableHandler()
*
* This creates a pair of functions to set/get the variable of a member.
* -------------------------------------------------------------------- */
virtual int membervariableHandler(Node *n) {
current = MEMBER_VAR;
Language::membervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* -----------------------------------------------------------------------
* staticmemberfunctionHandler()
*
* Wrap a static C++ function
* ---------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
current = STATIC_FUNC;
Language::staticmemberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* memberconstantHandler()
*
* Create a C++ constant
* --------------------------------------------------------------------- */
virtual int memberconstantHandler(Node *n) {
current = CLASS_CONST;
Language::memberconstantHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* staticmembervariableHandler()
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
current = STATIC_VAR;
Language::staticmembervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* C++ director class generation */
virtual int classDirector(Node *n) {
return Language::classDirector(n);
}
virtual int classDirectorInit(Node *n) {
String *declaration;
declaration = Swig_director_declaration(n);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "%s\n", declaration);
Printf(f_directors_h, "public:\n");
Delete(declaration);
return Language::classDirectorInit(n);
}
virtual int classDirectorEnd(Node *n) {
Printf(f_directors_h, "};\n\n");
return Language::classDirectorEnd(n);
}
/* ------------------------------------------------------------
* classDirectorConstructor()
* ------------------------------------------------------------ */
virtual int classDirectorConstructor(Node *n) {
Node *parent = Getattr(n, "parentNode");
String *sub = NewString("");
String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent);
String *classname = NewString("");
Printf(classname, "SwigDirector_%s", supername);
/* insert self parameter */
Parm *p;
ParmList *superparms = Getattr(n, "parms");
ParmList *parms = CopyParmList(superparms);
String *type = NewString("VALUE");
p = NewParm(type, NewString("self"));
set_nextSibling(p, parms);
parms = p;
if (!Getattr(n,"defaultargs")) {
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
String *target = Swig_method_decl(decl, classname, parms, 0, 0);
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call);
Delete(target);
Wrapper_print(w, f_directors);
Delete(call);
DelWrapper(w);
}
/* constructor header */
{
String *target = Swig_method_decl(decl, classname, parms, 0, 1);
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
}
Delete(sub);
Delete(classname);
Delete(supername);
Delete(parms);
return Language::classDirectorConstructor(n);
}
/* ------------------------------------------------------------
* classDirectorDefaultConstructor()
* ------------------------------------------------------------ */
virtual int classDirectorDefaultConstructor(Node *n) {
String *classname;
Wrapper *w;
classname = Swig_class_name(n);
w = NewWrapper();
Printf(w->def, "SwigDirector_%s::SwigDirector_%s(VALUE self) : Swig::Director(self) { }", classname, classname);
Wrapper_print(w, f_directors);
DelWrapper(w);
Printf(f_directors_h, " SwigDirector_%s(VALUE self);\n", classname);
Delete(classname);
return Language::classDirectorDefaultConstructor(n);
}
/* ---------------------------------------------------------------
* exceptionSafeMethodCall()
*
* Emit a virtual director method to pass a method call on to the
* underlying Ruby instance.
*
* --------------------------------------------------------------- */
void exceptionSafeMethodCall(String *className, Node *n, Wrapper *w, int argc, String *args) {
Wrapper *body = NewWrapper();
Wrapper *rescue = NewWrapper();
String *methodName = Getattr(n, "sym:name");
String *bodyName = NewStringf("%s_%s_body", className, methodName);
String *rescueName = NewStringf("%s_%s_rescue", className, methodName);
String *depthCountName = NewStringf("%s_%s_call_depth", className, methodName);
// Check for an exception typemap of some kind
String *tm = Swig_typemap_lookup_new("director:except", n, "result", 0);
if (!tm) {
tm = Getattr(n, "feature:director:except");
}
if ((tm != 0) && (Len(tm) > 0) && (Strcmp(tm, "1") != 0))
{
// Declare a global to hold the depth count
if (!Getattr(n,"sym:nextSibling")) {
Printf(f_directors, "static int %s = 0;\n", depthCountName);
// Function body
Printf(body->def, "VALUE %s(VALUE data) {\n", bodyName);
Wrapper_add_localv(body, "args", "Swig::body_args *", "args", "= reinterpret_cast<Swig::body_args *>(data)", NIL);
Wrapper_add_localv(body, "result", "VALUE", "result", "= Qnil", NIL);
Printf(body->code, "%s++;\n", depthCountName, NIL);
Printv(body->code, "result = rb_funcall2(args->recv, args->id, args->argc, args->argv);\n", NIL);
Printf(body->code, "%s--;\n", depthCountName, NIL);
Printv(body->code, "return result;\n", NIL);
Printv(body->code, "}", NIL);
// Exception handler
Printf(rescue->def, "VALUE %s(VALUE args, VALUE error) {\n", rescueName);
Replaceall(tm, "$error", "error");
Printf(rescue->code, "if (%s == 1) ", depthCountName);
Printv(rescue->code, Str(tm), "\n", NIL);
Printf(rescue->code, "%s--;\n", depthCountName);
Printv(rescue->code, "rb_exc_raise(error);\n", NIL);
Printv(rescue->code, "}", NIL);
}
// Main code
Wrapper_add_localv(w, "args", "Swig::body_args", "args", NIL);
Wrapper_add_localv(w, "status", "int", "status", NIL);
Printv(w->code, "args.recv = swig_get_self();\n", NIL);
Printf(w->code, "args.id = rb_intern(\"%s\");\n", methodName);
Printf(w->code, "args.argc = %d;\n", argc);
if (argc > 0) {
Printf(w->code, "args.argv = new VALUE[%d];\n", argc);
for (int i = 0; i < argc; i++) {
Printf(w->code, "args.argv[%d] = obj%d;\n", i, i);
}
} else {
Printv(w->code, "args.argv = 0;\n", NIL);
}
Printf(w->code,
"result = rb_protect(PROTECTFUNC(%s), reinterpret_cast<VALUE>(&args), &status);\n", bodyName, rescueName);
Printf(w->code,
"if (status) {\n");
Printf(w->code,
"VALUE lastErr = rb_gv_get(\"$!\");\n");
Printf(w->code,
"%s(reinterpret_cast<VALUE>(&args), lastErr);\n", rescueName);
Printf(w->code, "}\n");
if (argc > 0) {
Printv(w->code, "delete [] args.argv;\n", NIL);
}
// Dump wrapper code
Wrapper_print(body, f_directors);
Wrapper_print(rescue, f_directors);
}
else
{
if (argc > 0) {
Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), %d%s);\n", methodName, argc, args);
} else {
Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), 0, NULL);\n", methodName);
}
}
// Clean up
Delete(bodyName);
Delete(rescueName);
Delete(depthCountName);
DelWrapper(body);
DelWrapper(rescue);
}
virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
int is_void = 0;
int is_pointer = 0;
String *decl;
String *type;
String *name;
String *classname;
String *declaration;
ParmList *l;
Wrapper *w;
String *tm;
String *wrap_args;
String *return_type;
Parm* p;
String *value = Getattr(n, "value");
String *storage = Getattr(n,"storage");
bool pure_virtual = false;
int status = SWIG_OK;
int idx;
if (Cmp(storage,"virtual") == 0) {
if (Cmp(value,"0") == 0) {
pure_virtual = true;
}
}
classname = Getattr(parent, "sym:name");
type = Getattr(n, "type");
name = Getattr(n, "name");
w = NewWrapper();
declaration = NewString("");
/* determine if the method returns a pointer */
decl = Getattr(n, "decl");
is_pointer = SwigType_ispointer_return(decl);
is_void = (!Cmp(type, "void") && !is_pointer);
/* form complete return type */
return_type = Copy(type);
{
SwigType *t = Copy(decl);
SwigType *f = 0;
f = SwigType_pop_function(t);
SwigType_push(return_type, t);
Delete(f);
Delete(t);
}
/* virtual method definition */
l = Getattr(n, "parms");
String *target;
String *pclassname = NewStringf("SwigDirector_%s", classname);
String *qualified_name = NewStringf("%s::%s", pclassname, name);
target = Swig_method_decl(decl, qualified_name, l, 0, 0);
String *rtype = SwigType_str(type, 0);
Printf(w->def, "%s %s", rtype, target);
Delete(qualified_name);
Delete(target);
/* header declaration */
target = Swig_method_decl(decl, name, l, 0, 1);
Printf(declaration, " virtual %s %s", rtype, target);
Delete(target);
// Get any exception classes in the throws typemap
ParmList *throw_parm_list = 0;
if ((throw_parm_list = Getattr(n,"throws")) || Getattr(n,"throw")) {
Parm *p;
int gencomma = 0;
Append(w->def, " throw(");
Append(declaration, " throw(");
if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p=nextSibling(p)) {
if ((tm = Getattr(p,"tmap:throws"))) {
if (gencomma++) {
Append(w->def, ", ");
Append(declaration, ", ");
}
Printf(w->def, "%s", SwigType_str(Getattr(p, "type"),0));
Printf(declaration, "%s", SwigType_str(Getattr(p, "type"),0));
}
}
Append(w->def, ")");
Append(declaration, ")");
}
Append(w->def, " {");
Append(declaration, ";\n");
/* attach typemaps to arguments (C/C++ -> Ruby) */
String *arglist = NewString("");
/**
* For each parameter to the C++ member function, copy the parameter name
* to its "lname"; this ensures that Swig_typemap_attach_parms() will do
* the right thing when it sees strings like "$1" in your "directorin" typemaps.
* Not sure if it's OK to leave it like this, but seems OK so far.
*/
typemap_copy_pname_to_lname(l);
Swig_typemap_attach_parms("in", l, 0);
Swig_typemap_attach_parms("directorin", l, 0);
Swig_typemap_attach_parms("directorargout", l, w);
int num_arguments = emit_num_arguments(l);
int i;
char source[256];
wrap_args = NewString("");
int outputs = 0;
if (!is_void) outputs++;
/* build argument list and type conversion string */
for (i=0, idx=0, p = l; i < num_arguments; i++) {
while (Getattr(p, "tmap:ignore")) {
p = Getattr(p, "tmap:ignore:next");
}
if (Getattr(p, "tmap:directorargout") != 0) outputs++;
String* parameterName = Getattr(p, "name");
String* parameterType = Getattr(p, "type");
Putc(',',arglist);
if ((tm = Getattr(p, "tmap:directorin")) != 0) {
sprintf(source, "obj%d", idx++);
Replaceall(tm, "$input", source);
Replaceall(tm, "$owner", "0");
Printv(wrap_args, tm, "\n", NIL);
Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL);
Printv(arglist, source, NIL);
p = Getattr(p, "tmap:directorin:next");
continue;
} else if (Cmp(parameterType, "void")) {
/**
* Special handling for pointers to other C++ director classes.
* Ideally this would be left to a typemap, but there is currently no
* way to selectively apply the dynamic_cast<> to classes that have
* directors. In other words, the type "SwigDirector_$1_lname" only exists
* for classes with directors. We avoid the problem here by checking
* module.wrap::directormap, but it's not clear how to get a typemap to
* do something similar. Perhaps a new default typemap (in addition
* to SWIGTYPE) called DIRECTORTYPE?
*/
if (SwigType_ispointer(parameterType) || SwigType_isreference(parameterType)) {
Node *modname = Getattr(parent, "module");
Node *target = Swig_directormap(modname, parameterType);
sprintf(source, "obj%d", idx++);
String *nonconst = 0;
/* strip pointer/reference --- should move to Swig/stype.c */
String *nptype = NewString(Char(parameterType)+2);
/* name as pointer */
String *ppname = Copy(parameterName);
if (SwigType_isreference(parameterType)) {
Insert(ppname,0,"&");
}
/* if necessary, cast away const since Ruby doesn't support it! */
if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", parameterName);
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(parameterType, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
"Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(parameterType, parameterName), classname, name);
} else {
nonconst = Copy(ppname);
}
Delete(nptype);
Delete(ppname);
String *mangle = SwigType_manglestr(parameterType);
if (target) {
String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL);
Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(wrap_args, "} else {\n");
Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
Printf(wrap_args, "}\n");
Delete(director);
Printv(arglist, source, NIL);
} else {
Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n",
source, nonconst, mangle);
//Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
// source, nonconst, base);
Printv(arglist, source, NIL);
}
Delete(mangle);
Delete(nonconst);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(parameterType, 0), classname, name);
status = SWIG_NOWRAP;
break;
}
}
p = nextSibling(p);
}
/* declare method return value
* if the return value is a reference or const reference, a specialized typemap must
* handle it, including declaration of c_result ($result).
*/
if (!is_void) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
}
/* declare Ruby return value */
Wrapper_add_local(w, "result", "VALUE result");
/* direct call to superclass if _up is set */
Printf(w->code, "if (swig_get_up()) {\n");
if (pure_virtual) {
Printf(w->code, "throw Swig::DirectorPureVirtualException();\n");
} else {
if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l));
Printf(w->code, "return;\n");
} else {
Printf(w->code, "return %s;\n", Swig_method_call(super,l));
}
}
Printf(w->code, "}\n");
/* wrap complex arguments to VALUEs */
Printv(w->code, wrap_args, NIL);
/* pass the method call on to the Ruby object */
exceptionSafeMethodCall(classname, n, w, idx, arglist);
/*
* Ruby method may return a simple object, or an Array of objects.
* For in/out arguments, we have to extract the appropriate VALUEs from the Array,
* then marshal everything back to C/C++ (return value and output arguments).
*/
/* Marshal return value and other outputs (if any) from VALUE to C/C++ type */
String* cleanup = NewString("");
String* outarg = NewString("");
if (outputs > 1) {
Wrapper_add_local(w, "output", "VALUE output");
Printf(w->code, "if (TYPE(result) != T_ARRAY) {\n");
Printf(w->code, "throw Swig::DirectorTypeMismatchException(\"Ruby method failed to return an array.\");\n");
Printf(w->code, "}\n");
}
idx = 0;
/* Marshal return value */
if (!is_void) {
/* This seems really silly. The node's type excludes qualifier/pointer/reference markers,
* which have to be retrieved from the decl field to construct return_type. But the typemap
* lookup routine uses the node's type, so we have to swap in and out the correct type.
* It's not just me, similar silliness also occurs in Language::cDeclaration().
*/
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup_new("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = rb_ary_entry(result, %d);\n", idx++);
Replaceall(tm, "$input", "output");
} else {
Replaceall(tm, "$input", "result");
}
/* TODO check this */
if (Getattr(n,"wrap:disown")) {
Replaceall(tm,"$disown","SWIG_POINTER_DISOWN");
} else {
Replaceall(tm,"$disown","0");
}
Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), classname, name);
status = SWIG_ERROR;
}
}
/* Marshal outputs */
for (p = l; p; ) {
if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
if (outputs > 1) {
Printf(w->code, "output = rb_ary_entry(result, %d);\n", idx++);
Replaceall(tm, "$input", "output");
} else {
Replaceall(tm, "$input", "result");
}
Replaceall(tm, "$result", Getattr(p, "name"));
Printv(w->code, tm, "\n", NIL);
p = Getattr(p, "tmap:directorargout:next");
} else {
p = nextSibling(p);
}
}
/* any existing helper functions to handle this? */
if (!is_void) {
String* rettype = SwigType_str(return_type, 0);
if (!SwigType_isreference(return_type)) {
Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
Printf(w->code, "return (%s) *c_result;\n", rettype);
}
Delete(rettype);
}
Printf(w->code, "}\n");
/* emit the director method */
if (status == SWIG_OK) {
if (!Getattr(n,"defaultargs")) {
Wrapper_print(w, f_directors);
Printv(f_directors_h, declaration, NIL);
}
}
/* clean up */
Delete(wrap_args);
Delete(arglist);
Delete(rtype);
Delete(return_type);
Delete(pclassname);
Delete(cleanup);
Delete(outarg);
DelWrapper(w);
return status;
}
virtual int classDirectorConstructors(Node *n) {
return Language::classDirectorConstructors(n);
}
virtual int classDirectorMethods(Node *n) {
return Language::classDirectorMethods(n);
}
virtual int classDirectorDisown(Node *n) {
return Language::classDirectorDisown(n);
}
void typemap_copy_pname_to_lname(ParmList *parms)
{
Parm *p;
String *pname;
String *lname;
p = parms;
while (p) {
pname = Getattr(p,"name");
lname = Copy(pname);
Setattr(p,"lname",lname);
p = nextSibling(p);
}
}
String *runtimeCode() {
String *s = NewString("");
String *shead = Swig_include_sys("rubyhead.swg");
if (!shead) {
Printf(stderr, "*** Unable to open 'rubyhead.swg'\n");
} else {
Append(s, shead);
Delete(shead);
}
String *serrors = Swig_include_sys("rubyerrors.swg");
if (!serrors) {
Printf(stderr, "*** Unable to open 'rubyerrors.swg'\n");
} else {
Append(s, serrors);
Delete(serrors);
}
String *strack = Swig_include_sys("rubytracking.swg");
if (!strack) {
Printf(stderr, "*** Unable to open 'rubytracking.swg'\n");
} else {
Append(s, strack);
Delete(strack);
}
String *sapi = Swig_include_sys("rubyapi.swg");
if (!sapi) {
Printf(stderr, "*** Unable to open 'rubyapi.swg'\n");
} else {
Append(s, sapi);
Delete(sapi);
}
String *srun = Swig_include_sys("rubyrun.swg");
if (!srun) {
Printf(stderr, "*** Unable to open 'rubyrun.swg'\n");
} else {
Append(s, srun);
Delete(srun);
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigrubyrun.h");
}
}; /* class RUBY */
/* -----------------------------------------------------------------------------
* swig_ruby() - Instantiate module
* ----------------------------------------------------------------------------- */
static Language * new_swig_ruby() {
return new RUBY();
}
extern "C" Language * swig_ruby(void) {
return new_swig_ruby();
}
/*
* Local Variables:
* c-basic-offset: 2
* End:
*/
|