/usr/include/octave-4.0.0/octave/symtab.h is in liboctave-dev 4.0.0-3ubuntu9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
Copyright (C) 1993-2015 John W. Eaton
Copyright (C) 2009 VZLU Prague
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#if !defined (octave_symtab_h)
#define octave_symtab_h 1
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include "glob-match.h"
#include "lo-regexp.h"
class tree_argument_list;
class octave_user_function;
#include "oct-obj.h"
#include "workspace-element.h"
#include "oct-refcount.h"
#include "ov.h"
class
OCTINTERP_API
symbol_table
{
public:
typedef int scope_id;
typedef size_t context_id;
class
scope_id_cache
{
protected:
typedef std::set<scope_id>::iterator set_iterator;
typedef std::set<scope_id>::const_iterator set_const_iterator;
// We start with 2 because we allocate 0 for the global symbols
// and 1 for the top-level workspace.
scope_id_cache (void) : next_available (2), in_use (), free_list () { }
public:
~scope_id_cache (void) { }
static scope_id alloc (void)
{
return instance_ok () ? instance->do_alloc () : -1;
}
static void free (scope_id scope)
{
if (instance_ok ())
return instance->do_free (scope);
}
static std::list<scope_id> scopes (void)
{
return instance_ok () ? instance->do_scopes () : std::list<scope_id> ();
}
static void create_instance (void);
static bool instance_ok (void)
{
bool retval = true;
if (! instance)
create_instance ();
if (! instance)
{
::error ("unable to create scope_id_cache object!");
retval = false;
}
return retval;
}
private:
// No copying!
scope_id_cache (const scope_id_cache&);
scope_id_cache& operator = (const scope_id_cache&);
static scope_id_cache *instance;
static void cleanup_instance (void) { delete instance; instance = 0; }
// The next available scope not in the free list.
scope_id next_available;
// The set of scope IDs that are currently allocated.
std::set<scope_id> in_use;
// The set of scope IDs that are currently available.
std::set<scope_id> free_list;
scope_id do_alloc (void)
{
scope_id retval;
set_iterator p = free_list.begin ();
if (p != free_list.end ())
{
retval = *p;
free_list.erase (p);
}
else
retval = next_available++;
in_use.insert (retval);
return retval;
}
void do_free (scope_id scope)
{
set_iterator p = in_use.find (scope);
if (p != in_use.end ())
{
in_use.erase (p);
free_list.insert (scope);
}
else
error ("free_scope: scope %d not found!", scope);
}
std::list<scope_id> do_scopes (void) const
{
std::list<scope_id> retval;
for (set_const_iterator p = in_use.begin (); p != in_use.end (); p++)
retval.push_back (*p);
retval.sort ();
return retval;
}
};
class fcn_info;
class
symbol_record
{
public:
// generic variable
static const unsigned int local = 1;
// varargin, argn, .nargin., .nargout.
// (FIXME -- is this really used now?)
static const unsigned int automatic = 2;
// formal parameter
static const unsigned int formal = 4;
// not listed or cleared (.nargin., .nargout.)
static const unsigned int hidden = 8;
// inherited from parent scope; not cleared at function exit
static const unsigned int inherited = 16;
// global (redirects to global scope)
static const unsigned int global = 32;
// not cleared at function exit
static const unsigned int persistent = 64;
// this symbol may NOT become a variable.
// (symbol added to a static workspace)
static const unsigned int added_static = 128;
private:
class
symbol_record_rep
{
public:
symbol_record_rep (scope_id s, const std::string& nm,
const octave_value& v, unsigned int sc)
: decl_scope (s), curr_fcn (0), name (nm), value_stack (),
storage_class (sc), finfo (), valid (true), count (1)
{
value_stack.push_back (v);
}
void assign (const octave_value& value,
context_id context = xdefault_context)
{
varref (context) = value;
}
void assign (octave_value::assign_op op,
const std::string& type,
const std::list<octave_value_list>& idx,
const octave_value& value,
context_id context = xdefault_context)
{
varref(context).assign (op, type, idx, value);
}
void assign (octave_value::assign_op op, const octave_value& value,
context_id context = xdefault_context)
{
varref(context).assign (op, value);
}
void do_non_const_unary_op (octave_value::unary_op op,
context_id context = xdefault_context)
{
varref(context).do_non_const_unary_op (op);
}
void do_non_const_unary_op (octave_value::unary_op op,
const std::string& type,
const std::list<octave_value_list>& idx,
context_id context = xdefault_context)
{
varref(context).do_non_const_unary_op (op, type, idx);
}
octave_value& varref (context_id context = xdefault_context)
{
// We duplicate global_varref and persistent_varref here to
// avoid calling deprecated functions.
if (is_global ())
{
symbol_table::global_table_iterator p
= symbol_table::global_table.find (name);
return (p == symbol_table::global_table.end ())
? symbol_table::global_table[name] : p->second;
}
else if (is_persistent ())
{
static octave_value foobar;
symbol_table *inst
= symbol_table::get_instance (symbol_table::current_scope ());
return inst ? inst->do_persistent_varref (name) : foobar;
}
else
{
if (context == xdefault_context)
context = active_context ();
context_id n = value_stack.size ();
while (n++ <= context)
value_stack.push_back (octave_value ());
return value_stack[context];
}
}
octave_value varval (context_id context = xdefault_context) const
{
if (is_global ())
return symbol_table::global_varval (name);
else if (is_persistent ())
return symbol_table::persistent_varval (name);
else
{
if (context == xdefault_context)
context = active_context ();
if (context < value_stack.size ())
return value_stack[context];
else
return octave_value ();
}
}
void push_context (scope_id s)
{
if (! (is_persistent () || is_global ())
&& s == scope ())
value_stack.push_back (octave_value ());
}
// If pop_context returns 0, we are out of values and this element
// of the symbol table should be deleted. This can happen for
// functions like
//
// function foo (n)
// if (n > 0)
// foo (n-1);
// else
// eval ("x = 1");
// endif
// endfunction
//
// Here, X should only exist in the final stack frame.
size_t pop_context (scope_id s)
{
size_t retval = 1;
if (! (is_persistent () || is_global ())
&& s == scope ())
{
value_stack.pop_back ();
retval = value_stack.size ();
}
return retval;
}
void clear (void) { clear (scope ()); }
void clear (scope_id s)
{
if (! (is_hidden () || is_inherited ())
&& s == scope ())
{
if (is_global ())
unmark_global ();
if (is_persistent ())
{
symbol_table::persistent_assign (name, varval ());
unmark_persistent ();
}
assign (octave_value ());
}
}
bool is_defined (context_id context = xdefault_context) const
{
if (context == xdefault_context)
context = active_context ();
return varval (context).is_defined ();
}
bool is_valid (void) const
{
return valid;
}
bool is_variable (context_id context) const
{
if (context == xdefault_context)
context = active_context ();
return (! is_local () || is_defined (context));
}
bool is_local (void) const { return storage_class & local; }
bool is_automatic (void) const { return storage_class & automatic; }
bool is_formal (void) const { return storage_class & formal; }
bool is_hidden (void) const { return storage_class & hidden; }
bool is_inherited (void) const { return storage_class & inherited; }
bool is_global (void) const { return storage_class & global; }
bool is_persistent (void) const { return storage_class & persistent; }
bool is_added_static (void) const {return storage_class & added_static; }
void mark_local (void) { storage_class |= local; }
void mark_automatic (void) { storage_class |= automatic; }
void mark_formal (void) { storage_class |= formal; }
void mark_hidden (void) { storage_class |= hidden; }
void mark_inherited (void) { storage_class |= inherited; }
void mark_global (void)
{
if (is_persistent ())
error ("can't make persistent variable %s global", name.c_str ());
else
storage_class |= global;
}
void mark_persistent (void)
{
if (is_global ())
error ("can't make global variable %s persistent", name.c_str ());
else
storage_class |= persistent;
}
void mark_added_static (void) { storage_class |= added_static; }
void unmark_local (void) { storage_class &= ~local; }
void unmark_automatic (void) { storage_class &= ~automatic; }
void unmark_formal (void) { storage_class &= ~formal; }
void unmark_hidden (void) { storage_class &= ~hidden; }
void unmark_inherited (void) { storage_class &= ~inherited; }
void unmark_global (void) { storage_class &= ~global; }
void unmark_persistent (void) { storage_class &= ~persistent; }
void unmark_added_static (void) { storage_class &= ~added_static; }
void init_persistent (void)
{
if (! is_defined ())
{
mark_persistent ();
assign (symbol_table::persistent_varval (name));
}
// FIXME: this causes trouble with recursive calls.
// else
// error ("unable to declare existing variable persistent");
}
void invalidate (void)
{
valid = false;
}
void erase_persistent (void)
{
unmark_persistent ();
symbol_table::erase_persistent (name);
}
OCTINTERP_API context_id active_context (void) const;
scope_id scope (void) const { return decl_scope; }
void set_curr_fcn (octave_user_function *fcn)
{
curr_fcn = fcn;
}
symbol_record_rep *dup (scope_id new_scope) const
{
return new symbol_record_rep (new_scope, name, varval (),
storage_class);
}
void dump (std::ostream& os, const std::string& prefix) const;
scope_id decl_scope;
octave_user_function* curr_fcn;
std::string name;
std::deque<octave_value> value_stack;
unsigned int storage_class;
fcn_info *finfo;
bool valid;
octave_refcount<size_t> count;
private:
// No copying!
symbol_record_rep (const symbol_record_rep& ov);
symbol_record_rep& operator = (const symbol_record_rep&);
};
public:
symbol_record (scope_id s = xcurrent_scope,
const std::string& nm = std::string (),
const octave_value& v = octave_value (),
unsigned int sc = local)
: rep (new symbol_record_rep (s, nm, v, sc)) { }
symbol_record (const symbol_record& sr)
: rep (sr.rep)
{
rep->count++;
}
symbol_record& operator = (const symbol_record& sr)
{
if (this != &sr)
{
if (--rep->count == 0)
delete rep;
rep = sr.rep;
rep->count++;
}
return *this;
}
~symbol_record (void)
{
if (--rep->count == 0)
delete rep;
}
symbol_record dup (scope_id new_scope) const
{
return symbol_record (rep->dup (new_scope));
}
const std::string& name (void) const { return rep->name; }
void rename (const std::string& new_name) { rep->name = new_name; }
octave_value
find (const octave_value_list& args = octave_value_list ()) const;
void assign (const octave_value& value,
context_id context = xdefault_context)
{
rep->assign (value, context);
}
void assign (octave_value::assign_op op,
const std::string& type,
const std::list<octave_value_list>& idx,
const octave_value& value,
context_id context = xdefault_context)
{
rep->assign (op, type, idx, value, context);
}
void assign (octave_value::assign_op op, const octave_value& value,
context_id context = xdefault_context)
{
rep->assign (op, value, context);
}
void do_non_const_unary_op (octave_value::unary_op op)
{
rep->do_non_const_unary_op (op);
}
void do_non_const_unary_op (octave_value::unary_op op,
const std::string& type,
const std::list<octave_value_list>& idx)
{
rep->do_non_const_unary_op (op, type, idx);
}
// Delete when deprecated varref functions are removed.
octave_value& varref (context_id context = xdefault_context)
{
return rep->varref (context);
}
octave_value varval (context_id context = xdefault_context) const
{
return rep->varval (context);
}
void push_context (scope_id s) { rep->push_context (s); }
size_t pop_context (scope_id s) { return rep->pop_context (s); }
void clear (void) { rep->clear (); }
void clear (scope_id s) { rep->clear (s); }
bool is_defined (context_id context = xdefault_context) const
{
return rep->is_defined (context);
}
bool is_undefined (context_id context = xdefault_context) const
{
return ! rep->is_defined (context);
}
bool is_valid (void) const
{
return rep->is_valid ();
}
bool is_variable (context_id context = xdefault_context) const
{
return rep->is_variable (context);
}
bool is_local (void) const { return rep->is_local (); }
bool is_automatic (void) const { return rep->is_automatic (); }
bool is_formal (void) const { return rep->is_formal (); }
bool is_global (void) const { return rep->is_global (); }
bool is_hidden (void) const { return rep->is_hidden (); }
bool is_inherited (void) const { return rep->is_inherited (); }
bool is_persistent (void) const { return rep->is_persistent (); }
bool is_added_static (void) const { return rep->is_added_static (); }
void mark_local (void) { rep->mark_local (); }
void mark_automatic (void) { rep->mark_automatic (); }
void mark_formal (void) { rep->mark_formal (); }
void mark_hidden (void) { rep->mark_hidden (); }
void mark_inherited (void) { rep->mark_inherited (); }
void mark_global (void) { rep->mark_global (); }
void mark_persistent (void) { rep->mark_persistent (); }
void mark_added_static (void) { rep->mark_added_static (); }
void unmark_local (void) { rep->unmark_local (); }
void unmark_automatic (void) { rep->unmark_automatic (); }
void unmark_formal (void) { rep->unmark_formal (); }
void unmark_hidden (void) { rep->unmark_hidden (); }
void unmark_inherited (void) { rep->unmark_inherited (); }
void unmark_global (void) { rep->unmark_global (); }
void unmark_persistent (void) { rep->unmark_persistent (); }
void unmark_added_static (void) { rep->unmark_added_static (); }
void init_persistent (void) { rep->init_persistent (); }
void erase_persistent (void) { rep->erase_persistent (); }
void invalidate (void) { rep->invalidate (); }
context_id active_context (void) const { return rep->active_context (); }
scope_id scope (void) const { return rep->scope (); }
unsigned int xstorage_class (void) const { return rep->storage_class; }
void set_curr_fcn (octave_user_function *fcn) { rep->set_curr_fcn (fcn); }
void
dump (std::ostream& os, const std::string& prefix = std::string ()) const
{
rep->dump (os, prefix);
}
private:
symbol_record_rep *rep;
symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { }
};
// Always access a symbol from the current scope.
// Useful for scripts, as they may be executed in more than one scope.
class
symbol_reference
{
public:
symbol_reference (void) : scope (-1) { }
symbol_reference (const symbol_record& record,
scope_id curr_scope = symbol_table::current_scope ())
: scope (curr_scope), sym (record)
{ }
symbol_reference (const symbol_reference& ref)
: scope (ref.scope), sym (ref.sym)
{ }
symbol_reference& operator = (const symbol_reference& ref)
{
if (this != &ref)
{
scope = ref.scope;
sym = ref.sym;
}
return *this;
}
bool is_black_hole (void) const { return scope < 0; }
// The name is the same regardless of scope.
const std::string& name (void) const { return sym.name (); }
symbol_record *operator-> (void)
{
update ();
return &sym;
}
symbol_record *operator-> (void) const
{
update ();
return &sym;
}
// can be used to place symbol_reference in maps, we don't overload < as
// it doesn't make any sense for symbol_reference
struct comparator
{
bool operator ()(const symbol_reference& lhs,
const symbol_reference& rhs) const
{
return lhs.name () < rhs.name ();
}
};
private:
void update (void) const
{
scope_id curr_scope = symbol_table::current_scope ();
if (scope != curr_scope || ! sym.is_valid ())
{
scope = curr_scope;
sym = symbol_table::insert (sym.name ());
}
}
mutable scope_id scope;
mutable symbol_record sym;
};
class
fcn_info
{
public:
typedef std::map<std::string, std::string> dispatch_map_type;
typedef std::map<scope_id, octave_value>::const_iterator
scope_val_const_iterator;
typedef std::map<scope_id, octave_value>::iterator scope_val_iterator;
typedef std::map<std::string, octave_value>::const_iterator
str_val_const_iterator;
typedef std::map<std::string, octave_value>::iterator str_val_iterator;
typedef dispatch_map_type::const_iterator dispatch_map_const_iterator;
typedef dispatch_map_type::iterator dispatch_map_iterator;
private:
class
fcn_info_rep
{
public:
fcn_info_rep (const std::string& nm)
: name (nm), package_name (), subfunctions (), private_functions (),
class_constructors (), class_methods (), dispatch_map (),
cmdline_function (), autoload_function (), function_on_path (),
built_in_function (), count (1)
{
size_t pos = name.rfind ('.');
if (pos != std::string::npos)
{
package_name = name.substr (0, pos);
name = name.substr (pos+1);
}
}
octave_value load_private_function (const std::string& dir_name);
octave_value load_class_constructor (void);
octave_value load_class_method (const std::string& dispatch_type);
octave_value find (const octave_value_list& args, bool local_funcs);
octave_value builtin_find (void);
octave_value find_method (const std::string& dispatch_type);
octave_value find_autoload (void);
octave_value find_package (void);
octave_value find_user_function (void);
bool is_user_function_defined (void) const
{
return function_on_path.is_defined ();
}
octave_value find_function (const octave_value_list& args,
bool local_funcs)
{
return find (args, local_funcs);
}
void lock_subfunction (scope_id scope)
{
scope_val_iterator p = subfunctions.find (scope);
if (p != subfunctions.end ())
p->second.lock ();
}
void unlock_subfunction (scope_id scope)
{
scope_val_iterator p = subfunctions.find (scope);
if (p != subfunctions.end ())
p->second.unlock ();
}
std::pair<std::string, octave_value>
subfunction_defined_in_scope (scope_id scope) const
{
scope_val_const_iterator p = subfunctions.find (scope);
return p == subfunctions.end ()
? std::pair<std::string, octave_value> ()
: std::pair<std::string, octave_value> (name, p->second);
}
void erase_subfunction (scope_id scope)
{
scope_val_iterator p = subfunctions.find (scope);
if (p != subfunctions.end ())
subfunctions.erase (p);
}
void mark_subfunction_in_scope_as_private (scope_id scope,
const std::string& class_name);
void install_cmdline_function (const octave_value& f)
{
cmdline_function = f;
}
void install_subfunction (const octave_value& f, scope_id scope)
{
subfunctions[scope] = f;
}
void install_user_function (const octave_value& f)
{
function_on_path = f;
}
void install_built_in_function (const octave_value& f)
{
built_in_function = f;
}
template <class T>
void
clear_map (std::map<T, octave_value>& map, bool force = false)
{
typename std::map<T, octave_value>::iterator p = map.begin ();
while (p != map.end ())
{
if (force || ! p->second.islocked ())
map.erase (p++);
else
p++;
}
}
void clear_autoload_function (bool force = false)
{
if (force || ! autoload_function.islocked ())
autoload_function = octave_value ();
}
// We also clear command line functions here, as these are both
// "user defined"
void clear_user_function (bool force = false)
{
if (force || ! function_on_path.islocked ())
function_on_path = octave_value ();
if (force || ! cmdline_function.islocked ())
cmdline_function = octave_value ();
}
void clear_mex_function (void)
{
if (function_on_path.is_mex_function ())
clear_user_function ();
}
void clear_package (void)
{
package = octave_value ();
}
void clear (bool force = false)
{
clear_map (subfunctions, force);
clear_map (private_functions, force);
clear_map (class_constructors, force);
clear_map (class_methods, force);
clear_autoload_function (force);
clear_user_function (force);
clear_package ();
}
void add_dispatch (const std::string& type, const std::string& fname)
{
dispatch_map[type] = fname;
}
void clear_dispatch (const std::string& type)
{
dispatch_map_iterator p = dispatch_map.find (type);
if (p != dispatch_map.end ())
dispatch_map.erase (p);
}
void print_dispatch (std::ostream& os) const;
std::string help_for_dispatch (void) const;
dispatch_map_type get_dispatch (void) const { return dispatch_map; }
void dump (std::ostream& os, const std::string& prefix) const;
std::string full_name (void) const
{
if (package_name.empty ())
return name;
else
return package_name + "." + name;
}
std::string name;
std::string package_name;
// Scope id to function object.
std::map<scope_id, octave_value> subfunctions;
// Directory name to function object.
std::map<std::string, octave_value> private_functions;
// Class name to function object.
std::map<std::string, octave_value> class_constructors;
// Dispatch type to function object.
std::map<std::string, octave_value> class_methods;
// Legacy dispatch map (dispatch type name to function name).
dispatch_map_type dispatch_map;
octave_value cmdline_function;
octave_value autoload_function;
octave_value function_on_path;
octave_value package;
octave_value built_in_function;
octave_refcount<size_t> count;
private:
octave_value xfind (const octave_value_list& args, bool local_funcs);
octave_value x_builtin_find (void);
// No copying!
fcn_info_rep (const fcn_info_rep&);
fcn_info_rep& operator = (const fcn_info_rep&);
};
public:
fcn_info (const std::string& nm = std::string ())
: rep (new fcn_info_rep (nm)) { }
fcn_info (const fcn_info& fi) : rep (fi.rep)
{
rep->count++;
}
fcn_info& operator = (const fcn_info& fi)
{
if (this != &fi)
{
if (--rep->count == 0)
delete rep;
rep = fi.rep;
rep->count++;
}
return *this;
}
~fcn_info (void)
{
if (--rep->count == 0)
delete rep;
}
octave_value find (const octave_value_list& args = octave_value_list (),
bool local_funcs = true)
{
return rep->find (args, local_funcs);
}
octave_value builtin_find (void)
{
return rep->builtin_find ();
}
octave_value find_method (const std::string& dispatch_type) const
{
return rep->find_method (dispatch_type);
}
octave_value find_built_in_function (void) const
{
return rep->built_in_function;
}
octave_value find_cmdline_function (void) const
{
return rep->cmdline_function;
}
octave_value find_autoload (void)
{
return rep->find_autoload ();
}
octave_value find_user_function (void)
{
return rep->find_user_function ();
}
bool is_user_function_defined (void) const
{
return rep->is_user_function_defined ();
}
octave_value find_function (const octave_value_list& args
= octave_value_list (),
bool local_funcs = true)
{
return rep->find_function (args, local_funcs);
}
void lock_subfunction (scope_id scope)
{
rep->lock_subfunction (scope);
}
void unlock_subfunction (scope_id scope)
{
rep->unlock_subfunction (scope);
}
std::pair<std::string, octave_value>
subfunction_defined_in_scope (scope_id scope = xcurrent_scope) const
{
return rep->subfunction_defined_in_scope (scope);
}
void erase_subfunction (scope_id scope)
{
rep->erase_subfunction (scope);
}
void mark_subfunction_in_scope_as_private (scope_id scope,
const std::string& class_name)
{
rep->mark_subfunction_in_scope_as_private (scope, class_name);
}
void install_cmdline_function (const octave_value& f)
{
rep->install_cmdline_function (f);
}
void install_subfunction (const octave_value& f, scope_id scope)
{
rep->install_subfunction (f, scope);
}
void install_user_function (const octave_value& f)
{
rep->install_user_function (f);
}
void install_built_in_function (const octave_value& f)
{
rep->install_built_in_function (f);
}
void clear (bool force = false) { rep->clear (force); }
void clear_user_function (bool force = false)
{
rep->clear_user_function (force);
}
void clear_autoload_function (bool force = false)
{
rep->clear_autoload_function (force);
}
void clear_mex_function (void) { rep->clear_mex_function (); }
void add_dispatch (const std::string& type, const std::string& fname)
{
rep->add_dispatch (type, fname);
}
void clear_dispatch (const std::string& type)
{
rep->clear_dispatch (type);
}
void print_dispatch (std::ostream& os) const
{
rep->print_dispatch (os);
}
std::string help_for_dispatch (void) const
{ return rep->help_for_dispatch (); }
dispatch_map_type get_dispatch (void) const
{
return rep->get_dispatch ();
}
void
dump (std::ostream& os, const std::string& prefix = std::string ()) const
{
rep->dump (os, prefix);
}
private:
fcn_info_rep *rep;
};
static scope_id global_scope (void) { return xglobal_scope; }
static scope_id top_scope (void) { return xtop_scope; }
static scope_id current_scope (void) { return xcurrent_scope; }
static context_id current_context (void) { return xcurrent_context; }
static scope_id alloc_scope (void) { return scope_id_cache::alloc (); }
static void set_scope (scope_id scope)
{
if (scope == xglobal_scope)
error ("can't set scope to global");
else if (scope != xcurrent_scope)
{
all_instances_iterator p = all_instances.find (scope);
if (p == all_instances.end ())
{
symbol_table *inst = new symbol_table (scope);
if (inst)
all_instances[scope] = instance = inst;
}
else
instance = p->second;
xcurrent_scope = scope;
xcurrent_context = 0;
}
}
static void set_scope_and_context (scope_id scope, context_id context)
{
if (scope == xglobal_scope)
error ("can't set scope to global");
else
{
if (scope != xcurrent_scope)
{
all_instances_iterator p = all_instances.find (scope);
if (p == all_instances.end ())
error ("scope not found!");
else
{
instance = p->second;
xcurrent_scope = scope;
xcurrent_context = context;
}
}
else
xcurrent_context = context;
}
}
static void erase_scope (scope_id scope)
{
assert (scope != xglobal_scope);
erase_subfunctions_in_scope (scope);
all_instances_iterator p = all_instances.find (scope);
if (p != all_instances.end ())
{
delete p->second;
all_instances.erase (p);
free_scope (scope);
}
}
static void erase_subfunctions_in_scope (scope_id scope)
{
for (fcn_table_iterator q = fcn_table.begin (); q != fcn_table.end (); q++)
q->second.erase_subfunction (scope);
}
static void
mark_subfunctions_in_scope_as_private (scope_id scope,
const std::string& class_name)
{
for (fcn_table_iterator q = fcn_table.begin (); q != fcn_table.end (); q++)
q->second.mark_subfunction_in_scope_as_private (scope, class_name);
}
static scope_id dup_scope (scope_id scope)
{
scope_id retval = -1;
symbol_table *inst = get_instance (scope);
if (inst)
{
scope_id new_scope = alloc_scope ();
symbol_table *new_symbol_table = new symbol_table (scope);
if (new_symbol_table)
{
all_instances[new_scope] = new_symbol_table;
inst->do_dup_scope (*new_symbol_table);
retval = new_scope;
}
}
return retval;
}
static std::list<scope_id> scopes (void)
{
return scope_id_cache::scopes ();
}
static symbol_record
find_symbol (const std::string& name, scope_id scope = xcurrent_scope)
{
symbol_table *inst = get_instance (scope);
return inst ? inst->do_find_symbol (name) :
symbol_record (scope);
}
static void
inherit (scope_id scope, scope_id donor_scope, context_id donor_context)
{
symbol_table *inst = get_instance (scope);
if (inst)
{
symbol_table *donor_symbol_table = get_instance (donor_scope);
if (donor_symbol_table)
inst->do_inherit (*donor_symbol_table, donor_context);
}
}
static bool at_top_level (void) { return xcurrent_scope == xtop_scope; }
// Find a value corresponding to the given name in the table.
static octave_value
find (const std::string& name,
const octave_value_list& args = octave_value_list (),
bool skip_variables = false,
bool local_funcs = true);
static octave_value builtin_find (const std::string& name);
// Insert a new name in the table.
static symbol_record& insert (const std::string& name,
scope_id scope = xcurrent_scope)
{
static symbol_record foobar;
symbol_table *inst = get_instance (scope);
return inst ? inst->do_insert (name) : foobar;
}
static void rename (const std::string& old_name,
const std::string& new_name,
scope_id scope = xcurrent_scope)
{
symbol_table *inst = get_instance (scope);
if (inst)
inst->do_rename (old_name, new_name);
}
static void assign (const std::string& name,
const octave_value& value = octave_value (),
scope_id scope = xcurrent_scope,
context_id context = xdefault_context,
bool force_add = false)
{
static octave_value foobar;
symbol_table *inst = get_instance (scope);
if (inst)
inst->do_assign (name, value, context, force_add);
}
// Use assign (name, value, scope, context, force_add) instead.
static octave_value&
varref (const std::string& name, scope_id scope = xcurrent_scope,
context_id context = xdefault_context, bool force_add = false)
GCC_ATTR_DEPRECATED
{
static octave_value foobar;
symbol_table *inst = get_instance (scope);
return inst ? inst->do_varref (name, context, force_add) : foobar;
}
// Convenience function to simplify
// octave_user_function::bind_automatic_vars
static void force_assign (const std::string& name,
const octave_value& value = octave_value (),
scope_id scope = xcurrent_scope,
context_id context = xdefault_context)
{
assign (name, value, scope, context, true);
}
// Use force_assign (name, value, scope, context) instead.
static octave_value&
force_varref (const std::string& name, scope_id scope = xcurrent_scope,
context_id context = xdefault_context) GCC_ATTR_DEPRECATED
{
static octave_value foobar;
symbol_table *inst = get_instance (scope);
return inst ? inst->do_varref (name, context, true) : foobar;
}
static octave_value varval (const std::string& name,
scope_id scope = xcurrent_scope,
context_id context = xdefault_context)
{
symbol_table *inst = get_instance (scope);
return inst ? inst->do_varval (name, context) : octave_value ();
}
static void
global_assign (const std::string& name,
const octave_value& value = octave_value ())
{
global_table_iterator p = global_table.find (name);
if (p == global_table.end ())
global_table[name] = value;
else
p->second = value;
}
// Use global_assign (name, value) instead.
static octave_value&
global_varref (const std::string& name) GCC_ATTR_DEPRECATED
{
global_table_iterator p = global_table.find (name);
return (p == global_table.end ()) ? global_table[name] : p->second;
}
static octave_value
global_varval (const std::string& name)
{
global_table_const_iterator p = global_table.find (name);
return (p != global_table.end ()) ? p->second : octave_value ();
}
static void
top_level_assign (const std::string& name,
const octave_value& value = octave_value ())
{
assign (name, value, top_scope (), 0);
}
// Use top_level_assign (name, value) instead.
static octave_value&
top_level_varref (const std::string& name) GCC_ATTR_DEPRECATED
{
static octave_value foobar;
symbol_table *inst = get_instance (top_scope ());
return inst ? inst->do_varref (name, 0, true) : foobar;
}
static octave_value
top_level_varval (const std::string& name)
{
return varval (name, top_scope (), 0);
}
static void
persistent_assign (const std::string& name,
const octave_value& value = octave_value ())
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_persistent_assign (name, value);
}
// Use persistent_assign (name, value) instead.
static octave_value& persistent_varref (const std::string& name)
GCC_ATTR_DEPRECATED
{
static octave_value foobar;
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_persistent_varref (name) : foobar;
}
static octave_value persistent_varval (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_persistent_varval (name) : octave_value ();
}
static void erase_persistent (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_erase_persistent (name);
}
static bool is_variable (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_is_variable (name) : false;
}
static bool
is_built_in_function_name (const std::string& name)
{
octave_value val = find_built_in_function (name);
return val.is_defined ();
}
static octave_value
find_method (const std::string& name, const std::string& dispatch_type)
{
fcn_table_const_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
return p->second.find_method (dispatch_type);
else
{
fcn_info finfo (name);
octave_value fcn = finfo.find_method (dispatch_type);
if (fcn.is_defined ())
fcn_table[name] = finfo;
return fcn;
}
}
static octave_value
find_built_in_function (const std::string& name)
{
fcn_table_const_iterator p = fcn_table.find (name);
return (p != fcn_table.end ())
? p->second.find_built_in_function () : octave_value ();
}
static octave_value
find_autoload (const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
return (p != fcn_table.end ())
? p->second.find_autoload () : octave_value ();
}
static octave_value
find_function (const std::string& name,
const octave_value_list& args = octave_value_list (),
bool local_funcs = true);
static octave_value find_user_function (const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
return (p != fcn_table.end ())
? p->second.find_user_function () : octave_value ();
}
static void install_cmdline_function (const std::string& name,
const octave_value& fcn)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.install_cmdline_function (fcn);
}
else
{
fcn_info finfo (name);
finfo.install_cmdline_function (fcn);
fcn_table[name] = finfo;
}
}
// Install subfunction FCN named NAME. SCOPE is the scope of the
// primary function corresponding to this subfunction.
static void install_subfunction (const std::string& name,
const octave_value& fcn,
scope_id scope)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.install_subfunction (fcn, scope);
}
else
{
fcn_info finfo (name);
finfo.install_subfunction (fcn, scope);
fcn_table[name] = finfo;
}
}
static void install_nestfunction (const std::string& name,
const octave_value& fcn,
scope_id parent_scope);
static void update_nest (scope_id scope)
{
symbol_table *inst = get_instance (scope);
if (inst)
inst->do_update_nest ();
}
static void install_user_function (const std::string& name,
const octave_value& fcn)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.install_user_function (fcn);
}
else
{
fcn_info finfo (name);
finfo.install_user_function (fcn);
fcn_table[name] = finfo;
}
}
static void install_built_in_function (const std::string& name,
const octave_value& fcn)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.install_built_in_function (fcn);
}
else
{
fcn_info finfo (name);
finfo.install_built_in_function (fcn);
fcn_table[name] = finfo;
}
}
static void clear (const std::string& name)
{
clear_variable (name);
}
static void clear_all (bool force = false)
{
clear_variables ();
clear_global_pattern ("*");
clear_functions (force);
}
static void clear_variables (scope_id scope)
{
symbol_table *inst = get_instance (scope);
if (inst)
inst->do_clear_variables ();
}
// This is split for unwind_protect.
static void clear_variables (void)
{
clear_variables (xcurrent_scope);
}
static void clear_objects (scope_id scope = xcurrent_scope)
{
symbol_table *inst = get_instance (scope);
if (inst)
inst->do_clear_objects ();
}
static void clear_functions (bool force = false)
{
for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
p->second.clear (force);
}
static void clear_function (const std::string& name)
{
clear_user_function (name);
}
static void clear_global (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_clear_global (name);
}
static void clear_variable (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_clear_variable (name);
}
static void clear_symbol (const std::string& name)
{
// FIXME: are we supposed to do both here?
clear_variable (name);
clear_function (name);
}
static void clear_function_pattern (const std::string& pat)
{
glob_match pattern (pat);
for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
{
if (pattern.match (p->first))
p->second.clear_user_function ();
}
}
static void clear_global_pattern (const std::string& pat)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_clear_global_pattern (pat);
}
static void clear_variable_pattern (const std::string& pat)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_clear_variable_pattern (pat);
}
static void clear_variable_regexp (const std::string& pat)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_clear_variable_regexp (pat);
}
static void clear_symbol_pattern (const std::string& pat)
{
// FIXME: are we supposed to do both here?
clear_variable_pattern (pat);
clear_function_pattern (pat);
}
static void clear_user_function (const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.clear_user_function ();
}
// FIXME: is this necessary, or even useful?
// else
// error ("clear: no such function '%s'", name.c_str ());
}
// This clears oct and mex files, incl. autoloads.
static void clear_dld_function (const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.clear_autoload_function ();
finfo.clear_user_function ();
}
}
static void clear_mex_functions (void)
{
for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++)
{
fcn_info& finfo = p->second;
finfo.clear_mex_function ();
}
}
static bool set_class_relationship (const std::string& sup_class,
const std::string& inf_class);
static bool is_superiorto (const std::string& a, const std::string& b);
static void alias_built_in_function (const std::string& alias,
const std::string& name)
{
octave_value fcn = find_built_in_function (name);
if (fcn.is_defined ())
{
fcn_info finfo (alias);
finfo.install_built_in_function (fcn);
fcn_table[alias] = finfo;
}
else
panic ("alias: '%s' is undefined", name.c_str ());
}
static void add_dispatch (const std::string& name, const std::string& type,
const std::string& fname)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.add_dispatch (type, fname);
}
else
{
fcn_info finfo (name);
finfo.add_dispatch (type, fname);
fcn_table[name] = finfo;
}
}
static void clear_dispatch (const std::string& name, const std::string& type)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.clear_dispatch (type);
}
}
static void print_dispatch (std::ostream& os, const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
finfo.print_dispatch (os);
}
}
static fcn_info::dispatch_map_type get_dispatch (const std::string& name)
{
fcn_info::dispatch_map_type retval;
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
retval = finfo.get_dispatch ();
}
return retval;
}
static std::string help_for_dispatch (const std::string& name)
{
std::string retval;
fcn_table_iterator p = fcn_table.find (name);
if (p != fcn_table.end ())
{
fcn_info& finfo = p->second;
retval = finfo.help_for_dispatch ();
}
return retval;
}
static void push_context (void)
{
if (xcurrent_scope == xglobal_scope || xcurrent_scope == xtop_scope)
error ("invalid call to xymtab::push_context");
else
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_push_context ();
}
}
static void pop_context (void)
{
if (xcurrent_scope == xglobal_scope || xcurrent_scope == xtop_scope)
error ("invalid call to xymtab::pop_context");
else
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_pop_context ();
}
}
// For unwind_protect.
static void pop_context (void *) { pop_context (); }
static void mark_automatic (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_mark_automatic (name);
}
static void mark_hidden (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_mark_hidden (name);
}
static void mark_global (const std::string& name)
{
symbol_table *inst = get_instance (xcurrent_scope);
if (inst)
inst->do_mark_global (name);
}
// exclude: Storage classes to exclude, you can OR them together
static std::list<symbol_record>
all_variables (scope_id scope = xcurrent_scope,
context_id context = xdefault_context,
bool defined_only = true,
unsigned int exclude = symbol_record::hidden)
{
symbol_table *inst = get_instance (scope);
return inst
? inst->do_all_variables (context, defined_only, exclude)
: std::list<symbol_record> ();
}
static std::list<symbol_record> glob (const std::string& pattern)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_glob (pattern) : std::list<symbol_record> ();
}
static std::list<symbol_record> regexp (const std::string& pattern)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_regexp (pattern) : std::list<symbol_record> ();
}
static std::list<symbol_record> glob_variables (const std::string& pattern)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_glob (pattern, true) : std::list<symbol_record> ();
}
static std::list<symbol_record> regexp_variables (const std::string& pattern)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_regexp (pattern, true) : std::list<symbol_record> ();
}
static std::list<symbol_record>
glob_global_variables (const std::string& pattern)
{
std::list<symbol_record> retval;
glob_match pat (pattern);
for (global_table_const_iterator p = global_table.begin ();
p != global_table.end (); p++)
{
// We generate a list of symbol_record objects so that
// the results from glob_variables and glob_global_variables
// may be handled the same way.
if (pat.match (p->first))
retval.push_back (symbol_record (xglobal_scope,
p->first, p->second,
symbol_record::global));
}
return retval;
}
static std::list<symbol_record>
regexp_global_variables (const std::string& pattern)
{
std::list<symbol_record> retval;
::regexp pat (pattern);
for (global_table_const_iterator p = global_table.begin ();
p != global_table.end (); p++)
{
// We generate a list of symbol_record objects so that
// the results from regexp_variables and regexp_global_variables
// may be handled the same way.
if (pat.is_match (p->first))
retval.push_back (symbol_record (xglobal_scope,
p->first, p->second,
symbol_record::global));
}
return retval;
}
static std::list<symbol_record> glob_variables (const string_vector& patterns)
{
std::list<symbol_record> retval;
size_t len = patterns.length ();
for (size_t i = 0; i < len; i++)
{
std::list<symbol_record> tmp = glob_variables (patterns[i]);
retval.insert (retval.begin (), tmp.begin (), tmp.end ());
}
return retval;
}
static std::list<symbol_record> regexp_variables
(const string_vector& patterns)
{
std::list<symbol_record> retval;
size_t len = patterns.length ();
for (size_t i = 0; i < len; i++)
{
std::list<symbol_record> tmp = regexp_variables (patterns[i]);
retval.insert (retval.begin (), tmp.begin (), tmp.end ());
}
return retval;
}
static std::list<std::string> user_function_names (void)
{
std::list<std::string> retval;
for (fcn_table_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
{
if (p->second.is_user_function_defined ())
retval.push_back (p->first);
}
if (! retval.empty ())
retval.sort ();
return retval;
}
static std::list<std::string> global_variable_names (void)
{
std::list<std::string> retval;
for (global_table_const_iterator p = global_table.begin ();
p != global_table.end (); p++)
retval.push_back (p->first);
retval.sort ();
return retval;
}
static std::list<std::string> top_level_variable_names (void)
{
symbol_table *inst = get_instance (xtop_scope);
return inst ? inst->do_variable_names () : std::list<std::string> ();
}
static std::list<std::string> variable_names (void)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_variable_names () : std::list<std::string> ();
}
static std::list<std::string> built_in_function_names (void)
{
std::list<std::string> retval;
for (fcn_table_const_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
{
octave_value fcn = p->second.find_built_in_function ();
if (fcn.is_defined ())
retval.push_back (p->first);
}
if (! retval.empty ())
retval.sort ();
return retval;
}
static std::list<std::string> cmdline_function_names (void)
{
std::list<std::string> retval;
for (fcn_table_const_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
{
octave_value fcn = p->second.find_cmdline_function ();
if (fcn.is_defined ())
retval.push_back (p->first);
}
if (! retval.empty ())
retval.sort ();
return retval;
}
static bool is_local_variable (const std::string& name)
{
if (xcurrent_scope == xglobal_scope)
return false;
else
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_is_local_variable (name) : false;
}
}
static bool is_global (const std::string& name)
{
if (xcurrent_scope == xglobal_scope)
return true;
else
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst ? inst->do_is_global (name) : false;
}
}
static std::list<workspace_element> workspace_info (void)
{
symbol_table *inst = get_instance (xcurrent_scope);
return inst
? inst->do_workspace_info () : std::list<workspace_element> ();
}
static void dump (std::ostream& os, scope_id scope = xcurrent_scope);
static void dump_global (std::ostream& os);
static void dump_functions (std::ostream& os);
static void cache_name (scope_id scope, const std::string& name)
{
symbol_table *inst = get_instance (scope, false);
if (inst)
inst->do_cache_name (name);
}
static void lock_subfunctions (scope_id scope = xcurrent_scope)
{
for (fcn_table_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
p->second.lock_subfunction (scope);
}
static void unlock_subfunctions (scope_id scope = xcurrent_scope)
{
for (fcn_table_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
p->second.unlock_subfunction (scope);
}
static std::map<std::string, octave_value>
subfunctions_defined_in_scope (scope_id scope = xcurrent_scope)
{
std::map<std::string, octave_value> retval;
for (fcn_table_const_iterator p = fcn_table.begin ();
p != fcn_table.end (); p++)
{
std::pair<std::string, octave_value> tmp
= p->second.subfunction_defined_in_scope (scope);
std::string nm = tmp.first;
if (! nm.empty ())
retval[nm] = tmp.second;
}
return retval;
}
static void free_scope (scope_id scope)
{
if (scope == xglobal_scope || scope == xtop_scope)
error ("can't free global or top-level scopes!");
else
symbol_table::scope_id_cache::free (scope);
}
static void stash_dir_name_for_subfunctions (scope_id scope,
const std::string& dir_name);
static void add_to_parent_map (const std::string& classname,
const std::list<std::string>& parent_list)
{
parent_map[classname] = parent_list;
}
static std::list<std::string>
parent_classes (const std::string& dispatch_type)
{
std::list<std::string> retval;
const_parent_map_iterator it = parent_map.find (dispatch_type);
if (it != parent_map.end ())
retval = it->second;
for (std::list<std::string>::const_iterator lit = retval.begin ();
lit != retval.end (); lit++)
{
// Search for parents of parents and append them to the list.
// FIXME: should we worry about a circular inheritance graph?
std::list<std::string> parents = parent_classes (*lit);
if (! parents.empty ())
retval.insert (retval.end (), parents.begin (), parents.end ());
}
return retval;
}
static octave_user_function *get_curr_fcn (scope_id scope = xcurrent_scope)
{
symbol_table *inst = get_instance (scope);
return inst->curr_fcn;
}
static void set_curr_fcn (octave_user_function *curr_fcn,
scope_id scope = xcurrent_scope)
{
assert (scope != xtop_scope && scope != xglobal_scope);
symbol_table *inst = get_instance (scope);
// FIXME: normally, functions should not usurp each other's scope.
// If for any incredible reason this is needed, call
// set_user_function (0, scope) first. This may cause problems with
// nested functions, as the curr_fcn of symbol_records must be updated.
assert (inst->curr_fcn == 0 || curr_fcn == 0);
inst->curr_fcn = curr_fcn;
}
static void cleanup (void);
private:
// No copying!
symbol_table (const symbol_table&);
symbol_table& operator = (const symbol_table&);
typedef std::map<std::string, symbol_record>::const_iterator
table_const_iterator;
typedef std::map<std::string, symbol_record>::iterator
table_iterator;
typedef std::map<std::string, octave_value>::const_iterator
global_table_const_iterator;
typedef std::map<std::string, octave_value>::iterator
global_table_iterator;
typedef std::map<std::string, octave_value>::const_iterator
persistent_table_const_iterator;
typedef std::map<std::string, octave_value>::iterator
persistent_table_iterator;
typedef std::map<scope_id, symbol_table*>::const_iterator
all_instances_const_iterator;
typedef std::map<scope_id, symbol_table*>::iterator
all_instances_iterator;
typedef std::map<std::string, fcn_info>::const_iterator
fcn_table_const_iterator;
typedef std::map<std::string, fcn_info>::iterator
fcn_table_iterator;
// The scope of this symbol table.
scope_id my_scope;
// Name for this table (usually the file name of the function
// corresponding to the scope);
std::string table_name;
// Map from symbol names to symbol info.
std::map<std::string, symbol_record> table;
// Child nested functions.
std::vector<symbol_table*> nest_children;
// Parent nested function (may be null).
symbol_table *nest_parent;
// The associated user code (may be null).
octave_user_function *curr_fcn;
// If true then no variables can be added.
bool static_workspace;
// Map from names of global variables to values.
static std::map<std::string, octave_value> global_table;
// Map from names of persistent variables to values.
std::map<std::string, octave_value> persistent_table;
// Pointer to symbol table for current scope (variables only).
static symbol_table *instance;
// Map from scope id to symbol table instances.
static std::map<scope_id, symbol_table*> all_instances;
// Map from function names to function info (subfunctions, private
// functions, class constructors, class methods, etc.)
static std::map<std::string, fcn_info> fcn_table;
// Mape from class names to set of classes that have lower
// precedence.
static std::map<std::string, std::set<std::string> > class_precedence_table;
typedef std::map<std::string, std::set<std::string> >::const_iterator
class_precedence_table_const_iterator;
typedef std::map<std::string, std::set<std::string> >::iterator
class_precedence_table_iterator;
// Map from class names to parent class names.
static std::map<std::string, std::list<std::string> > parent_map;
typedef std::map<std::string, std::list<std::string> >::const_iterator
const_parent_map_iterator;
typedef std::map<std::string, std::list<std::string> >::iterator
parent_map_iterator;
static const scope_id xglobal_scope;
static const scope_id xtop_scope;
static scope_id xcurrent_scope;
static context_id xcurrent_context;
static const context_id xdefault_context = static_cast<context_id> (-1);
symbol_table (scope_id scope)
: my_scope (scope), table_name (), table (), nest_children (),
nest_parent (0), curr_fcn (0), static_workspace (false),
persistent_table () { }
~symbol_table (void) { }
static symbol_table *get_instance (scope_id scope, bool create = true)
{
symbol_table *retval = 0;
bool ok = true;
if (scope != xglobal_scope)
{
if (scope == xcurrent_scope)
{
if (! instance && create)
{
symbol_table *inst = new symbol_table (scope);
if (inst)
{
all_instances[scope] = instance = inst;
if (scope == xtop_scope)
instance->do_cache_name ("top-level");
}
}
if (! instance)
ok = false;
retval = instance;
}
else
{
all_instances_iterator p = all_instances.find (scope);
if (p == all_instances.end ())
{
if (create)
{
retval = new symbol_table (scope);
if (retval)
all_instances[scope] = retval;
else
ok = false;
}
else
ok = false;
}
else
retval = p->second;
}
}
if (! ok)
error ("unable to %s symbol_table object for scope %d!",
create ? "create" : "find", scope);
return retval;
}
void add_nest_child (symbol_table& st)
{
assert (!st.nest_parent);
nest_children.push_back (&st);
st.nest_parent = this;
}
void insert_symbol_record (const symbol_record& sr)
{
table[sr.name ()] = sr;
}
void
do_dup_scope (symbol_table& new_symbol_table) const
{
for (table_const_iterator p = table.begin (); p != table.end (); p++)
new_symbol_table.insert_symbol_record (p->second.dup (new_symbol_table
.my_scope));
}
symbol_record do_find_symbol (const std::string& name)
{
table_iterator p = table.find (name);
if (p == table.end ())
return do_insert (name);
else
return p->second;
}
void do_inherit (symbol_table& donor_table, context_id donor_context)
{
for (table_iterator p = table.begin (); p != table.end (); p++)
{
symbol_record& sr = p->second;
if (! (sr.is_automatic () || sr.is_formal ()))
{
std::string nm = sr.name ();
if (nm != "__retval__")
{
octave_value val = donor_table.do_varval (nm, donor_context);
if (val.is_defined ())
{
sr.assign (val, 0);
sr.mark_inherited ();
}
}
}
}
}
static fcn_info *get_fcn_info (const std::string& name)
{
fcn_table_iterator p = fcn_table.find (name);
return p != fcn_table.end () ? &p->second : 0;
}
octave_value
do_find (const std::string& name, const octave_value_list& args,
bool skip_variables, bool local_funcs);
octave_value do_builtin_find (const std::string& name);
symbol_record& do_insert (const std::string& name, bool force_add = false)
{
table_iterator p = table.find (name);
if (p == table.end ())
{
symbol_record ret (my_scope, name);
if (nest_parent && nest_parent->look_nonlocal (name, ret))
return table[name] = ret;
else
{
if (static_workspace && ! force_add)
ret.mark_added_static ();
return table[name] = ret;
}
}
else
return p->second;
}
void do_rename (const std::string& old_name, const std::string& new_name)
{
table_iterator p = table.find (old_name);
if (p != table.end ())
{
symbol_record sr = p->second;
sr.rename (new_name);
table.erase (p);
table[new_name] = sr;
}
}
void do_assign (const std::string& name, const octave_value& value,
context_id context, bool force_add)
{
table_iterator p = table.find (name);
if (p == table.end ())
{
symbol_record& sr = do_insert (name, force_add);
sr.assign (value, context);
}
else
p->second.assign (value, context);
}
// Use do_assign (name, value, context, force_add) instead.
// Delete when deprecated varref functions are removed.
octave_value& do_varref (const std::string& name, context_id context,
bool force_add)
{
table_iterator p = table.find (name);
if (p == table.end ())
{
symbol_record& sr = do_insert (name, force_add);
return sr.varref (context);
}
else
return p->second.varref (context);
}
octave_value do_varval (const std::string& name, context_id context) const
{
table_const_iterator p = table.find (name);
return (p != table.end ()) ? p->second.varval (context) : octave_value ();
}
void do_persistent_assign (const std::string& name, const octave_value& value)
{
persistent_table_iterator p = persistent_table.find (name);
if (p == persistent_table.end ())
persistent_table[name] = value;
else
p->second = value;
}
// Use do_persistent_assign (name, value) instead.
// Delete when deprecated varref functions are removed.
octave_value& do_persistent_varref (const std::string& name)
{
persistent_table_iterator p = persistent_table.find (name);
return (p == persistent_table.end ())
? persistent_table[name] : p->second;
}
octave_value do_persistent_varval (const std::string& name)
{
persistent_table_const_iterator p = persistent_table.find (name);
return (p != persistent_table.end ()) ? p->second : octave_value ();
}
void do_erase_persistent (const std::string& name)
{
persistent_table_iterator p = persistent_table.find (name);
if (p != persistent_table.end ())
persistent_table.erase (p);
}
bool do_is_variable (const std::string& name) const
{
bool retval = false;
table_const_iterator p = table.find (name);
if (p != table.end ())
{
const symbol_record& sr = p->second;
retval = sr.is_variable ();
}
return retval;
}
void do_push_context (void)
{
for (table_iterator p = table.begin (); p != table.end (); p++)
p->second.push_context (my_scope);
}
void do_pop_context (void)
{
table_iterator p = table.begin ();
while (p != table.end ())
{
if (p->second.pop_context (my_scope) == 0)
table.erase (p++);
else
p++;
}
}
void do_clear_variables (void)
{
for (table_iterator p = table.begin (); p != table.end (); p++)
p->second.clear (my_scope);
}
void do_clear_objects (void)
{
for (table_iterator p = table.begin (); p != table.end (); p++)
{
symbol_record& sr = p->second;
octave_value val = sr.varval ();
if (val.is_object ())
p->second.clear (my_scope);
}
}
void do_clear_global (const std::string& name)
{
table_iterator p = table.find (name);
if (p != table.end ())
{
symbol_record& sr = p->second;
if (sr.is_global ())
sr.unmark_global ();
}
global_table_iterator q = global_table.find (name);
if (q != global_table.end ())
global_table.erase (q);
}
void do_clear_variable (const std::string& name)
{
table_iterator p = table.find (name);
if (p != table.end ())
p->second.clear (my_scope);
}
void do_clear_global_pattern (const std::string& pat)
{
glob_match pattern (pat);
for (table_iterator p = table.begin (); p != table.end (); p++)
{
symbol_record& sr = p->second;
if (sr.is_global () && pattern.match (sr.name ()))
sr.unmark_global ();
}
global_table_iterator q = global_table.begin ();
while (q != global_table.end ())
{
if (pattern.match (q->first))
global_table.erase (q++);
else
q++;
}
}
void do_clear_variable_pattern (const std::string& pat)
{
glob_match pattern (pat);
for (table_iterator p = table.begin (); p != table.end (); p++)
{
symbol_record& sr = p->second;
if (sr.is_defined () || sr.is_global ())
{
if (pattern.match (sr.name ()))
sr.clear (my_scope);
}
}
}
void do_clear_variable_regexp (const std::string& pat)
{
::regexp pattern (pat);
for (table_iterator p = table.begin (); p != table.end (); p++)
{
symbol_record& sr = p->second;
if (sr.is_defined () || sr.is_global ())
{
if (pattern.is_match (sr.name ()))
sr.clear (my_scope);
}
}
}
void do_mark_automatic (const std::string& name)
{
do_insert (name).mark_automatic ();
}
void do_mark_hidden (const std::string& name)
{
do_insert (name).mark_hidden ();
}
void do_mark_global (const std::string& name)
{
do_insert (name).mark_global ();
}
std::list<symbol_record>
do_all_variables (context_id context, bool defined_only,
unsigned int exclude) const
{
std::list<symbol_record> retval;
for (table_const_iterator p = table.begin (); p != table.end (); p++)
{
const symbol_record& sr = p->second;
if ((defined_only && ! sr.is_defined (context))
|| (sr.xstorage_class () & exclude))
continue;
retval.push_back (sr);
}
return retval;
}
std::list<symbol_record> do_glob (const std::string& pattern,
bool vars_only = false) const
{
std::list<symbol_record> retval;
glob_match pat (pattern);
for (table_const_iterator p = table.begin (); p != table.end (); p++)
{
if (pat.match (p->first))
{
const symbol_record& sr = p->second;
if (vars_only && ! sr.is_variable ())
continue;
retval.push_back (sr);
}
}
return retval;
}
std::list<symbol_record> do_regexp (const std::string& pattern,
bool vars_only = false) const
{
std::list<symbol_record> retval;
::regexp pat (pattern);
for (table_const_iterator p = table.begin (); p != table.end (); p++)
{
if (pat.is_match (p->first))
{
const symbol_record& sr = p->second;
if (vars_only && ! sr.is_variable ())
continue;
retval.push_back (sr);
}
}
return retval;
}
std::list<std::string> do_variable_names (void)
{
std::list<std::string> retval;
for (table_const_iterator p = table.begin (); p != table.end (); p++)
{
if (p->second.is_variable ())
retval.push_back (p->first);
}
retval.sort ();
return retval;
}
bool do_is_local_variable (const std::string& name) const
{
table_const_iterator p = table.find (name);
return (p != table.end ()
&& ! p->second.is_global ()
&& p->second.is_defined ());
}
bool do_is_global (const std::string& name) const
{
table_const_iterator p = table.find (name);
return p != table.end () && p->second.is_global ();
}
std::list<workspace_element> do_workspace_info (void) const;
void do_dump (std::ostream& os);
void do_cache_name (const std::string& name) { table_name = name; }
void do_update_nest (void);
bool look_nonlocal (const std::string& name, symbol_record& result)
{
table_iterator p = table.find (name);
if (p == table.end ())
{
if (nest_parent)
return nest_parent->look_nonlocal (name, result);
}
else if (! p->second.is_automatic ())
{
result = p->second;
return true;
}
return false;
}
};
extern bool out_of_date_check (octave_value& function,
const std::string& dispatch_type = std::string (),
bool check_relative = true);
extern OCTINTERP_API std::string
get_dispatch_type (const octave_value_list& args);
extern OCTINTERP_API std::string
get_dispatch_type (const octave_value_list& args, builtin_type_t& builtin_type);
#endif
|