1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547
|
/*************************************************************
* This file is part of the Surface Evolver source code. *
* Programmer: Ken Brakke, brakke@susqu.edu *
*************************************************************/
/*****************************************************************
*
* File: yexparse.c
*
* Purpose: To read and parse user commands and functions in algebraic form
* for evolver constraints. Expressions are given
* in algebraic form and parsed with yacc (see command.yac
* and y.tab.c).
*
*/
#include "include.h"
#include "lex.h"
#include "ytab.h"
/*****************************************************************
*
* Function exparse()
*
* Purpose: reading, parsing, checking of algebraic function definition.
* Takes tokens from yylex() until non-expression token.
* Function value is size in bytes of tree.
*
*/
#define LISTMAX 200
struct treenode *list; /* tree */
struct treenode *permlist; /* to use if user doesn't want own copy */
NTYPE listtop; /* first spot reserved for root */
NTYPE maxp;
int listmax; /* allocated */
/* for BREAK and CONTINUE */
#define LOOPMAX 30
int loopdepth;
int loopbase[LOOPMAX];
int using_param_flag; /* so can detect if using boundary parameters */
int exparse ARGS3((maxparam,enode,flag),
int maxparam, /* maximum number of parameters allowed */
struct expnode *enode, /* pointer to storage pointer */
int flag) /* whether to make copy for user */
{
int retval;
struct treenode *old_list = list; /* for nested parsing */
int old_listtop = listtop;
int old_listmax = listmax;
int old_brace_depth = brace_depth;
PROF_START(exparse);
listmax = LISTMAX;
if ( permlist == NULL )
permlist =
(struct treenode *)mycalloc(listmax,sizeof(struct treenode));
maxp = (NTYPE)maxparam;
if ( flag == USERCOPY )
{ enode->start = list =
(struct treenode *)mycalloc(listmax,sizeof(struct treenode));
}
else enode->start = list = permlist;
list[1].type = SETUP_FRAME_;
listtop = 2;
parse_error_flag = 0;
brace_depth = parens = in_quote = 0;
/* unput expression start token for yacc */
tok = EXPRESSION_START_; unput_tok();
using_param_flag = 0;
if ( !const_expr_flag || backquote_flag )
{
/*local_nest_depth = 0;*/
init_local_scope(0);
begin_local_scope();
}
PROF_FINISH(exparse);
PROF_START(yyparse);
retval = yyparse(); /* 0 for accept, 1 for error */
PROF_FINISH(yyparse);
PROF_START(exparse);
if ( !const_expr_flag || backquote_flag )
{ end_local_scope();
enode->locals = localbase;
if ( localbase )
localbase->flags |= LL_IN_USE;
exit_local_scope();
}
if ( (tok != 0) && (tok != ',') && (tok != LEXERROR) )
{
/* push back last token */
unput_tok();
}
if ( (retval == 1) || parse_error_flag || (listtop == 1) )
{ if ( flag == USERCOPY )
{ myfree((char *)enode->start);
if ( enode->start == list ) list = NULL;
if ( enode->start == permlist ) permlist = NULL;
}
enode->start = NULL;
retval = -1;
goto exparse_exit;
}
/* free excess list */
if ( flag == USERCOPY )
enode->start = list = (struct treenode *)kb_realloc((char *)list,
(listtop+2)*sizeof(struct treenode));
enode->root = list + listtop - 1;
list[0] = list[listtop-1]; /* root also in first spot */
list[0].left += listtop - 1;
list[0].right += listtop - 1;
/* put DONE marker after root */
list[listtop++].type = FINISHED;
/* figure stack usage */
stack_usage(enode);
enode->flag = flag;
if ( using_param_flag )
enode->flag |= USING_PARAM_FLAG;
retval = listtop*sizeof(struct treenode);
list = old_list; /* for nested parsing */
listtop = old_listtop;
listmax = old_listmax;
brace_depth = old_brace_depth;
exparse_exit:
PROF_FINISH(exparse);
return retval;
}
/*********************************************************************
*
* Function: free_expr()
*
* Purpose: Deallocate lists of expression.
*
*/
void free_expr ARGS1((ex),
struct expnode *ex)
{
if ( ex == NULL ) return;
if ( ex->flag == NOUSERCOPY ) return;
if ( ex->start )
{
struct treenode *node;
for ( node = ex->start ; node != ex->root ; node ++ )
{
#ifdef XXXXXXX
/* free local symbol tables ?? */
if ( node->flags & HAS_LOCALLIST )
{ struct locallist_t *locals = node->op5.locals;
if ( locals->list )
{ if ( locals->flags & LL_PERMANENT ) free((char*)locals->list);
else myfree((char*)locals->list);
}
if ( locals->flags & LL_PERMANENT )
free((char*)locals);
else
myfree((char*)locals);
}
#endif
if ( node->flags & HAS_STRING )
myfree(node->op1.string);
if ( node->flags & HAS_STRING_5 )
myfree(node->op5.string);
}
myfree((char *)ex->start);
}
ex->root = NULL;
ex->start = NULL;
if ( ex->locals )
{ myfree((char*)(ex->locals->list));
myfree((char*)(ex->locals));
}
ex->locals = NULL;
}
/*********************************************************************
*
* Function: perm_free_expr()
*
* Purpose: Deallocate lists of permanent expression.
*
*/
void perm_free_expr ARGS1((ex),
struct expnode *ex)
{ struct treenode *node;
if ( ex == NULL ) return;
if ( ex->flag == NOUSERCOPY ) return;
if ( ex->start )
{ for ( node = ex->start ; node != ex->root ; node ++ )
if ( node->flags & HAS_STRING )
free(node->op1.string);
if ( node->flags & HAS_STRING_5 )
free(node->op5.string);
free((char *)ex->start);
}
ex->root = NULL;
ex->start = NULL;
}
/*********************************************************************
*
* Function: makenode()
*
* Purpose: Add nodes to parse tree when called by yyparse.
* Linear order of node list is such that sequential
* execution is postorder. If left > right, then
* subtrees physically swapped, but they must be adjacent.
*
* Return: Index of created node.
*/
void more_makenode ARGS((NTYPE,NTYPE,NTYPE));
int makenode ARGS3((ntype,left,right),
NTYPE ntype, /* type of node */
NTYPE left, /* left son, if any */
NTYPE right) /* right son, if any */
{
short type = (short)ntype;
int i,n;
struct treenode *nnode;
struct global *g;
int etype = -1; /* element type */
if ( listtop > listmax - 10 )
{ list = (struct treenode *)kb_realloc((char*)list,
(listmax+LISTMAX)*sizeof(struct treenode));
listmax += LISTMAX;
}
else
memset((char*)(list+listtop),0,2*sizeof(struct treenode)); /* clear nodes */
switch ( type )
{
case NULLBLOCK_:
list[listtop].type = NULLBLOCK_;
break;
case NULLCMD_:
list[listtop].type = NULLCMD_;
break;
case NOP_:
list[listtop].type = NOP_;
break;
case SUPPRESS_WARNING_:
case UNSUPPRESS_WARNING_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].stack_delta = -1;
break;
case WHEREAMI_COMMAND_:
list[listtop].type = WHEREAMI_COMMAND_;
break;
case SET_BREAKPOINT_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].left = right - listtop;
list[listtop].flags |= EPHEMERAL;
break;
case UNSET_BREAKPOINT_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
if ( right )
list[listtop].left = right - listtop;
list[listtop].flags |= EPHEMERAL;
break;
case BACKQUOTE_START_:
list[listtop].type = type;
break;
case BACKQUOTE_END_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[left].op1.skipsize = right-left+1; /* so START can jump over */
break;
/* command ',' expr */
case ACOMMANDEXPR_:
list[listtop].type = ACOMMANDEXPR_;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].datatype = REAL_TYPE;
break;
/* IF THEN ELSE parse tree
ELSE_
/ \
IF_ command2
/ \
IFTEST_ command1
/
testexpr
sequence: testexpr IFTEST_ command1 IF_ command2 ELSE_
*/
case IFTEST_:
list[listtop].type = IFTEST_;
list[listtop].left = left - listtop; /* test expression */
/* op1 will be offset for jump if condition false */
list[listtop].stack_delta = -1;
break;
case IF_:
list[listtop].type = IF_;
list[listtop].left = left - listtop; /* IFTEST_ */
list[listtop].right = right - listtop; /* THEN command */
list[left].op1.skipsize = listtop - left; /* in IFTEST_ node */
/* op1 will be offset to skip ELSE part */
break;
case ELSE_: /* really the continue node at root of IF tree */
list[listtop].type = ELSE_;
list[listtop].left = left - listtop; /* IF_ node */
if ( right ) list[listtop].right = right - listtop; /* command2 */
list[left].op1.skipsize = listtop - left; /* in IF_ node */
break;
case DECLARE_LOCAL_:
list[listtop].type = DECLARE_LOCAL_;
list[listtop].op1.name_id = left; /* identifier */
globals(left)->flags |= GLOB_LOCALVAR;
/* globals(left)->flags |= ORDINARY_PARAM; */
break;
case LOCAL_LIST_START_:
list[listtop].type = LOCAL_LIST_START_;
list[listtop].left = left-listtop;
break;
case INDEXSET_:
list[listtop].type = INDEXSET_;
/* "left" is previous indexset */
/* "right" is next index expression */
/* note we have to use left pointer if any used at all for
later nodes trying to find start of subtree */
if ( left )
{ /* then left is previous indexlist */
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
list[listtop].op1.indexcount = list[left].op1.indexcount+1;
}
else
{ list[listtop].op1.indexcount = 1;
list[listtop].left = right-listtop;
}
/* Sanity check on index */
if ( list[right].type == PUSHCONST )
{ if ( (int)(list[right].op1.real) < 1 )
{ sprintf(errmsg,"Index %d must be positive.\n",
list[listtop].op1.indexcount);
kb_error(2238,errmsg, COMMAND_ERROR);
}
}
break;
case DIMENSIONSET_:
/* "left" is previous indexset, except in leaf it is index expr */
/* "right" is next index expression, except 0 in leaf */
list[listtop].type = DIMENSIONSET_;
if ( left ) /* have previous dimensionset */
{ list[listtop].left = left-listtop;
list[listtop].op1.indexcount = list[left].op1.indexcount+1;
list[listtop].right = right-listtop;
} else
{ list[listtop].op1.indexcount = 1;
list[listtop].left = right-listtop;
}
/* Sanity check on index */
if ( list[right].type == PUSHCONST )
{ if ( (int)(list[right].op1.real) < 0 ) /* can be 0 in define */
{ sprintf(errmsg,"Index %d must be nonnegative.\n",
list[listtop].op1.indexcount);
kb_error(2522,errmsg, COMMAND_ERROR);
}
}
break;
case SINGLE_ASSIGN_:
/* tree: SINGLE_ASSIGN
/ \
SINGLE_ELEMENT_ SET_ATTRIBUTE_A
/ / \
single expr index expr
*/
list[listtop].type = type;
list[listtop].op1.assigntype = assigntype;
list[listtop].left = left-listtop; /* single element */
list[listtop].right = right-listtop; /* attribute and expression */
list[listtop].stack_delta = -3;
break;
case DEFINE_EXTRA_: /* new element attribute */
list[listtop].type = type;
if ( left ) list[listtop].left = left-listtop; /* dimension expression */
list[listtop].op2.eltype = right; /* element type */
break;
case DEFINE_EXTRA_INDEX_: /* index added to extra attribute */
{ struct extra *ex;
list[listtop].type = type;
list[listtop].left = left-listtop; /* definition header */
list[listtop].right = right-listtop; /* indexset expression */
list[listtop].op1.extranum = list[left].op1.extranum;
list[listtop].op2.eltype = list[left].op2.eltype;
ex = EXTRAS(list[left].op2.eltype) + list[left].op1.extranum;
if ( (ex->array_spec.datacount > 0) && (ex->array_spec.dim != list[right].op1.indexcount) )
{ sprintf(errmsg,"Cannot change number of dimensions of %s\n",
ex->name);
kb_error(4562,errmsg,COMMAND_ERROR);
}
ex->array_spec.dim = list[right].op1.indexcount;
ex->flags |= DIMENSIONED_ATTR;
list[listtop].stack_delta = -ex->array_spec.dim;
}
break;
case ATTR_FUNCTION_: /* attribute function */
list[listtop].type = type;
list[listtop].left = left-listtop; /* main define */
break;
case ATTR_FUNCTION_END_: /* attribute function */
list[listtop].type = type;
list[listtop].left = left-listtop; /* ATTR_FUNCTION node */
list[listtop].right = right-listtop; /* function */
break;
case RETURN_: /* end command */
list[listtop].type = type;
if ( left ) list[listtop].left = left - listtop; /* return expr */
break;
case RESET_COUNTS_: /* set counts back to 0 */
list[listtop].type = type;
break;
case FLUSH_COUNTS_: /* print pending counts */
list[listtop].type = type;
break;
case PAUSE_: /* wait for user */
list[listtop].type = type;
break;
case PRINT_PROFILING_:
case RESET_PROFILING_:
list[listtop].type = type;
break;
case BREAK_:
case CONTINUE_:
list[listtop].type = type;
if ( loopdepth < 1 )
kb_error(1388,"Cannot BREAK or CONTINUE unless inside a loop.\n",
COMMAND_ERROR);
if ( loopdepth < left )
kb_error(1389,"BREAK or CONTINUE out of too many levels.\n",
COMMAND_ERROR);
list[listtop].op1.skipsize = loopbase[loopdepth-left]-listtop;
list[listtop].op2.breakdepth = left;
break;
/* WHILE DO tree: WHILE_END_
/ \
WHILE_TOP_ command
/
testexpr
execution sequence: testexpr WHILE_TOP_ command WHILE_END_
*/
case WHILE_TOP_:
list[listtop].type = WHILE_TOP_;
list[listtop].left = left - listtop;
/* op1 will be offset to after WHILE_END_ */
loopbase[loopdepth++] = listtop;
/* find start of WHILE expression */
for ( n = left ; list[n].left ; n += list[n].left ) ;
list[listtop].op4.contjump = n - listtop - 1; /* for continue */
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
list[listtop].stack_delta = -1;
break;
case WHILE_END_:
list[listtop].type = WHILE_END_;
list[listtop].left = left - listtop; /* test */
list[listtop].right = right - listtop; /* command */
list[left].op1.skipsize = listtop - left; /* jump if test fails */
list[left].op3.breakjump = listtop - left; /* for break */
/* find start of WHILE test expression and set jump back */
for ( n = left ; list[n].left ; n += list[n].left ) ;
list[listtop].op1.skipsize = n - listtop - 1; /* allow increment */
loopdepth--;
if ( loopdepth < 0 )
kb_error(1390,"Internal error: loopdepth negative.\n",COMMAND_ERROR);
break;
/* DO WHILE tree: DO_END_
/ \
DO_TOP_ test expr
/ /
DO_ENTRY_ command
execution sequence: DO_ENTRY command DO_TOP_ test expr DO_END_
*/
case DO_ENTRY_:
list[listtop].type = type;
loopbase[loopdepth++] = listtop;
/* op3 will hold offsets for break and continue */
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
break;
case DO_TOP_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* DO_ENTRY */
list[listtop].right = right - listtop; /* command */
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
break;
case DO_END_:
{ int entry;
list[listtop].type = type;
list[listtop].left = left - listtop; /* DO_TOP_ */
list[listtop].right = right - listtop; /* command */
/* find start of DO loop */
for ( n = left ; list[n].left ; n += list[n].left ) ;
list[listtop].op1.skipsize = n - listtop - 1; /* allow increment */
/* find start of test loop */
for ( n = right ; list[n].left ; n += list[n].left ) ;
entry = left + list[left].left; /* DO_ENTRY_ */
list[entry].op3.breakjump = listtop-entry; /* break */
list[entry].op4.contjump = n - entry - 1; /* continue */
loopdepth--;
if ( loopdepth < 0 )
kb_error(1391,"Internal error: loopdepth negative.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
}
/* FOR syntax: FOR ( command1 ; expr ; command2 ) command3
FOR tree:
FOR_END_
/ \
FOR_TOP_ command3
/ \
FOR_HEAD_ command2
/ \
FOR_ENTRY expr
|
command1
FOR execution sequence:
command1 expr FOR_HEAD_ command2 FOR_TOP_ command3 FOR_END_
FOR_ENTRY.op3.breakjump holds break jump
FOR_ENTRY.op4.contjump holds continue jump
FOR_HEAD_.op1.skipsize is jump to command3
FOR_HEAD_.op2.jumpsize is jump out of loop
FOR_TOP_.op1.skipsize is jump back to expr
FOR_END_.op1.skipsize is jump back to command2
*/
case FOR_ENTRY_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* command1 */
loopbase[loopdepth++] = listtop;
/* op3 will hold offsets for break and continue */
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
break;
case FOR_HEAD_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* FOR_ENTRY */
list[listtop].right = right - listtop; /* expr */
list[left].op4.contjump = listtop-left; /* expr follows immediately */
list[listtop].stack_delta = -1;
break;
case FOR_TOP_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* FOR_HEAD_ */
list[listtop].right = right - listtop; /* command2 */
list[listtop].op1.skipsize = left + list[left].left - listtop;
list[left].op1.skipsize = listtop - left;
break;
case FOR_END_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* FOR_TOP_ */
if ( right )
list[listtop].right = right - listtop; /* command3 */
list[left+list[left].left].op2.jumpsize =
listtop - left - list[left].left;
list[listtop].op1.skipsize = (left + list[left].left) - listtop;
n = left+list[left].left; /* n = FOR_HEAD */
n += list[n].left; /* n = FOR_ENTRY */
list[n].op3.breakjump = listtop-n; /* break */
loopdepth--;
if ( loopdepth < 0 )
kb_error(2515,"Internal error: loopdepth negative.\n",COMMAND_ERROR);
break;
/* >> redirection tree: REDIRECT_END_
/ \
REDIRECT_ command
/
stringexpr
execution sequence: stringexpr REDIRECT_ command REDIRECT_END_
*/
case REDIRECT_: /* >> */
case REDIRECTOVER_: /* >>> */
list[listtop].type = type;
list[listtop].left = left - listtop; /* stringexpr */
break;
case REDIRECT_END_:
list[listtop].type = type;
list[listtop].left = left - listtop;
if ( right )
list[listtop].right = right - listtop;
list[listtop].stack_delta = -1;
break;
/* piping tree: PIPE_END_
/ \
PIPE_ command
/
stringexpr
execution sequence: stringexpr PIPE_ command PIPE_END_
*/
case PIPE_:
list[listtop].type = PIPE_;
list[listtop].left = left - listtop; /* command */
break;
case PIPE_END_:
list[listtop].type = type;
list[listtop].left = left - listtop;
if ( right ) list[listtop].right = right - listtop;
list[listtop].stack_delta = -1;
break;
case TRANSFORM_DEPTH_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* number of transforms */
list[listtop].stack_delta = -1;
break;
case VIEW_TRANSFORM_PARITY_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* index of transform */
list[listtop].datatype = REAL_TYPE;
break;
case VIEW_TRANSFORM_SWAP_COLORS_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* index of transform */
list[listtop].datatype = REAL_TYPE;
break;
case CREATE_VERTEX_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* expression list for coords */
if ( list[left].op1.indexcount != SDIM )
{ sprintf(msg,
"Need exactly %d coordinates in NEW_VERTEX (...).\n",SDIM);
kb_error(2217,msg,COMMAND_ERROR);
}
list[listtop].stack_delta = 1 - SDIM;
list[listtop].datatype = REAL_TYPE;
break;
case CREATE_EDGE_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* id of tail vertex */
list[listtop].right = right - listtop; /* id of head vertex */
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case CREATE_FACET_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* expression list for edges */
if ( (web.representation == SIMPLEX)
&& (list[left].op1.argcount != web.dimension+1) )
{ sprintf(msg,"Need exactly %d vertices in NEW_FACET (...).\n",
web.dimension+1);
kb_error(2218,msg,COMMAND_ERROR);
}
list[listtop].stack_delta = 1 - list[left].op1.argcount;
list[listtop].datatype = REAL_TYPE;
break;
case CREATE_BODY_:
list[listtop].type = type;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case ELINDEX_:
list[listtop].type = type;
list[listtop].left = left-listtop;
if ( right )
{ list[listtop].right = right - listtop;
list[listtop].stack_delta = -1;
}
break;
case PUSH_ELEMENT_ID_:
list[listtop].type = PUSH_ELEMENT_ID_;
if ( left == 0 )
kb_error(6343,"Element id 0 is illegal.\n",RECOVERABLE);
list[listtop].op1.id = (element_id)abs(left) - 1;
if ( left < 0 )
invert(list[listtop].op1.id);
#ifdef MPI_EVOLVER
list[listtop].op1.id |= ((element_id)right << TASK_ID_SHIFT);
#endif
list[listtop].stack_delta = 1;
break;
case VALID_ELEMENT_:
list[listtop].type = type;
list[listtop].op1.eltype = left;
list[listtop].left = right - listtop; /* index expression */
list[listtop].datatype = REAL_TYPE;
break;
case VALID_CONSTRAINT_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* index expression */
list[listtop].datatype = REAL_TYPE;
break;
case VALID_BOUNDARY_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* index expression */
list[listtop].datatype = REAL_TYPE;
break;
case MATRIX_MULTIPLY_:
{ struct array *a = get_name_arrayptr(list[left].op2.name_id,NULL,localbase);
struct array *b = get_name_arrayptr(list[right].op2.name_id,NULL,localbase);
struct array *c = get_name_arrayptr(list[int_val].op2.name_id,NULL,localbase);
list[listtop].type = type;
list[listtop].op1.name_id = list[left].op2.name_id; /* first multiplicand */
list[listtop].op2.name_id = list[right].op2.name_id; /* second multiplicand */
list[listtop].op3.name_id = list[int_val].op2.name_id; /* result */
list[listtop].stack_delta = -3;
if ( a->datatype != REAL_TYPE)
kb_error(3863,"matrix_multiply: first matrix is not of type REAL.\n",
RECOVERABLE);
if ( b->datatype != REAL_TYPE )
kb_error(3864,"matrix_multiply: second matrix is not of type REAL.\n",
RECOVERABLE);
if ( c->datatype != REAL_TYPE )
kb_error(3865,"matrix_multiply: third matrix is not of type REAL.\n",
RECOVERABLE);
if ( a == c )
kb_error(3866,
"matrix_multiply: first and third matrices must not be the same matrix.\n",
RECOVERABLE);
if ( b == c )
kb_error(3867,
"matrix_multiply: second and third matrices must not be the same matrix.\n",
RECOVERABLE);
}
break;
case MATRIX_INVERSE_:
{ struct array *a = get_name_arrayptr(list[left].op2.name_id,NULL,localbase);
struct array *b = get_name_arrayptr(list[right].op2.name_id,NULL,localbase);
list[listtop].type = type;
list[listtop].op1.name_id = list[left].op2.name_id; /* original */
list[listtop].op2.name_id = list[right].op2.name_id; /* inverse */
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
if ( a->datatype != REAL_TYPE )
kb_error(3874,"matrix_inverse: first matrix is not of type REAL.\n",
RECOVERABLE);
if ( b->datatype != REAL_TYPE )
kb_error(3875,"matrix_inverse: second matrix is not of type REAL.\n",
RECOVERABLE);
if ( a->dim != 2 )
kb_error(3870,"matrix_inverse first array is not two-dimensional.\n",
RECOVERABLE);
if ( b->dim != 2 )
kb_error(3871,"matrix_inverse second array is not two-dimensional.\n",
RECOVERABLE);
}
break;
case MATRIX_DETERMINANT_:
{ struct array *a = get_name_arrayptr(list[left].op2.name_id,NULL,localbase);
list[listtop].type = type;
list[listtop].op1.name_id = list[left].op2.name_id; /* original */
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
if ( a->dim != 2 )
kb_error(3219,"matrix_determinant array is not two-dimensional.\n",
RECOVERABLE);
}
break;
case MERGE_VERTEX_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* id of first vertex */
list[listtop].right = right - listtop; /* id of second vertex */
list[listtop].stack_delta = -2;
break;
case MERGE_EDGE_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* oid of first edge */
list[listtop].right = right - listtop; /* oid of second edge */
list[listtop].stack_delta = -2;
break;
case MERGE_FACET_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* oid of first facet */
list[listtop].right = right - listtop; /* oid of second facet */
list[listtop].stack_delta = -2;
break;
/* Aggregate loops.
(not all nodes need be present)
Tree: AGGREGATE_END_
/ \
AGGREGATE_INIT_ AGGREGATE_
or SET_INIT_ / \
WHERE_ SET_ATTRIBUTE_L
/ \ / \
element_gen expr value expr index expr
sequence: INIT_ element_gen expr WHERE_ value index SET_AT_L AGGR_ AGGR_END_
prep cleanup
If present, SET_ATTRIBUTE_L will do setting and AGGREGATE_ does looping.
Else AGGREGATE_ does both.
Actually, AGGREGATE_ type is collection of node types.
*/
case SET_INIT_:
list[listtop].type = type;
loopbase[loopdepth++] = listtop;
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
break;
case AGGREGATE_INIT_:
list[listtop].type = type;
list[listtop].op1.aggrtype = aggrtype;
loopbase[loopdepth-1] = listtop;
i = add_local_var(NULL,1);
list[listtop].stackpos = get_local(i).offset;
switch ( aggrtype )
{ case MAX_: case MIN_: case SUM_: case COUNT_:
list[listtop].stack_delta = 1;
break;
case AVG_:
list[listtop].stack_delta = 2;
break;
case HISTOGRAM_: case LOGHISTOGRAM_:
list[listtop].stack_delta = 3 + HISTBINS + 1;
break;
}
/* op1 has aggregate type; op2 will have element type; */
/* op3 will have break and continue jump offsets */
break;
case WHERE_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* generator */
list[listtop].right = right - listtop; /* condition expr */
list[listtop].stack_delta = -1;
list[listtop].op2.localnum = list[left].op2.localnum;
/* op1 will hold runtime where count */
break;
case AGGREGATE_:
list[listtop].type = aggrtype;
/* op1 holds offset back to start of loop */
if ( list[left].type == SINGLE_ELEMENT_ )
{ list[listtop].op1.skipsize = 1; /* don't go back */
nnode = list+left;
nnode->op1.skipsize = listtop - left; /* in case of WHERE_ */
}
else if ( list[left].type == WHERE_ )
{ list[listtop].op1.skipsize = list[left].left + left - listtop;
nnode = list+left+list[left].left;
if ( nnode->type == SINGLE_ELEMENT_ )
nnode->op1.skipsize = listtop - (left+list[left].left);
}
else
{ list[listtop].op1.skipsize = left - listtop; /* no WHERE_ */
nnode = list+left;
}
list[listtop].left = left - listtop; /* generator */
if ( right ) list[listtop].right = right - listtop; /* value */
/* also handy to have element type */
etype = (nnode+nnode->left)->op1.eltype; /* from INIT */
/* some type error checking and stuff */
switch ( aggrtype )
{
case SUM_: case AVG_: case COUNT_: case HISTOGRAM_:
case LOGHISTOGRAM_: case MAX_: case MIN_:
list[listtop].stack_delta = -1; break;
case FIX_:
if ( etype == BODY )
kb_error(2230,
"Cannot FIX bodies. To fix volume, do \"set body target expr\".\n",
COMMAND_ERROR);
break;
case UNFIX_:
if ( etype == BODY )
kb_error(2881,
"Cannot UNFIX bodies. To unfix volume, \"unset body target\".\n",
COMMAND_ERROR);
break;
case VERTEX_AVERAGE_:
case RAW_VERTEX_AVERAGE_:
case RAWEST_VERTEX_AVERAGE_:
if ( web.representation == SIMPLEX )
kb_error(2219,"No vertex_average in simplex model yet.\n",
COMMAND_ERROR);
if ( (etype != VERTEX) )
kb_error(1238,"Can vertex_average only vertices.\n",COMMAND_ERROR);
break;
case DELETE_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(1392,"Can delete only edges or facets.\n",COMMAND_ERROR);
break;
case REVERSE_ORIENTATION_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(4392,"Can reverse_orientation only edges or facets.\n",COMMAND_ERROR);
break;
case POP_:
if ( web.representation == SIMPLEX )
kb_error(2432,"Can pop only in SOAPFILM or STRING model.\n",
COMMAND_ERROR);
if ( (etype != EDGE) && (etype != VERTEX) )
kb_error(2433,"Can pop only edges or vertices.\n",
COMMAND_ERROR);
if ( (etype == EDGE) && (web.representation==STRING) )
kb_error(2434,"Can pop edges only in soapfilm model.\n",
COMMAND_ERROR);
break;
case POP_TRI_TO_EDGE_:
if ( web.representation != SOAPFILM )
kb_error(2803,"Can pop_tri_to_edge only in SOAPFILM model.\n",
COMMAND_ERROR);
if ( etype != FACET )
kb_error(2804,"Can pop_tri_to_edge only facets.\n",
COMMAND_ERROR);
break;
case POP_EDGE_TO_TRI_:
if ( web.representation != SOAPFILM )
kb_error(2806,"Can pop_edge_to_tro only in SOAPFILM model.\n",
COMMAND_ERROR);
if ( etype != EDGE )
kb_error(2807,"Can pop_edge_to_tri only edges.\n",
COMMAND_ERROR);
break;
case POP_QUAD_TO_QUAD_:
if ( web.representation != SOAPFILM )
kb_error(2808,"Can pop_quad_to_quad only in SOAPFILM model.\n",
COMMAND_ERROR);
if ( etype != FACET )
kb_error(2809,"Can pop_quad_to_quad only facets.\n",
COMMAND_ERROR);
break;
case EDGESWAP_:
if ( web.representation != SOAPFILM )
kb_error(1393,"Can edgeswap only in the SOAPFILM model. Did you mean t1_edgeswap?\n",
COMMAND_ERROR);
if ( (etype != EDGE) )
kb_error(1394,"Can edgeswap only edges.\n",COMMAND_ERROR);
break;
case T1_EDGESWAP_:
if ( web.representation != STRING )
kb_error(3910,"Can t1_edgeswap only in the STRING model.\n",
COMMAND_ERROR);
if ( (etype != EDGE) )
kb_error(3657,"Can t1_edgeswap only edges.\n",COMMAND_ERROR);
break;
case EQUIANGULATE_:
if ( web.representation != SOAPFILM )
kb_error(2500,"Can equiangulate only in the SOAPFILM model.\n",
COMMAND_ERROR);
if ( (etype != EDGE) )
kb_error(2501,"Can edgeswap only edges.\n",COMMAND_ERROR);
break;
case REFINE_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(1241,"Can refine only edges or facets.\n",COMMAND_ERROR);
break;
case SET_NO_DISPLAY_:
if ( etype != FACET )
kb_error(1265,"No_display only applies to facets.\n",
COMMAND_ERROR);
break;
case SET_NONCONTENT_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(2902,"Noncontent only applies to edges or facets.\n",
COMMAND_ERROR);
break;
case SET_HIT_PARTNER_:
if ( etype != VERTEX )
kb_error(3001,"Hit_partner only applies to vertices.\n",
COMMAND_ERROR);
break;
case SET_NO_REFINE_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(1395,"No_refine only applies to edges or facets.\n",
COMMAND_ERROR);
break;
case SET_CONSTRAINT_:
case UNSET_CONSTRAINT_:
case SET_BOUNDARY_:
case UNSET_BOUNDARY_:
list[listtop].stack_delta = -1;
break;
case SET_EXTRA_ATTR_:
{ struct extra *ex;
ex = EXTRAS(etype);
for ( n = 0 ; n < web.skel[etype].extra_count ; n++,ex++ )
if ( stricmp(ex->name,set_extra_name) == 0 ) break;
if ( n == web.skel[etype].extra_count )
kb_error(1396,"Internal error: Invalid extra attribute number.\n",COMMAND_ERROR);
n += etype << ESHIFT; /* handy to have type here */
list[listtop].op3.extra_info = n;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -ex->array_spec.dim-1;
}
break;
}
if ( (aggrtype >= SET_COORD_) && (aggrtype <= SET_COORD_ + MAXCOORD))
{ list[listtop].type = SET_COORD_;
n = aggrtype - SET_COORD_ - 1;
if ( n >= SDIM )
kb_error(2220,"Coordinate dimension exceeds space dimension.\n",
COMMAND_ERROR);
if ( etype != VERTEX )
kb_error(1398,"Can set coordinates only for vertices.\n",
COMMAND_ERROR);
list[listtop].op2.coordnum = n;
}
else if ((aggrtype>=SET_PARAM_) && (aggrtype <= SET_PARAM_+MAXPARAM))
{ list[listtop].type = SET_PARAM_;
list[listtop].op2.coordnum = aggrtype - SET_PARAM_ - 1;
if ( etype != VERTEX )
kb_error(1399,"Can set parameters only for vertices.\n",
COMMAND_ERROR);
}
else list[listtop].op2.eltype = etype;
break;
case AGGREGATE_END_:
{ struct treenode *wnode;
list[listtop].type = type;
list[listtop].op1.aggrtype = aggrtype;
list[listtop].left = left - listtop; /* aggr init */
list[listtop].right = right - listtop; /* aggr op */
list[listtop].stack_delta = -list[left].stack_delta - 3;
list[listtop].datatype = REAL_TYPE;
if ( (aggrtype == SUM_) || (aggrtype == COUNT_) ||
(aggrtype == AVG_) || (aggrtype == MAX_ ) ||
(aggrtype == MIN_ ) ) list[listtop].stack_delta += 1;
wnode = list+right + list[right].left;
list[listtop].flags |= IN_ELEMENT_LOOP;
if ( wnode[wnode->left].type != SINGLE_ELEMENT_ )
{ if ( wnode->type == WHERE_ )
{ nnode = wnode + wnode->left;
nnode->op1.skipsize = (int)((list + listtop) - nnode);
}
else
wnode->op1.skipsize = listtop - (right + list[right].left);
}
}
/* element type in aggr_init node */
list[left].op2.eltype = list[right].op2.eltype;
list[left].op3.breakjump = listtop-left-1; /* break to here */
list[left].op4.contjump = right-left+list[right].op1.skipsize-1;
list[loopbase[loopdepth-1]].op3.breakjump =
listtop-loopbase[loopdepth-1]-1; /* break to here */
loopdepth--;
if ( loopdepth < 0 )
kb_error(1400,"Internal error: loopdepth negative.\n",COMMAND_ERROR);
break;
/* Element generator.
Tree: WHERE_
/ \
element_gen expr
SINGLE_ELEMENT_
/
INDEXED_SUBTYPE_
/ \
single expr
INDEXED_ELEMENT_
/
expr
SYMBOL_ELEMENT_
NEXT_ELEMENT_
/
INIT_ELEMENT_
*/
case INIT_ELEMENT_:
if ( (list[listtop-1].type != AGGREGATE_INIT_)
&& (list[listtop-1].type != SET_INIT_) )
{ int k; /* for break and continue */
int n;
i = add_local_var(NULL,1);
n = get_local(i).offset;
list[listtop].stackpos = n;
for ( k = listtop-1; k >= 0 ; k-- )
if ( list[k].type==AGGREGATE_INIT_ ||
list[k].type==SET_INIT_ )
{ list[k].stackpos = n; break; }
}
list[listtop].op1.eltype = left; /* save type */
list[listtop].op2.localnum = use_given_id ? 0 : add_local_var(NULL,1);
/* op5.string will have name, if any */
switch ( left )
{ case VERTEX: etype = INIT_VERTEX_; break;
case EDGE : etype = INIT_EDGE_ ; break;
case FACET : etype = INIT_FACET_ ; break;
case BODY : etype = INIT_BODY_ ; break;
case FACETEDGE : etype = INIT_FACETEDGE_ ; break;
default : kb_error(1401,"Internal error: Bad INIT_ELEMENT_ type.\n",
COMMAND_ERROR);
}
list[listtop].type = etype;
list[listtop].stack_delta = 3;
break;
case INIT_SUBELEMENT_: /* subelement of named element */
etype = right;
list[listtop].op1.eltype = etype; /* save type */
list[listtop].left = left - listtop; /* single element */
list[listtop].op2.localnum = list[left].op2.localnum;
{ int k; /* for break and continue */
int n;
i = add_local_var(NULL,1);
n = get_local(i).offset;
list[listtop].stackpos = 0;
for ( k = listtop-1; k >= 0 ; k-- )
if ( list[k].type==AGGREGATE_INIT_ ||
list[k].type==SET_INIT_ )
{ list[k].stackpos = n; break; }
}
switch ( list[left].op1.eltype ) /* parent type */
{ case VERTEX:
switch ( etype )
{
case EDGE : etype = INIT_VERTEX_EDGE_ ;
if ( web.representation == SIMPLEX )
kb_error(1402,"Vertex edge iterator not valid in simplex model.\n",
COMMAND_ERROR);
break;
case FACET : etype = INIT_VERTEX_FACET_ ;
break;
case BODY : etype = INIT_VERTEX_BODY_ ; break;
default : kb_error(1403,"Cannot do vertices of vertex.\n",COMMAND_ERROR);
}
break;
case EDGE:
switch ( etype )
{ case VERTEX: etype = INIT_EDGE_VERTEX_; break;
case EDGE : kb_error(1406,"Cannot do edges of edge.\n",
COMMAND_ERROR);
case FACET : etype = INIT_EDGE_FACET_ ;
if ( web.representation == SIMPLEX )
kb_error(1404,"Edge facet iterator not valid in simplex model.\n",
COMMAND_ERROR);
break;
case BODY : etype = INIT_EDGE_BODY_ ;
if ( web.representation == SIMPLEX )
kb_error(1405,"Edge body iterator not valid in simplex model.\n",
COMMAND_ERROR);
break;
case FACETEDGE: etype = INIT_EDGE_FACETEDGE_ ;
break;
default : kb_error(2830,"Cannot do facetedges of edge.\n",
COMMAND_ERROR);
}
break;
case FACET:
switch ( etype )
{ case VERTEX: etype = INIT_FACET_VERTEX_; break;
case EDGE : etype = INIT_FACET_EDGE_ ;
if ( web.representation == SIMPLEX )
kb_error(1407,"Facet edge iterator not valid in simplex model.\n",
COMMAND_ERROR);
break;
case BODY : etype = INIT_FACET_BODY_ ;
if ( web.representation == SIMPLEX )
kb_error(1408,"Facet body iterator not valid in simplex model.\n",
COMMAND_ERROR);
break;
case FACETEDGE : kb_error(3755,"Cannot do facetedges of facet.\n",COMMAND_ERROR);
default : kb_error(1409,"Cannot do facets of facet.\n",COMMAND_ERROR);
}
break;
case BODY:
switch ( etype )
{ case VERTEX: etype = INIT_BODY_VERTEX_; break;
case EDGE : etype = INIT_BODY_EDGE_ ; break;
case FACET : etype = INIT_BODY_FACET_ ; break;
default : kb_error(1410,"Internal error: Bad INIT_ELEMENT_ type.\n",COMMAND_ERROR);
}
break;
case FACETEDGE:
switch ( etype )
{
case EDGE : etype = INIT_FACETEDGE_EDGE_ ; break;
case FACET : etype = INIT_FACETEDGE_FACET_ ; break;
default : kb_error(3914,"Facetedge can only have edge or facet subelement.\n",COMMAND_ERROR);
}
break;
default: kb_error(1411,"Cannot do bodies of body.\n",COMMAND_ERROR);
}
list[listtop].type = etype;
list[listtop].stack_delta = 3;
break;
case NEXT_ELEMENT_:
list[listtop].left = left - listtop; /* element initializer */
/* op5.string will have name, if any */
/* op2.localnum will point to iteration local variable */
/* op1 reserved for jump to end of loop */
/* left->op2.localnum will point to parent */
list[listtop].op2.localnum = use_given_id ? 0 : add_local_var(NULL,1);
if ( loopdepth > 0 )
list[loopbase[loopdepth-1]].op4.contjump =
listtop-loopbase[loopdepth-1]-1; /* CONTINUE to here */
switch ( list[left].type ) /* parent type */
{
case INIT_VERTEX_EDGE_ : type = NEXT_VERTEX_EDGE_ ; break;
case INIT_VERTEX_FACET_ : type = NEXT_VERTEX_FACET_ ; break;
case INIT_VERTEX_BODY_ : type = NEXT_VERTEX_BODY_ ; break;
case INIT_EDGE_VERTEX_: type = NEXT_EDGE_VERTEX_; break;
case INIT_EDGE_FACET_ : type = NEXT_EDGE_FACET_ ; break;
case INIT_EDGE_FACETEDGE_ : type = NEXT_EDGE_FACETEDGE_ ; break;
case INIT_EDGE_BODY_ : type = NEXT_EDGE_BODY_ ; break;
case INIT_FACET_VERTEX_: type = NEXT_FACET_VERTEX_; break;
case INIT_FACET_EDGE_ : type = NEXT_FACET_EDGE_ ; break;
case INIT_FACET_BODY_ : type = NEXT_FACET_BODY_ ; break;
case INIT_BODY_VERTEX_: type = NEXT_BODY_VERTEX_; break;
case INIT_BODY_EDGE_ : type = NEXT_BODY_EDGE_ ; break;
case INIT_BODY_FACET_ : type = NEXT_BODY_FACET_ ; break;
case INIT_VERTEX_: type = NEXT_VERTEX_; break;
case INIT_EDGE_ : type = NEXT_EDGE_ ; break;
case INIT_FACET_: type = NEXT_FACET_ ; break;
case INIT_BODY_ : type = NEXT_BODY_ ; break;
case INIT_FACETEDGE_ : type = NEXT_FACETEDGE_; break;
case INIT_FACETEDGE_EDGE_ : type = NEXT_FACETEDGE_EDGE_; break;
case INIT_FACETEDGE_FACET_ : type = NEXT_FACETEDGE_FACET_; break;
default : kb_error(1412,"Internal error: Bad NEXT_ELEMENT_ type.\n",COMMAND_ERROR);
}
list[listtop].type = type;
break;
case RITZ_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].stack_delta = -2;
break;
case WRAP_VERTEX_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].stack_delta = -2;
break;
case LANCZOS_:
case EIGENPROBE_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
if ( right )
{ list[listtop].right = right - listtop;
list[listtop].stack_delta = -2;
}
break;
case HESSIAN_SADDLE_:
case HESSIAN_SEEK_:
list[listtop].type = type;
if ( left )
{ list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
}
break;
case MOVE_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case AREAWEED_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case METIS_:
case METIS_READJUST_:
case KMETIS_:
case BODY_METIS_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case OMETIS_:
list[listtop].type = type;
if ( left )
{ list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
}
break;
case EDGEWEED_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case EDGEDIVIDE_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case HISTORY_:
list[listtop].type = type;
break;
case LAGRANGE_:
list[listtop].type = type;
list[listtop].left = left-listtop; /* degree approximation */
list[listtop].stack_delta = -1;
break;
case BURCHARD_:
list[listtop].type = type;
list[listtop].op1.maxsteps = left; /* number of steps */
break;
case ZOOM_:
list[listtop].type = type;
if ( left )
{ list[listtop].left = left - listtop; /* vertex number */
list[listtop].stack_delta = -1;
}
if ( right )
{ list[listtop].left = right - listtop; /* radius expression */
list[listtop].stack_delta += -1;
}
break;
case SET_GRAVITY_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* value expression */
list[listtop].op1.assigntype = assigntype;
list[listtop].stack_delta = -1;
break;
case SET_AMBIENT_PRESSURE_: case SET_GAP_CONSTANT_:
case NOTCH_: case SET_AUTOCHOP_: case SET_FIXED_AREA_:
case SET_OPTIMIZE_: case SET_SCALE_:
case JIGGLE_: case SET_BACKGROUND_:
case PRINT_: case STRPRINT_:
case INVOKE_P_MENU_: case SET_MODEL_: case SKINNY_: case TORDUP_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* value expression */
list[listtop].stack_delta = -1;
break;
case SET_INTERNAL_:
list[listtop].type = type;
list[listtop].left = right - listtop; /* value expression */
list[listtop].op1.name_id = left; /* variable */
list[listtop].op2.assigntype = assigntype;
list[listtop].stack_delta = (assigntype == ASSIGN_) ? -1 : 0;
switch(left)
{ /* break on settable variables */
case V_AMBIENT_PRESSURE: case V_HESSIAN_SLANT_CUTOFF:
case GRAV_CONST_: case V_BREAKFLAG_: case V_VISIBILITY_DEBUG_:
case V_TOLERANCE: case V_HESS_EPSILON:
case V_SCALE_SCALE: case V_TIME: case V_SCALE:
case V_JIG_TEMP: case V_SCALE_LIMIT: case V_GAP_CONSTANT:
case V_THICKNESS: case V_TARGET_TOLERANCE: case V_SCROLLBUFFERSIZE_:
case V_PICKVNUM: case V_PICKENUM: case V_PICKFNUM:
case V_LINEAR_METRIC_MIX: case V_QUADRATIC_METRIC_MIX:
case V_RANDOM_SEED: break; case V_BRIGHTNESS:
case V_BACKGROUND: break; case V_LAST_ERROR: case V_DIFFUSION_:
case V_INTEGRAL_ORDER_1D: case V_INTEGRAL_ORDER_2D: case V_DIFFUSION:
case V_PS_STRINGWIDTH_: case V_PS_FIXEDEDGEWIDTH_:
case V_PS_TRIPLEEDGEWIDTH_: case V_PS_GRIDEDGEWIDTH_:
case V_PS_CONEDGEWIDTH_: case V_PS_BAREEDGEWIDTH_:
case V_PS_LABELSIZE_: case V_MINDEG_MARGIN: case V_MINDEG_DEBUG_LEVEL:
case V_MINDEG_MIN_REGION_SIZE: case V_WINDOW_ASPECT_RATIO:
case V_CORONA_STATE: case V_STRING_CURVE_TOLERANCE:
break;
case V_INTEGRAL_ORDER:
kb_error(1413,
"Please use integral_order_1d or integral_order_2d.\n",WARNING);
break;
default:
sprintf(msg,"Cannot set internal variable '%s'.\n",keywordname(left));
kb_error(1414,msg,EXPRESSION_ERROR);
}
list[listtop].stack_delta = -1;
break;
case FIX_QUANTITY_: case UNFIX_QUANTITY_:
case SET_Q_FIXED_: case SET_Q_ENERGY_: case SET_Q_INFO_:
case SET_Q_CONSERVED_:
list[listtop].type = type;
list[listtop].op1.quant_id = left; /* named quantity var number */
list[listtop].flags |= EPHEMERAL;
break;
case FIX_PARAMETER_:
case UNFIX_PARAMETER_:
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
if ( !(globals(left)->flags & ORDINARY_PARAM ) )
{ sprintf(errmsg,"'%s' cannot be made an optimizing parameter.\n",
globals(left)->name);
kb_error(2223,errmsg,COMMAND_ERROR);
}
list[listtop].flags |= EPHEMERAL;
break;
case PRINT_ARRAY_LVALUE_:
list[listtop].type = type;
list[listtop].left = left-listtop; /* arraylvalue */
list[listtop].op2.name_id = list[left].op2.name_id;
list[listtop].stack_delta = -1;
break;
case PRINT_ARRAYPART_:
list[listtop].type = type;
list[listtop].left = left-listtop; /* arrayhead */
list[listtop].op1.indexcount = list[left].op2.indexcount;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -list[listtop].op1.indexcount;
break;
case PRINT_ARRAY_:
case PRINT_PROCEDURE_:
case EXPRINT_PROCEDURE_:
case PRINT_LETTER_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
break;
case PRINT_PERM_PROCEDURE_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
break;
case UNREDEFINE_SINGLE_:
list[listtop].type = type;
list[listtop].op1.letter = right;
if ( right > 127 )
kb_error(1415,"Illegal unredefine.\n",COMMAND_ERROR);
break;
case REDEFINE_SINGLE_:
list[listtop].type = type;
list[listtop].op1.letter = right; /* letter */
list[listtop].op5.locals = localbase;
if ( localbase )
localbase->flags |= LL_IN_USE;
if ( right > 127 )
kb_error(1416,"Illegal redefine.\n",COMMAND_ERROR);
right = listtop;
subtree_swap(&left,&right);
list[right].op2.jumpsize = left - right; /* proc root */
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
listtop++;
list[listtop].type = SET_PROC_END_;
list[listtop].left = right - listtop; /* action node */
list[listtop].right = left - listtop; /* procedure */
break;
case SET_PROCEDURE_:
{ struct global *g = globals(right);
list[listtop].type = type;
list[listtop].op1.name_id = right; /* variable number */
if ( g->flags & ORDINARY_PARAM )
{ sprintf(errmsg,"Cannot redefine variable '%s' as a command.\n",
g->name);
kb_error(3357,errmsg,COMMAND_ERROR);
}
g->flags |= SUBROUTINE;
list[listtop].op5.locals = localbase;
if ( localbase )
{ list[listtop].flags |= HAS_LOCALLIST;
localbase->flags |= LL_IN_USE;
}
right = listtop;
subtree_swap(&left,&right);
list[right].op2.jumpsize = left - right; /* proc root */
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
listtop++;
list[listtop].type = SET_PROC_END_;
list[listtop].left = right - listtop; /* action node */
list[listtop].right = left - listtop; /* procedure */
list[listtop].flags |= EPHEMERAL;
break;
}
case SET_PERM_PROCEDURE_:
{ struct global *g = globals(right);
list[listtop].type = type;
list[listtop].op1.name_id = right; /* variable number */
if ( g->flags & ORDINARY_PARAM )
{ sprintf(errmsg,"Cannot redefine variable '%s' as a command.\n",
g->name);
kb_error(2516,errmsg,COMMAND_ERROR);
}
g->flags |= SUBROUTINE;
right = listtop;
subtree_swap(&left,&right);
/* see if any ephemeral stuff, and mark as part of permanent cmd */
for ( n = right ; n < listtop ; n++ )
{ if ( list[n].flags & EPHEMERAL )
{ sprintf(errmsg,"Non-permanent items in definition of %s.\n",
g->name);
kb_error(2517,errmsg,COMMAND_ERROR);
}
list[n].flags |= PERMNODE;
}
list[right].op2.jumpsize = left - right; /* proc root */
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
list[listtop].op5.locals = localbase;
if ( localbase )
{ list[listtop].flags |= HAS_LOCALLIST;
localbase->flags |= LL_IN_USE;
}
listtop++;
list[listtop].type = SET_PERM_PROC_END_;
list[listtop].left = right - listtop; /* action node */
list[listtop].right = left - listtop; /* procedure */
break;
}
case ARGLIST_:
list[listtop].type = type;
list[listtop].left = left ? left - listtop : 0; /* prev args */
if ( right )
{ list[listtop].op1.name_id = right; /* name id */
globals(right)->flags |= ORDINARY_PARAM;
}
list[listtop].op2.argcount = /* count of arguments */
(left ? list[left].op2.argcount : 0) + (right?1:0);
list[listtop].op3.argtype = int_val; /* argument type */
break;
case FUNCTION_DEF_START_:
case FUNCTION_PROTO_START_:
{ struct global *g = globals(left);
list[listtop].type = type;
list[listtop].op1.name_id = left; /* name id */
if ( g->flags & ORDINARY_PARAM )
{ sprintf(errmsg,"Cannot redefine '%s' as a function.\n",g->name);
kb_error(3358,errmsg,COMMAND_ERROR);
}
g->flags |= FUNCTION_NAME;
/* op2.jumpsize for skip ahead, set later */
/* op3.argcount for argument count */
list[listtop].op4.ret_type = right; /* type of return value */
break;
}
case FUNCTION_HEAD_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* function def start */
list[listtop].right = right - listtop; /* function arglist */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
list[left].op3.argcount = list[right].op2.argcount; /* arg count */
globals(list[left].op1.name_id)->attr.procstuff.argcount =
list[right].op2.argcount;
list[listtop].op4.ret_type = list[left].op4.ret_type;
break;
case SET_FUNCTION_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* function head */
list[listtop].right = right - listtop; /* function body */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
n = left + list[left].left;
list[n].op2.jumpsize = listtop - n; /* for FUNCTION_START_ jump */
list[listtop].flags |= EPHEMERAL;
list[listtop].op4.ret_type = list[left].op4.ret_type;
if ( topflag )
globals(list[left].op1.name_id)->flags |= IN_DATAFILE_TOP;
break;
case FUNCTION_PROTO_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* function head */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
n = left + list[left].left;
list[n].op2.jumpsize = listtop - n; /* for FUNCTION_PROTO_START_ jump */
list[n].type = FUNCTION_PROTO_START_;
list[listtop].flags |= EPHEMERAL;
list[listtop].op4.ret_type = list[left].op4.ret_type; /* type */
break;
case FUNCTION_CALL_:
{ struct global *g = globals(left);
list[listtop].type = type;
if ( right )
list[listtop].left = right - listtop; /* argument expressions */
list[listtop].op1.name_id = left; /* function name id */
if ( list[right].op1.argcount != g->attr.procstuff.argcount )
{ sprintf(errmsg,"Function \"%s\" needs %d arguments; call has %d,\n",
g->name,g->attr.procstuff.argcount,list[right].op1.argcount);
kb_error(2620,errmsg,COMMAND_ERROR);
}
list[listtop].op2.argcount = g->attr.procstuff.argcount;
list[listtop].stack_delta = 1 - g->attr.procstuff.argcount;
list[listtop].datatype = g->type <= MAX_NUMERIC_TYPE ? REAL_TYPE :
g->type;
break;
}
case FUNCTION_CALL_RETURN_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* to FUNCTION_CALL */
list[listtop].op2.argcount = list[left].op2.argcount;
break;
case PROCEDURE_DEF_START_:
case PROCEDURE_PROTO_START_:
{ struct global *g = globals(left);
list[listtop].type = type;
list[listtop].op1.name_id = left; /* name id */
if ( g->flags & ORDINARY_PARAM )
{ sprintf(errmsg,"Cannot redefine '%s' as a function.\n",g->name);
kb_error(1417,errmsg,COMMAND_ERROR);
}
g->flags |= PROCEDURE_NAME;
/* op2.jumpsize for skip ahead, set later */
/* op3.argcount for argument count */
break;
}
case PROCEDURE_HEAD_:
{ struct global *g;
list[listtop].type = type;
list[listtop].left = left - listtop; /* procedure def start */
list[listtop].right = right - listtop; /* procedure arglist */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
list[left].op3.argcount = list[right].op2.argcount; /* arg count */
g = globals(list[left].op1.name_id);
g->attr.procstuff.argcount = list[right].op2.argcount;
break;
}
case SET_ARGSPROC_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* function head */
list[listtop].right = right - listtop; /* function body */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
n = left + list[left].left;
list[n].op2.jumpsize = listtop - n; /* for PROCEDURE_START_ jump */
list[listtop].flags |= EPHEMERAL;
if ( topflag )
globals(list[left].op1.name_id)->flags |= IN_DATAFILE_TOP;
break;
case PROCEDURE_PROTO_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* function head */
list[listtop].op1.name_id = list[left].op1.name_id; /* name id */
n = left + list[left].left;
list[n].op2.jumpsize = listtop - n; /* for PROCEDURE_PROTO_START_ jump */
list[n].type = PROCEDURE_PROTO_START_;
list[listtop].flags |= EPHEMERAL;
break;
case PROCEDURE_CALL_:
{ struct global *g = globals(left);
list[listtop].type = type;
if ( right )
list[listtop].left = right - listtop; /* argument expressions */
list[listtop].op1.name_id = left; /* procedure name id */
if ( list[right].op1.argcount != g->attr.procstuff.argcount )
{ sprintf(errmsg,"Procedure \"%s\" needs %d arguments; call has %d.\n",
g->name,g->attr.procstuff.argcount,list[right].op1.argcount);
kb_error(2623,errmsg,COMMAND_ERROR);
}
list[listtop].op2.argcount = g->attr.procstuff.argcount;
list[listtop].stack_delta = -g->attr.procstuff.argcount;
break;
}
case PROCEDURE_CALL_RETURN_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* to PROCEDURE_CALL */
list[listtop].op2.argcount = list[left].op2.argcount;
break;
case DEFINE_IDENT_:
{ struct global *g = globals(left);
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].op2.valtype = right; /* type */
g->type = right;
if ( right == STRING_TYPE ) g->flags |= STRINGVAL;
else if ( !(g->flags & ANY_TYPE) )
{ g->flags |= ORDINARY_PARAM;
list[listtop].flags |= EPHEMERAL;
g->attr.varstuff.delta = OPTPARAM_DELTA;
g->attr.varstuff.pscale = 1.0;
}
break;
}
case DEFINE_ARRAY_:
{ struct global *g = globals(left);
int datatype = int_val; /* kludge due to shortage of arguments */
int dim = list[right].op1.indexcount;
int datastart;
if ( g->flags & ORDINARY_PARAM )
{ sprintf(errmsg,
"Illegal to convert ordinary variable \"%s\" into array.\n",
g->name);
kb_error(3289,errmsg,Q_ERROR);
}
if ( g->flags & FIXED_SIZE_ARRAY )
{ sprintf(errmsg,"Cannot re-declare a local fixed-size array %s.\n",
g->name);
kb_error(3176,errmsg,COMMAND_ERROR);
}
if ( dim > MAXARRAYDIMS )
{ sprintf(errmsg,
"Maximum number of array dimensions is %d; %s has %d.\n",
MAXARRAYDIMS,g->name,dim);
kb_error(3177,errmsg,COMMAND_ERROR);
}
if ( !g->attr.arrayptr )
g->attr.arrayptr = (struct array*)mycalloc(1,sizeof(struct array));
g->attr.arrayptr->datatype = g->type = datatype;
g->attr.arrayptr->dim = dim;
g->flags |= ARRAY_PARAM;
g->flags &= ~ORDINARY_PARAM;
/* see if fixed-zized local array, so we can allocate stack space */
if ( g->flags & GLOB_LOCALVAR && !(g->flags & UNFIXED_SIZE_ARRAY) )
{ /* test previous nodes for fixed sizes */
int cantflag = 0; /* set if not fixed sizes */
int indexset_node = right;
int rexpr_node=0;
int i;
for ( i = dim-1 ; i >= 0 ; i-- )
{ rexpr_node = indexset_node +
(i ? list[indexset_node].right : list[indexset_node].left);
if ( list[rexpr_node].type != PUSHCONST )
{ cantflag = 1;
break;
}
indexset_node += list[indexset_node].left;
}
if ( cantflag == 0 )
{ int datacount = 1;
int pointercount = 1;
g->flags |= FIXED_SIZE_ARRAY;
g->attr.arrayptr = (struct array*)mycalloc(1,sizeof(struct array));
g->attr.arrayptr->datatype = g->type = datatype;
g->attr.arrayptr->dim = dim;
/* gather sizes */
indexset_node = right;
for ( i = dim-1 ; i >= 0 ; i-- )
{ int size;
rexpr_node = indexset_node +
(i ? list[indexset_node].right : list[indexset_node].left);
size = (int)list[rexpr_node].op1.real;
g->attr.arrayptr->sizes[i] = size;
datacount *= size;
if ( i < dim-1 ) pointercount *= size;
indexset_node += list[indexset_node].left;
}
/* pop index nodes off execution list */
listtop = rexpr_node;
memset(list+listtop,0,sizeof(struct treenode));
g->attr.arrayptr->itemsize = datatype_size[datatype];
g->attr.arrayptr->datacount = datacount;
i = add_local_var(NULL,datacount+pointercount);
datastart = get_local(i).offset;
g = globals(left); /* kludge since add_local_var can move things */
g->attr.arrayptr->datastart = datastart;
list[listtop].type = DEFINE_FIXED_LOCAL_ARRAY_;
list[listtop].op1.name_id = left; /* global variable number */
list[listtop].op2.valtype = datatype; /* type */
break;
}
else g->flags |= UNFIXED_SIZE_ARRAY;
}
list[listtop].type = type;
list[listtop].left = right-listtop; /* index expression list */
list[listtop].op1.name_id = left; /* global variable number */
list[listtop].op2.valtype = datatype;
g->flags |= ARRAY_PARAM;
g->flags &= ~ORDINARY_PARAM;
if ( !(g->flags & GLOB_LOCALVAR) && g->attr.arrayptr &&
g->type != datatype )
{ sprintf(errmsg,
"Array %s type declaration conflicts with previous type.\n",
g->name);
kb_error(2224,errmsg,COMMAND_ERROR);
}
g->type = datatype;
if ( (g->attr.arrayptr->dim > 0) &&
(g->attr.arrayptr->dim != list[right].op1.indexcount) )
{ sprintf(errmsg,"Cannot change the number of dimensions of array %s.\n",
g->name);
kb_error(2225,errmsg,COMMAND_ERROR);
}
else g->attr.arrayptr->dim = list[right].op1.indexcount;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -list[right].op1.indexcount;
break;
}
case ARRAY_HEAD_:
list[listtop].type = type;
list[listtop].op1.name_id = right; /* global variable number */
list[listtop].left = left-listtop; /* indexset */
list[listtop].op2.indexcount = list[left].op1.indexcount; /* # indices */
/*
if ( list[left].op1.indexcount != globals(right)->dim )
{ sprintf(errmsg,
"Array %s has wrong number of dimensions; should be %d\n",
globals(int_val)->name,globals(int_val)->dim);
kb_error(3360,errmsg,COMMAND_ERROR);
}
*/
list[listtop].flags |= EPHEMERAL;
break;
/* whole-array syntax */
case ARRAYIDENT_: /* push datastart for an array */
list[listtop].type = type;
list[listtop].op2.name_id = left;
list[listtop].stack_delta = 1;
break;
case ATTRIB_LVALUE_ :
list[listtop].type = type;
if ( left )
list[listtop].left = left - listtop;
list[listtop].stack_delta = 1;
break;
case ARRAY_LVALUE_INDEXED_: /* nop at execution */
{ struct array *a = get_name_arrayptr(list[left].op2.name_id,NULL,localbase);
if ( a->dim != list[right].op1.indexcount )
{ sprintf(errmsg,"Array %s needs %d indexes, has %d.\n",
get_name_name(list[left].op2.name_id,localbase),a->dim,list[right].op1.indexcount);
kb_error(3267,errmsg,Q_ERROR);
}
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
list[listtop].op1.indexcount = list[right].op1.indexcount;
list[listtop].op2.name_id = list[left].op2.name_id;
break;
}
case ARRAY_EVAL_: /* rexpr: arraylvalue indexset */
{ struct array *a = get_name_arrayptr(list[left].op2.name_id,NULL,localbase);
if ( a->dim != list[right].op1.indexcount )
{ sprintf(errmsg,"Array %s needs %d indexes, has only %d.\n",
get_name_name(list[left].op2.name_id,localbase),a->dim,list[right].op1.indexcount);
kb_error(3268,errmsg,Q_ERROR);
}
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
list[listtop].op2.name_id = list[left].op2.name_id;
list[listtop].datatype = REAL_TYPE;
if ( (list[left].type == ARRAY_VERTEX_NORMAL_) ||
(list[left].type == ARRAY_EDGE_VECTOR_) ||
(list[left].type == ARRAY_FACET_NORMAL_) )
list[listtop].flags |= IS_VIRTUAL_ATTR;
list[listtop].stack_delta = list[right].op1.indexcount;
break;
}
case ARRAY_ASSIGNOP_SINGLE_:
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
/* list[listtop].stack_delta done in command.yac */
break;
case DOT_: /* dot product */
{
int name1 = list[left].op2.name_id;
int name2 = list[right].op2.name_id;
int adim = get_name_dim(name1,localbase);
int bdim = get_name_dim(name2,localbase);
if ( (adim != 1) || (bdim != 1) )
kb_error(3329,"Dot product operands must be one dimensional.\n",
COMMAND_ERROR);
if ( (get_name_datatype(name1,localbase) != REAL_TYPE) ||
(get_name_datatype(name2,localbase) != REAL_TYPE) )
kb_error(3330,"Dot product operands must be of type real.\n",
COMMAND_ERROR);
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
list[listtop].datatype = REAL_TYPE;
list[listtop].op2.name_id = name1;
list[listtop].op3.name_id = name2;
list[listtop].stack_delta = 1;
}
break;
case ARRAY_ASSIGNOP_ARRAY_: /* full array syntax */
/* see if we have special attributes on right side */
{ int name_id = list[right].op2.name_id;
check_readonly_attr(list[left].op2.name_id);
if ( name_id == set_name_eltype(V_NORMAL_ATTR,VERTEX) )
list[listtop].type = ARRAY_ASSIGNOP_VERTEX_NORMAL_;
else if ( name_id == set_name_eltype(E_VECTOR_ATTR,EDGE) )
list[listtop].type = ARRAY_ASSIGNOP_EDGE_VECTOR_;
else if ( name_id == set_name_eltype(F_NORMAL_ATTR,FACET) )
list[listtop].type = ARRAY_ASSIGNOP_FACET_NORMAL_;
else
list[listtop].type = type;
list[listtop].left = left-listtop; /* lvalue */
list[listtop].right = right-listtop; /* rvalue */
list[listtop].op2.name_id = list[left].op2.name_id;
list[listtop].op3.name_id = list[right].op2.name_id;
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
/* op1.assigntype will be set back in command.yac */
/* Can do dimension check now */
if ( check_array_dims_same(list[left].op2.name_id,
list[right].op2.name_id) == 0 )
kb_error(4378,"Arrays don't have same number of dimensions or types different.\n",
COMMAND_ERROR);
list[listtop].stack_delta = -2;
}
break;
case ARRAY_ASSIGNOP_SCALAR_: /* full array syntax */
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].op2.name_id = list[left].op2.name_id;
list[listtop].left = left-listtop; /* lvalue array */
list[listtop].right = right-listtop; /* rexpr */
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
list[listtop].stack_delta = -2;
/* op1.assigntype will be set back in command.yac */
break;
case ARRAY_RVALUE_: /* nop needed for tree construction */
list[listtop].type = type;
list[listtop].left = left-listtop; /* lvalue array */
list[listtop].right = right-listtop; /* rexpr */
break;
case ARRAY_ASSIGNOP_S_X_A_: /* full array syntax, scalar times array */
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].op2.name_id = list[left].op2.name_id;
list[listtop].left = left-listtop; /* lvalue array */
list[listtop].right = right-listtop; /* rvalue */
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
/* op1.assigntype will be set back in command.yac */
list[listtop].stack_delta = -3;
break;
case ARRAY_ASSIGNOP_A_P_A_: /* full array syntax, array plus array */
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].left = left-listtop; /* lvalue array */
list[listtop].right = right-listtop; /* rvalue */
list[listtop].op2.name_id = list[left].op2.name_id;
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
/* op1.assigntype will be set back in command.yac */
list[listtop].stack_delta = -3;
break;
case ARRAY_ASSIGNOP_A_S_A_: /* full array syntax, array subtract array */
check_readonly_attr(list[left].op2.name_id);
list[listtop].type = type;
list[listtop].left = left-listtop; /* lvalue array */
list[listtop].right = right-listtop; /* rvalue */
list[listtop].op2.name_id = list[left].op2.name_id;
if ( check_recalc_attr(list[left].op2.name_id) )
list[listtop].flags |= RECALC_NODE;
/* op1.assigntype will be set back in command.yac */
list[listtop].stack_delta = -3;
break;
/* end whole-array syntax */
case ARRAYASSIGN:
list[listtop].type = type;
list[listtop].left = left-listtop; /* arrayhead */
list[listtop].right = right-listtop; /* rhs */
list[listtop].op1.assigntype = assigntype;
list[listtop].op2.name_id = list[left].op1.name_id; /* glob var number */
g = globals(list[left].op1.name_id);
if ( list[left].op2.indexcount != g->attr.arrayptr->dim )
{ sprintf(errmsg,
"Array %s has wrong number of dimensions; should be %d\n",
g->name,g->attr.arrayptr->dim);
kb_error(2226,errmsg,COMMAND_ERROR);
}
if ( g->flags & READONLY )
{ sprintf(errmsg, "Array %s is read-only.\n",g->name);
kb_error(2846,errmsg,COMMAND_ERROR);
}
list[listtop].stack_delta = -list[left].op2.indexcount-1;
if ( !(g->flags & PERMANENT) )
list[listtop].flags |= EPHEMERAL;
break;
case ARRAYEVAL:
{
g = globals(list[left].op1.name_id);
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].op2.name_id = list[left].op1.name_id;
list[listtop].flags |= EPHEMERAL;
if ( list[left].op2.indexcount != g->attr.arrayptr->dim )
{ sprintf(errmsg,
"Array %s has wrong number of dimensions; should be %d\n",
g->name, g->attr.arrayptr->dim );
kb_error(2608,errmsg,COMMAND_ERROR);
}
list[listtop].stack_delta = -list[left].op2.indexcount+1;
list[listtop].datatype = (g->type <= MAX_NUMERIC_TYPE) ? REAL_TYPE:
g->type;
break;
}
case PDELTA_LVALUE_: case PSCALE_LVALUE_:
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
break;
case SET_DELTA_: case SET_PARAM_SCALE:
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].left = right - listtop; /* value expression */
list[listtop].op2.assigntype = assigntype;
if ( !(globals(left)->flags & ANY_TYPE) )
globals(left)->flags |= ORDINARY_PARAM;
if ( perm_flag ) globals(left)->flags |= PERMANENT;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -1;
break;
case SET_ELEMENT_GLOBAL_:
{ struct global *g = globals(left);
int eltype = -1; /* of right side */
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].left = right - listtop; /* value expression */
if ( !(g->flags & ANY_TYPE) )
g->flags |= ORDINARY_PARAM;
if ( (list[listtop].datatype < VERTEX_TYPE)
|| (list[listtop].datatype > FACETEDGE_TYPE) )
kb_error(2884,"Right side expression must be an element.\n",
COMMAND_ERROR);
switch ( list[right].op1.eltype )
{ case VERTEX:
eltype = VERTEX_TYPE; break;
case EDGE:
eltype = EDGE_TYPE; break;
case FACET:
eltype = FACET_TYPE; break;
case BODY:
eltype = BODY_TYPE; break;
case FACETEDGE:
eltype = FACETEDGE_TYPE; break;
default:
kb_error(3684,"Illegal element type.\n",Q_ERROR);
}
if ( g->type && (g->type != eltype) )
{ sprintf(errmsg,
"Cannot assign expression of type %s to variable %s of type %s.\n",
datatype_name[eltype],globals(left)->name,datatype_name[g->type]);
kb_error(3686,errmsg,Q_ERROR);
}
else g->type = eltype;
if ( perm_flag ) g->flags |= PERMANENT;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -1;
break;
}
case SET_GLOBAL_:
case PLUSASSIGN_: case SUBASSIGN_: case MULTASSIGN_: case DIVASSIGN_:
{
struct global *g = globals(left);
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].left = right - listtop; /* value expression */
if ( !(g->flags & ANY_TYPE) )
g->flags |= ORDINARY_PARAM;
if ( !(g->flags & (ORDINARY_PARAM|GLOB_LOCALVAR)) )
{ sprintf(errmsg, "Variable %s is not proper type for left side of assighmant.\n",g->name);
kb_error(3021,errmsg,Q_ERROR);
}
if ( perm_flag ) g->flags |= PERMANENT;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -1;
g->type = list[right].datatype;
break;
}
case SET_PERM_GLOBAL_:
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].left = right - listtop; /* value expression */
perm_globals(left)->flags |= ORDINARY_PARAM;
perm_globals(left)->attr.varstuff.delta = OPTPARAM_DELTA;
perm_globals(left)->attr.varstuff.pscale = 1.0;
list[listtop].stack_delta = -1;
break;
case SET_SGLOBAL_:
case SET_PERM_SGLOBAL_:
list[listtop].type = type;
list[listtop].op1.name_id = left; /* variable number */
list[listtop].left = right - listtop; /* value expression */
globals(left)->flags |= STRINGVAL;
globals(left)->flags &= ~ORDINARY_PARAM;
if ( type == SET_SGLOBAL_ ) list[listtop].flags |= EPHEMERAL;
if ( perm_flag ) globals(left)->flags |= PERMANENT;
list[listtop].stack_delta = -1;
break;
case SHOW_:
case SHOW_EXPR_:
list[listtop].type = type;
/* put node in front of expression */
right = listtop;
subtree_swap(&left,&right);
list[right].op1.skipsize = left - right;
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
listtop++;
list[listtop].type = SHOW_END_;
list[listtop].left = right - listtop; /* action node */
list[listtop].right = left - listtop; /* procedure */
break;
case SELF_ELEMENT_:
list[listtop].type = type;
list[listtop].op1.eltype = left;
list[listtop].op2.localnum = elsym->localnum;
break;
case SINGLE_ELEMENT_EXPR_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* action node */
list[listtop].op1.eltype = right;
list[listtop].stack_delta = 1;
list[listtop].datatype = VERTEX_TYPE + right;
break;
case ELEMENT_IDENT_:
list[listtop].type = type;
list[listtop].op3.name_id = left;
list[listtop].op2.localnum = add_local_var(NULL,1);
break;
case SYMBOL_ELEMENT_:
list[listtop].type = type;
list[listtop].op1.eltype = symtable[left].type;
list[listtop].op2.localnum = symtable[left].localnum;
list[listtop].op5.string =
(char*)mycalloc(strlen(symtable[left].name)+1,1);
list[listtop].flags |= HAS_STRING_5;
strcpy(list[listtop].op5.string,symtable[left].name);
break;
case SINGLE_ELEMENT_: /* generator */
list[listtop].type = SINGLE_ELEMENT_INIT_; /* for dummy loop */
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
list[listtop].stack_delta = 3;
listtop++;
list[listtop].type = type;
list[listtop].left = left-listtop; /* index value */
list[listtop].right = -1; /* to INIT */
list[listtop].op2.localnum = add_local_var(NULL,1);
/* local will hold id at runtime */
/* op1 will hold jump to end of loop */
break;
case INDEXED_ELEMENT_:
list[listtop].type = type;
list[listtop].left = right-listtop; /* index value */
list[listtop].op1.eltype = left; /* element type */
list[listtop].stack_delta = -1;
list[listtop].op2.localnum = add_local_var(NULL,1);
/* local will hold id at runtime */
/* Sanity check on index */
if ( list[right].type == PUSHCONST )
{ if ( list[right].op1.real == 0.0 )
kb_error(2228,"Element index must be nonzero.\n",COMMAND_ERROR);
}
break;
case INDEXED_SUBTYPE_:
list[listtop].type = type;
list[listtop].left = left-listtop; /* single element */
list[listtop].right = right-listtop; /* index value */
list[listtop].op1.eltype = subtype; /* element type */
list[listtop].stack_delta = -1;
list[listtop].op2.localnum = add_local_var(NULL,1);
/* local will hold id at runtime */
/* Sanity check on index */
if ( list[right].type == PUSHCONST )
{ if ( list[right].op1.real <= 0.0 )
kb_error(2229,"Element index must be positive.\n",COMMAND_ERROR);
}
/* some type checking */
etype = list[left].op1.eltype;
if ( etype == subtype )
kb_error(1418,"Cannot do same subtype as type of element.\n",
COMMAND_ERROR);
switch ( etype )
{ case VERTEX:
switch ( subtype /* subtype */ )
{ case BODY: case FACETEDGE:
kb_error(1419,"Unimplemented subtype of vertex.\n",COMMAND_ERROR);
}
break;
case EDGE:
switch ( subtype /* subtype */ )
{ case BODY:
kb_error(1420,"Unimplemented subtype of edge.\n",COMMAND_ERROR);
}
break;
case FACET:
switch ( subtype /* subtype */ )
{ case FACETEDGE:
kb_error(1421,"Unimplemented subtype of facet.\n",COMMAND_ERROR);
}
break;
case BODY:
switch ( subtype /* subtype */ )
{ case FACETEDGE:
case VERTEX:
case EDGE:
kb_error(1422,"Unimplemented subtype of body.\n",COMMAND_ERROR);
}
break;
case FACETEDGE:
switch ( subtype /* subtype */ )
{ case FACETEDGE:
case VERTEX:
case BODY:
kb_error(1423,"Unimplemented subtype of facet.\n",COMMAND_ERROR);
}
break;
}
break;
case SHOW_VOL_: case CHECK_: case LONG_JIGGLE_: case RAW_VERAVG_:
case STABILITY_TEST_: case UTEST_: case GO_: case SHELL_:
case ALICE_: case TOPINFO_: case RECALC_: case COUNTS_:
case EXTRAPOLATE_: case HESSIAN_: case SOBOLEV_:
case SHOWQ_:case RAWEST_VERAVG_: case DIRICHLET_: case BOTTOMINFO_:
case CLOSE_SHOW_: case REBODY_: case LIST_PROCS_: case HESSIAN_MENU_:
case DIRICHLET_SEEK_: case SOBOLEV_SEEK_: case CONVERT_TO_QUANTS_:
case LIST_ATTRIBUTES_: case REORDER_STORAGE_: case RENUMBER_ALL_:
case DUMP_MEMLIST_: case FREE_DISCARDS_: case REPARTITION_:
case SUBCOMMAND_: case ABORT_: case SIMPLEX_TO_FE_:
list[listtop].type = type;
break;
case LIST_BOUNDARY_: case LIST_CONSTRAINT_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case LIST_QUANTITY_:
list[listtop].type = type;
list[listtop].op1.quant_id = left;
break;
case LIST_METHOD_INSTANCE_:
list[listtop].type = type;
list[listtop].op1.meth_id = left;
break;
/* toggles */ case LINEAR_: case QUADRATIC_: case QUIETGO_:
case KUSNER_: case ESTIMATE_: case DETURCK_: case HOMOTHETY_:
case SQGAUSS_: case AUTOPOP_: case AUTOCHOP_: case QUIET_:
case OLD_AREA_: case APPROX_CURV_: case RUNGE_KUTTA_:
case CHECK_INCREASE_: case DEBUG_: case MEAN_CURV_: case RIBIERE_CG_:
case DIFFUSION_: case GRAVITY_: case CONJ_GRAD_: case TRANSFORMS_:
case CONF_EDGE_SQCURV_: case EFFECTIVE_AREA_: case AREA_FIXED_:
case RAW_CELLS_: case CONNECTED_CELLS_: case CLIPPED_CELLS_:
case THICKEN_: case SHOW_INNER_: case SHOW_OUTER_: case COLORMAP_:
case HESSIAN_DIFF_: case POST_PROJECT_: case MEAN_CURV_INT_:
case OPTIMIZE_: case NORMAL_CURVATURE_: case DIV_NORMAL_CURVATURE_:
case SHADING_: case FACET_COLORS_: case BOUNDARY_CURVATURE_:
case NORMAL_MOTION_: case PINNING_: case VIEW_4D_: case MEMDEBUG_:
case METRIC_CONVERSION_: case AUTORECALC_: case GV_BINARY_:
case SELF_SIMILAR_: case AUTODISPLAY_: case FORCE_POS_DEF_:
case ASSUME_ORIENTED_: case HESSIAN_QUIET_: case JIGGLE_TOGGLE_:
case HESSIAN_NORMAL_: case YSMP_: case BUNCH_KAUFMAN_:
case QUANTITIES_ONLY_: case LINEAR_METRIC_: case GEOMVIEW_TOGGLE_:
case GEOMPIPE_TOGGLE_: case SQUARED_GRADIENT_: case H_INVERSE_METRIC_:
case HESSIAN_DOUBLE_NORMAL_: case INTERP_BDRY_PARAM_: case LOGFILE_TOGGLE_:
case HESSIAN_NORMAL_ONE_: case PSCOLORFLAG_: case GRIDFLAG_:
case CROSSINGFLAG_: case LABELFLAG_: case SHOW_ALL_QUANTITIES_:
case HESSIAN_NORMAL_PERP_: case HESSIAN_SPECIAL_NORMAL_: case ITDEBUG_:
case METIS_FACTOR_: case VOLGRADS_EVERY_: case ZENER_DRAG_:
case BACKCULL_: case INTERP_NORMALS_: case TORUS_FILLED_: case VERBOSE_:
case AMBIENT_PRESSURE_: case DIRICHLET_MODE_: case SOBOLEV_MODE_:
case KRAYNIKPOPVERTEX_FLAG_: case KEYLOGFILE_TOGGLE_:
case KRAYNIKPOPEDGE_FLAG_: case VISIBILITY_TEST_: case SPARSE_CONSTRAINTS_:
case BLAS_FLAG_: case AUGMENTED_HESSIAN_: case BREAK_AFTER_WARNING_:
case RGB_COLORS_FLAG_: case CIRCULAR_ARC_DRAW_: case BEZIER_BASIS_:
case SMOOTH_GRAPH_: case MPI_DEBUG_: case POP_DISJOIN_:
case POP_TO_EDGE_: case POP_TO_FACE_: case POP_ENJOIN_:
case FULL_BOUNDING_BOX_: case BIG_ENDIAN_: case LITTLE_ENDIAN_:
case QUIETLOAD_: case SLICE_VIEW_: case FUNCTION_QUANTITY_SPARSE_:
case CLIP_VIEW_: case STAR_FINAGLING_: case FORCE_DELETION_:
case AUTOPOP_QUARTIC_: case IMMEDIATE_AUTOPOP_:
list[listtop].type = type;
list[listtop].op1.toggle_state = left; /* toggle state */
break;
case SYSTEM_:
case READ_:
case EXEC_: case PARALLEL_EXEC_:
case CHDIR_:
case SHOW_TRANS_:
case SET_COLORMAP_:
case TRANSFORM_EXPR_: case KEYLOGFILE_: case OOGLFILE_:
case BINARY_OFF_FILE_:
case GEOMVIEW_: case GEOMPIPE_: case POSTSCRIPT_: case LOGFILE_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case TASK_EXEC_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].stack_delta = -2;
break;
case TEXT_SPOT_: /* just accumulate two arguments */
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
break;
case DISPLAY_TEXT_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].stack_delta = -2; /* pops 3, leaves string id */
break;
case DELETE_TEXT_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case PRINTFHEAD_:
case BINARY_PRINTFHEAD_:
case ERRPRINTFHEAD_:
case SPRINTFHEAD_:
list[listtop].type = type;
/* copy and convert escape sequences */
if ( left )
{ list[listtop].left = left - listtop;
list[listtop].stack_delta = 0; /* since pushes result string */
}
else
{
char *c, *s;
list[listtop].op1.string =
(char*)mycalloc(strlen(yytext)+1,sizeof(char));
list[listtop].flags |= HAS_STRING;
s = yytext; /* source */
c = list[listtop].op1.string; /* destination */
while ( *s )
if ( *s == '\\' )
{ switch ( s[1] )
{ case 'n' : *(c++) = '\n'; s += 2; break;
case 't' : *(c++) = '\t'; s += 2; break;
case 'b' : *(c++) = '\b'; s += 2; break;
case 'r' : *(c++) = '\r'; s += 2; break;
default: *(c++) = s[1]; s += 2; break;
}
}
else *(c++) = *(s++);
*c = '\0';
}
break;
case SPRINTF_: /* with expressions */
list[listtop].type = type;
list[listtop].left = left - listtop; /* has string */
list[listtop].right = right - listtop; /* expressions */
list[left].type = PRESPRINTF_;
list[left].stack_delta = 0;
list[listtop].stack_delta = -list[right].op1.argcount;
list[listtop].datatype = STRING_TYPE;
list[listtop].flags |= DEALLOCATE_POINTER;
break;
case PRINTF_: /* with expressions */
case BINARY_PRINTF_: /* with expressions */
case ERRPRINTF_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* has string */
list[listtop].right = right - listtop; /* expressions */
list[left].type = PREPRINTF_;
list[left].stack_delta = 0;
list[listtop].stack_delta = -list[right].op1.argcount-1;
break;
case EXPRLIST_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* expr */
if ( right )
{ list[listtop].right = right - listtop; /* exprlist */
list[listtop].op1.argcount = list[right].op1.argcount+1;
}
else list[listtop].op1.argcount = 1; /* arg count */
break;
case DATAFILENAME_:
case WARNING_MESSAGES_:
case GET_TRANSFORM_EXPR_:
list[listtop].type = type;
list[listtop].stack_delta = 1;
list[listtop].datatype = STRING_TYPE;
break;
case HELP_KEYWORD:
list[listtop].type = type;
list[listtop].op1.string =
(char*)mycalloc(strlen(yytext)+1,sizeof(char));
list[listtop].flags |= HAS_STRING;
strcpy(list[listtop].op1.string,yytext);
list[listtop].datatype = STRING_TYPE;
break;
default:
more_makenode(type,left,right);
break;
}
if ( listtop > listmax-2 )
kb_error(1336,"Expression too long",COMMAND_ERROR);
list[listtop].line_no = line_no;
list[listtop].file_no = file_no;
return listtop++;
}
/*********************************************************************
*
* Function: subtree_swap()
*
* Purpose: Swap two adjacent subtrees at the end of the list
* so they are in proper order for sequential execution.
*
* Return: Adjust index values in arguments.
*/
void subtree_swap ARGS2((left,right),
int *left, /* index of left subtree */
int *right) /* index of right subtree */
{ int n;
struct treenode *temp;
if ( *left && *right && (*left < *right ) )
{ int leftstart = *left, rightstart = *right;
int leftsize,rightsize;
for (;;)
{ if ( list[leftstart].left && list[leftstart].right )
{ if ( list[leftstart].left < list[leftstart].right )
leftstart += list[leftstart].left;
else leftstart += list[leftstart].right;
}
else if ( list[leftstart].left )
leftstart += list[leftstart].left;
else if ( list[leftstart].right )
leftstart += list[leftstart].right;
else break;
}
for (;;)
{ if ( list[rightstart].left && list[rightstart].right )
{ if ( list[rightstart].left < list[rightstart].right )
rightstart += list[rightstart].left;
else rightstart += list[rightstart].right;
}
else if ( list[rightstart].left )
rightstart += list[rightstart].left;
else if ( list[rightstart].right )
rightstart += list[rightstart].right;
else break;
}
if ( rightstart != *left + 1 )
{ sprintf(errmsg,
"Internal error: Left: %d-%d right: %d-%d subtrees not adjacent.\n",
leftstart,*left,rightstart,*right);
kb_error(1387,errmsg,COMMAND_ERROR);
}
/* swap subtrees */
leftsize = *left - leftstart + 1;
rightsize = *right - rightstart +1;
temp = (struct treenode*)temp_calloc(leftsize,sizeof(struct treenode));
memcpy((char*)(temp),(char*)(list+leftstart),
leftsize*sizeof(struct treenode));
kb_memmove((char*)(list+leftstart),(char*)(list+rightstart),
rightsize*sizeof(struct treenode));
memcpy((char*)(list+leftstart+rightsize),(char*)(temp),
leftsize*sizeof(struct treenode));
temp_free((char*)temp);
/* adjust subtree pointers */
*left += rightsize;
*right -= leftsize;
/* kludge to adjust pointers to local variables */
for ( n = leftstart ; n < leftstart+rightsize ; n++ )
{
if ( ((list[n].type == BREAK_) || (list[n].type == CONTINUE_)) &&
(n+leftsize+list[n].op1.skipsize < leftstart) )
list[n].op1.skipsize += leftsize;
}
for ( n = leftstart+rightsize ; n < leftstart+rightsize+leftsize ; n++ )
{
if ( ((list[n].type == BREAK_) || (list[n].type == CONTINUE_)) &&
(n-rightsize+list[n].op1.skipsize < leftstart) )
list[n].op1.skipsize -= rightsize;
}
}
}
/**********************************************************************
*
* Function: more_makenode()
*
* Purpose: Overflow from makenode(), to keep code under 32K for Mac
*/
void more_makenode ARGS3((type,left,right),
NTYPE type, NTYPE left, NTYPE right)
{ int n,etype;
switch (type)
{
case QUOTATION_:
list[listtop].type = type;
list[listtop].op1.string =
(char*)mycalloc(strlen(yytext)+1,sizeof(char));
list[listtop].flags |= HAS_STRING;
strcpy(list[listtop].op1.string,yytext);
list[listtop].stack_delta = 1;
list[listtop].datatype = STRING_TYPE;
break;
case DUMP_:
case LOAD_:
case PERMLOAD_:
case ADDLOAD_:
list[listtop].type = type;
if ( left )
{ list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
}
break;
case SINGLE_LETTER_:
list[listtop].type = SINGLE_LETTER_;
list[listtop].op1.letter = left;
break;
case SINGLE_REDEFD_:
list[listtop].type = SINGLE_REDEFD_;
list[listtop].op1.letter = left;
break;
case CMDLIST_:
list[listtop].type = type;
list[listtop].left = left - listtop;
if ( right ) list[listtop].right = right - listtop;
break;
case COMMAND_BLOCK_:
list[listtop].type = COMMAND_BLOCK_;
list[listtop].left = left - listtop;
break;
case REPEAT_INIT_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = +1;
break;
case REPEAT_:
list[listtop].type = REPEAT_;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[left].op1.skipsize = right+1-left; /* for skipping body */
list[listtop].stack_delta = -2;
break;
case EPRINT_:
list[listtop].type = type;
break;
case COND_TEST_:
list[listtop].type = COND_TEST_;
list[listtop].left = left - listtop;
/* inx will be target for false jmp */
list[listtop].stack_delta = -1;
break;
case COND_EXPR_:
list[listtop].type = COND_EXPR_;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[left].op1.skipsize = listtop - left; /* to skip TRUE part */
list[listtop].stack_delta = -1; /* since one expression skipped */
list[listtop].datatype = list[right].datatype;
break;
case COND_ELSE_: /* really the continue node at root of IF */
list[listtop].type = COND_ELSE_;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[left].op1.skipsize = listtop - left; /* to skip ELSE part */
if ( list[left].datatype != list[right].datatype )
kb_error(3710,"Datatypes disagree in conditional expression.\n",
COMMAND_ERROR);
list[listtop].datatype = list[right].datatype;
break;
case SIZEOF_ATTR_: /* current attribute dimension */
list[listtop].type = SIZEOF_ATTR_;
list[listtop].op1.extranum = left; /* attr num */
list[listtop].op2.eltype = right; /* etype */
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case SIZEOF_ARRAY_: /* current array total size */
list[listtop].type = SIZEOF_ARRAY_;
list[listtop].op1.name_id = left; /* array id */
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case SIZEOF_STRING_: /* string length */
list[listtop].type = SIZEOF_STRING_;
list[listtop].left = left-listtop; /* string expr */
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case DEFINE_CONSTRAINT_:
{ int old_verb_flag;
list[listtop].type = type;
/* Parse-time evaluation and construction of quantity */
datafile_flag = PRETEND_DATAFILE;
old_verb_flag = verb_flag; verb_flag = 0;
list[listtop].op1.con_id = read_constraint();
datafile_flag = NOT_DATAFILE;
verb_flag = old_verb_flag;
if ( tok == ';' ) /* in case reentrant parser ate ';' */
kb_unput(';');
}
break;
case DEFINE_BOUNDARY_:
{ int old_verb_flag;
list[listtop].type = type;
/* Parse-time evaluation and construction of quantity */
datafile_flag = PRETEND_DATAFILE; old_verb_flag = verb_flag; verb_flag = 0;
list[listtop].op1.bdry_id = read_boundary();
datafile_flag = NOT_DATAFILE;
verb_flag = old_verb_flag;
if ( tok == ';' ) /* in case reentrant parser ate ';' */
kb_unput(';');
}
break;
case DEFINE_QUANTITY_:
{ int old_verb_flag;
list[listtop].type = type;
/* Parse-time evaluation and construction of quantity */
datafile_flag = 1; old_verb_flag = verb_flag; verb_flag = 0;
list[listtop].op1.quant_id = read_quantity();
datafile_flag = 0;
verb_flag = old_verb_flag;
if ( tok == ';' ) /* in case reentrant parser ate ';' */
kb_unput(';');
}
break;
case DEFINE_METHOD_INSTANCE_:
{ int old_verb_flag;
list[listtop].type = type;
/* Parse-time evaluation and construction of quantity */
datafile_flag = 1; old_verb_flag = verb_flag; verb_flag = 0;
list[listtop].op1.quant_id = read_method_instance();
datafile_flag = 0;
verb_flag = old_verb_flag;
if ( tok == ';' ) /* in case reentrant parser ate ';' */
kb_unput(';');
}
break;
case IS_DEFINED_:
/* Parse-time evaluation. */
list[listtop].type = type;
list[listtop].left = left-listtop;
list[listtop].stack_delta = 0;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHCONST:
list[listtop].type = PUSHCONST;
list[listtop].op1.real = real_val;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSH_NAMED_QUANTITY:
list[listtop].type = type;
list[listtop].op1.quant_id = left;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSH_METHOD_INSTANCE_:
list[listtop].type = type;
list[listtop].op1.meth_id = left;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHPI:
list[listtop].type = type;
list[listtop].op1.real = M_PI;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHE:
list[listtop].type = type;
list[listtop].op1.real = M_E;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHG:
list[listtop].type = type;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case DATE_AND_TIME_:
list[listtop].type = type;
list[listtop].stack_delta = 1;
list[listtop].datatype = STRING_TYPE;
break;
case TOGGLEVALUE:
list[listtop].type = type;
list[listtop].op1.toggle_id = left; /* which toggle */
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case GET_TORUS_PERIODS_:
case GET_INVERSE_PERIODS_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case EXP:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = exp(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case LOG:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
if ( list[listtop].op1.real < 0.0 )
kb_error(1425,"log of negative number.\n", COMMAND_ERROR );
list[listtop].op1.real = log(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ABS:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = fabs(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case SIN:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = sin(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case SINH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = exp(list[listtop].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].op1.real = (x-1/x)/2;
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case COSH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = exp(list[listtop].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].op1.real = (x+1/x)/2;
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case TANH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = exp(list[listtop].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].op1.real = (x-1/x)/(x+1/x);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ATANH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = list[listtop].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = (log(x+1)-log(1-x))/2;
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ASINH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = list[listtop].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = log(x + sqrt(x*x+1));
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ACOSH:
if ( is_constant(left) )
{ /* fold constants */
REAL x;
listtop--;
x = list[listtop].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = 2*log(sqrt(x+1) + sqrt(x-1))-log(2.0);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ASIN:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
if ( fabs(list[listtop].op1.real) > 1.0 )
kb_error(1426,"asin argument out of bounds.\n", COMMAND_ERROR );
list[listtop].op1.real = asin(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case COS:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = cos(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ACOS:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
if ( fabs(list[listtop].op1.real) > 1.0 )
kb_error(1427,"acos argument out of bounds.\n", COMMAND_ERROR );
list[listtop].op1.real = acos(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case TAN:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = tan(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ATAN:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = atan(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case SQR:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = list[listtop].op1.real*list[listtop].op1.real;
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case SQRT:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
if ( list[listtop].op1.real < 0.0 )
kb_error(1428,"sqrt of negative number.\n", COMMAND_ERROR );
list[listtop].op1.real = sqrt(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ELLIPTICK:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = ellipticK(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case ELLIPTICE:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = ellipticE(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case CEIL_:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = ceil(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case FLOOR_:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = floor(list[listtop].op1.real);
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case CHS:
if ( is_constant(left) )
{ /* fold constants */
listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real = -list[listtop].op1.real;
break;
}
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case MAXIMUM_:
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1429,"Constant folding not working.",COMMAND_ERROR);
list[listtop].op1.real =
(list[left].op1.real > list[right].op1.real) ?
list[left].op1.real : list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
break;
}
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case MINIMUM_:
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1430,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real =
(list[left].op1.real < list[right].op1.real) ?
list[left].op1.real : list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
break;
}
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = list[right].datatype;
break;
case ATAN2_:
case INCOMPLETE_ELLIPTICF:
case INCOMPLETE_ELLIPTICE:
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1431,"Internal error: Constant folding not working.",
COMMAND_ERROR);
switch(type)
{ case ATAN2_: list[listtop].op1.real =
atan2(list[left].op1.real,list[right].op1.real);
break;
case INCOMPLETE_ELLIPTICF: list[listtop].op1.real =
incompleteEllipticF(list[left].op1.real,list[right].op1.real);
break;
case INCOMPLETE_ELLIPTICE: list[listtop].op1.real =
incompleteEllipticE(list[left].op1.real,list[right].op1.real);
break;
}
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
break;
}
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case WRAP_COMPOSE_:
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case WRAP_INVERSE_:
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
case POW:
case '^':
if ( is_constant(right) )
{ REAL p = list[right].op1.real;
if ( floor(p) == p )
{ /* integer power */
n = (int)p;
if ( n == 0 )
{ kb_error(1432,"Exponent 0. Did you mean this?\n",WARNING);
listtop--;
list[listtop].type = REPLACECONST;
list[listtop].op1.real = 1.0;
break;
}
else if ( n == 1 )
{ /* leave alone */
kb_error(1433,"Exponent 1. Did you mean this?\n",WARNING);
listtop-=2;
break;
}
else if ( n == 2 )
{ listtop--;
if ( is_constant(left) )
{ listtop--;
list[listtop].type = PUSHCONST;
list[listtop].op1.real *= list[listtop].op1.real;
list[listtop].stack_delta = 1;
}
else
{ list[listtop].type = SQR;
list[listtop].left = left - listtop;
list[listtop].stack_delta = 0;
}
break;
}
else if ( n == -1 )
{ listtop--;
if ( is_constant(left) )
{ listtop--;
list[listtop].op1.real = 1./list[listtop].op1.real;
}
else
{ list[listtop].type = INV;
list[listtop].left = left - listtop;
list[listtop].stack_delta = 0;
}
break;
}
/* general */
if ( is_constant(left) )
{ /* fold constants */
int k;
REAL x;
listtop -= 2;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
if ( left != listtop )
kb_error(1434,"Internal error: Constant folding not working.",
COMMAND_ERROR);
x = list[left].op1.real;
for ( k = 1 ; k < abs(n) ; k++ )
list[left].op1.real *= x;
if ( n < 0 )
list[left].op1.real = 1/list[left].op1.real;
break;
}
listtop--; /* pop constant power */
list[listtop].left = left - listtop;
list[listtop].op1.intpow = n;
list[listtop].type = INTPOW;
break;
}
}
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1435,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real =
pow(list[left].op1.real,list[right].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
break;
}
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case '+':
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1436,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = list[left].op1.real + list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else if ( is_constant(right) && (list[right].op1.real==0.0) )
listtop -= 2; /* just leave left summand */
else if ( is_constant(left) && (list[left].op1.real==0.0) )
{ subtree_swap(&left,&right);
listtop -= 2;
}
else
{
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = PLUS;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case '-':
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1437,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = list[left].op1.real - list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else if ( is_constant(right) && (list[right].op1.real==0.0) )
listtop -= 2; /* just leave left summand */
else if ( is_constant(left) && (list[left].op1.real==0.0) )
{ subtree_swap(&left,&right);
listtop -= 1;
list[listtop].left = right - listtop;
list[listtop].type = CHS;
list[listtop].stack_delta = 0;
}
else
{
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = MINUS;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case '=': /* equality as low priority minus */
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1438,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = list[left].op1.real - list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else if ( is_constant(right) && (list[right].op1.real==0.0) )
listtop -= 2; /* just leave left summand */
else
{
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = EQUATE;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case '*':
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1439,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = list[left].op1.real * list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else if ( is_constant(left) && (list[left].op1.real==0.0) )
{
listtop = left; /* just leave 0 */
}
else if ( ( is_constant(right) && (list[right].op1.real==0.0) ) )
{ subtree_swap(&left,&right);
listtop = right; /* just leave 0 */
}
else if ( is_constant(right) && (list[right].op1.real==1.0) )
listtop -= 2; /* just leave left multiplicand */
else if ( is_constant(left) && (list[left].op1.real==1.0) )
{ subtree_swap(&left,&right);
listtop -= 2;
}
else
{
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = TIMES;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case '/':
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1440,"Internal error: Constant folding not working.",
COMMAND_ERROR);
if ( list[right].op1.real == 0.0 )
{
kb_error(1441,"Divide by zero.",COMMAND_ERROR);
}
list[listtop].op1.real = list[left].op1.real / list[right].op1.real;
list[listtop].type = PUSHCONST;
}
else if ( is_constant(left) && (list[left].op1.real==0.0) )
{ listtop = left; /* just leave 0 */
list[listtop].op1.real = 0.0;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else if ( is_constant(right) && (list[right].op1.real==0.0) )
kb_error(1442,"Divide by zero.",COMMAND_ERROR);
else if ( is_constant(right) && (list[right].op1.real==1.0) )
listtop -= 2; /* just leave numerator */
else
{
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = DIVIDE;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case '%':
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1443,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = list[left].op1.real -
floor(list[left].op1.real / list[right].op1.real)
*list[right].op1.real;
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else
{ list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = REALMOD;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case IMOD_:
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1444,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real = floor(list[left].op1.real) -
floor(floor(list[left].op1.real)/floor(list[right].op1.real))
*floor(list[right].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else
{ list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = IMOD_;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case IDIV_:
if ( is_constant(right) && is_constant(left) )
{ /* fold constants */
listtop -= 2;
if ( (left != listtop) || (right != listtop+1) )
kb_error(1445,"Internal error: Constant folding not working.",
COMMAND_ERROR);
list[listtop].op1.real =
(int)(list[left].op1.real)/(int)(list[right].op1.real);
list[listtop].type = PUSHCONST;
list[listtop].stack_delta = 1;
}
else
{ list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = IDIV_;
list[listtop].stack_delta = -1;
}
list[listtop].datatype = REAL_TYPE;
break;
case PUSHPARAM:
if ( maxp == 0 )
kb_error(1446,"Constant expression required.\n",EXPRESSION_ERROR);
list[listtop].type = PUSHPARAM;
list[listtop].op1.coordnum = n = coord_num-1;
if ( (n < 0) || (n >= maxp) )
{
sprintf(errmsg,"Coordinate number too high: %d\n",n+1);
kb_error(1447,errmsg,EXPRESSION_ERROR);
}
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case USERFUNC:
list[listtop].type = USERFUNC;
list[listtop].op1.userfunc = (NTYPE)int_val-1;
if ( int_val < 1 || (userfunc[int_val-1] == NULL) )
{ sprintf(errmsg,"Invalid user function number: %d\n",int_val);
kb_error(1448,errmsg,EXPRESSION_ERROR);
}
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case VIEW_MATRIX_:
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case GET_INTERNAL_:
list[listtop].type = GET_INTERNAL_;
list[listtop].op1.name_id = left;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHQPRESSURE_:
case PUSHQTARGET_:
case PUSHQVALUE_:
case PUSHQMODULUS_:
case PUSHQTOLERANCE_:
case PUSHMMODULUS_:
case PUSHQVOLCONST_:
case PUSHQPARAMETER_1_:
case PUSHQFIXED_:
case PUSHQENERGY_:
case PUSHQCONSERVED_:
case PUSHQINFO_ONLY_:
list[listtop].type = type;
list[listtop].op1.quant_id = left;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHMVALUE_:
list[listtop].type = type;
list[listtop].op1.meth_id = left;
if ( reading_comp_quant_flag )
{ int i;
struct gen_quant *q = GEN_QUANT(cur_quant);
METH_INSTANCE(left)->flags |= Q_COMPOUND;
/* see if in quantity's list */
for ( i = 0 ; i < q->method_count ; i++ )
if ( q->meth_inst[i] == left )
break;
if ( i == q->method_count )
{ /* add to list */
METH_INSTANCE(left)->quant = cur_quant;
METH_INSTANCE(left)->quant_index = q->method_count;
attach_method_num(cur_quant,left);
}
}
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case VIEW_MATRIX_LVALUE_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
break;
case SET_VIEW_MATRIX_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].right = right - listtop;
list[listtop].op2.assigntype = assigntype;
list[listtop].stack_delta = -3;
break;
case SET_QMODULUS_:
case SET_QTOLERANCE_:
case SET_MMODULUS_:
case SET_QVOLCONST_:
case SET_QTARGET_:
case SET_QPARAMETER_1_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].op1.quant_id = right;
list[listtop].op2.assigntype = assigntype;
list[listtop].stack_delta = -1;
break;
case DYNAMIC_LOAD_FUNC_:
list[listtop].type = DYNAMIC_LOAD_FUNC_;
list[listtop].op1.funcptr = globals(left)->value.funcptr;
list[listtop].op2.name_id = left;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHDELTA_:
case PUSH_PARAM_SCALE:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSH_PARAM_FIXED:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSH_PARAM_EXTRA_:
if ( (right != V_VELOCITY_ATTR) && (right != V_FORCE_ATTR) )
kb_error(2473,"Illegal attribute of variable.\n",COMMAND_ERROR);
list[listtop].type = type;
list[listtop].op1.name_id = left; /* which parameter */
list[listtop].op2.extranum = right; /* which attribute */
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case PUSHGLOBAL_:
{
struct global *g = globals(left);
list[listtop].type = PUSHGLOBAL_;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
if ( (g->flags & METHOD_NAME) && reading_comp_quant_flag )
{ struct method_instance *mi=METH_INSTANCE(left);
mi->flags |= Q_COMPOUND;
quant_flags[basic_gen_methods[mi->gen_method].type]
|= GEN_QUANT(cur_quant)->flags &
(Q_ENERGY|Q_FIXED|Q_INFO|Q_CONSERVED);
attach_method_num(cur_quant,left);
}
list[listtop].datatype = (g->type <= MAX_NUMERIC_TYPE) ? REAL_TYPE :
g->type;
list[listtop].stack_delta = 1;
break;
}
case PUSH_PERM_GLOBAL_:
case PERM_STRINGGLOBAL_:
{ struct global *g;
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].stack_delta = 1;
g = globals(left);
list[listtop].datatype = g->type <= MAX_NUMERIC_TYPE ? REAL_TYPE :
g->type;
break;
}
case PERM_PROCEDURE_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
break;
case STRINGGLOBAL_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = STRING_TYPE;
break;
case PROCEDURE_:
list[listtop].type = type;
list[listtop].op1.name_id = left;
list[listtop].flags |= EPHEMERAL;
break;
case SET_CONSTRAINT_GLOBAL:
case UNSET_CONSTRAINT_GLOBAL:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].stack_delta = -1;
break;
case SET_CONSTRAINT_NAME_GLOBAL:
case UNSET_CONSTRAINT_NAME_GLOBAL:
list[listtop].type = type;
list[listtop].stack_delta = 0;
list[listtop].op3.connum = globals(left)->value.cnum;
break;
case ON_CONSTRAINT_:
case HIT_CONSTRAINT_:
case ON_BOUNDARY_:
list[listtop].type = type;
list[listtop].left = left - listtop;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 0;
list[listtop].datatype = REAL_TYPE;
break;
case ON_CONSTRAINT_NAME:
case HIT_CONSTRAINT_NAME:
list[listtop].type = type;
list[listtop].op3.connum = globals(left)->value.cnum;
/* actual constraint number */
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case ON_BOUNDARY_NAME:
list[listtop].type = type;
list[listtop].op3.bdrynum = globals(left)->value.bnum;
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case ON_QUANTITY_:
list[listtop].type = type;
list[listtop].op2.quant_id = left;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case ON_METHOD_INSTANCE_:
list[listtop].type = type;
list[listtop].op2.meth_id = left;
list[listtop].stack_delta = 1;
list[listtop].datatype = REAL_TYPE;
break;
case INDEXED_COORD_:
list[listtop].type = type;
list[listtop].left = left - listtop;
if ( list[left].op1.indexcount != 1 )
kb_error(2568,"Coordinate can have only one index.\n",COMMAND_ERROR);
list[listtop].datatype = REAL_TYPE;
break;
case PRINT_VERTEXNORMAL_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* element */
break;
case GET_VERTEXNORMAL_:
list[listtop].type = type;
list[listtop].left = left - listtop; /* index set */
if ( list[left].op1.indexcount != 1 )
kb_error(2569,"Vertexnormal can have only one index.\n",
COMMAND_ERROR);
list[listtop].datatype = REAL_TYPE;
break;
case INDEXED_ATTRIBUTE: /* get extra attribute value */
{ struct extra *ex;
etype = (unsigned)right >> YYTYPESHIFT;
right = right & YYSHIFTMASK;
ex = EXTRAS(etype) + right;
list[listtop].type = GET_EXTRA_ATTR_;
list[listtop].op2.eltype = etype;
list[listtop].op3.extranum = right; /* which extra */
list[listtop].left = left - listtop; /* index */
list[listtop].stack_delta = 1 - ex->array_spec.dim;
if ( ex->array_spec.dim != list[left].op1.indexcount )
{ sprintf(errmsg,"Attribute %s must have %d indices.\n",
ex->name,ex->array_spec.dim);
kb_error(2513,errmsg,COMMAND_ERROR);
}
list[listtop].flags |= EPHEMERAL;
}
break;
case PRINT_ATTR_ARRAY_: /* print element attribute array or slice */
{ struct extra *ex;
int exnum;
etype = int_val >> YYTYPESHIFT;
exnum = int_val & YYSHIFTMASK;
ex = EXTRAS(etype) + exnum;
list[listtop].type = type;
list[listtop].op1.indexcount = right ? list[right].op1.indexcount : 0; /* indices */
list[listtop].op2.eltype = etype;
list[listtop].op3.extranum = exnum; /* which extra */
list[listtop].left = left - listtop; /* element */
if ( right ) list[listtop].right = right - listtop; /* index */
if ( ex->array_spec.dim < list[right].op1.indexcount )
{ sprintf(errmsg,"Attribute %s must have at most %d indices.\n",
ex->name,ex->array_spec.dim);
kb_error(2644,errmsg,COMMAND_ERROR);
}
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = -list[listtop].op1.indexcount;
}
break;
case QUALIFIED_ATTRIBUTE:
list[listtop].type = QUALIFIED_ATTRIBUTE;
list[listtop].left = left-listtop;
list[listtop].right = right-listtop;
list[listtop].datatype = REAL_TYPE;
etype = list[left].op1.eltype; /* element type */
/* element type error checking */
check_element_type(list[right].type,etype);
break;
case ATTRIBUTE:
list[listtop].type = (NTYPE)left;
/* some special treatments */
switch ( left )
{
case COORD_: list[listtop].op2.coordnum = right-1;
if ( right > SDIM )
kb_error(2475,"Coordinate dimension exceeds space dimension.\n",
COMMAND_ERROR);
break;
case PARAM_: list[listtop].op2.coordnum = right-1;
using_param_flag = 1;
break;
case GET_INSTANCE_:
case GET_QUANTITY_: list[listtop].op2.quant_id = right;
break;
case GET_EXTRA_ATTR_:
{ struct extra *ex;
etype = (unsigned)right >> YYTYPESHIFT;
ex = EXTRAS(etype) + (right & YYSHIFTMASK);
if ( ex->array_spec.dim > 0 )
{ sprintf(errmsg,
"\"%s\" is an indexed attribute; index is missing. Or use element name to print as full array.\n",
ex->name);
kb_error(2634,errmsg,Q_ERROR);
}
list[listtop].op2.eltype = etype;
list[listtop].op3.extranum = (right & YYSHIFTMASK);
list[listtop].flags |= EPHEMERAL;
list[listtop].stack_delta = 1-ex->array_spec.dim;
}
break;
}
if ( left != GET_EXTRA_ATTR_ )
list[listtop].stack_delta = 1;
break;
case SET_ATTRIBUTE_:
case SET_ATTRIBUTE_L:
case SET_ATTRIBUTE_A:
if ( elsym == NULL )
kb_error(1477,"Don't have element for attribute to apply to.\n",
COMMAND_ERROR);
list[listtop].type = type;
if ( left ) list[listtop].left = left-listtop; /* value */
if ( right )
{ /* index; check which attributes are legal */
list[listtop].right = right-listtop;
switch ( attr_kind )
{ case SET_EXTRA_ATTR_:
list[listtop].flags |= EPHEMERAL;
break;
case SET_COORD_1: case SET_PARAM_1: break;
default: kb_error(1478,"Attribute is not indexed.\n",COMMAND_ERROR);
}
}
list[listtop].op1.localnum = elsym->localnum;
list[listtop].op2.attr_kind = attr_kind;
/* to node */
/* error checking on attributes and element types */
etype = elsym->type;
switch ( attr_kind )
{
case SET_EXTRA_ATTR_:
{ struct extra *ex;
ex = EXTRAS(etype);
for ( n = 0 ; n < web.skel[etype].extra_count ; n++,ex++ )
if ( stricmp(ex->name,set_extra_name) == 0 ) break;
if ( n == web.skel[etype].extra_count )
{ sprintf(errmsg,"Invalid extra attribute name '%s'.\n",
set_extra_name);
kb_error(1479,errmsg,COMMAND_ERROR);
}
list[listtop].op3.extra_info = (etype << ESHIFT) + n;
if ( !(ex->flags & DIMENSIONED_ATTR) && right )
{ sprintf(errmsg,"Cannot use index with attribute '%s'.\n",ex->name);
kb_error(2499,errmsg,COMMAND_ERROR);
}
if ( (ex->flags & DIMENSIONED_ATTR) && !right )
{ sprintf(errmsg,"Must use index with attribute '%s'.\n",ex->name);
kb_error(1481,errmsg,COMMAND_ERROR);
}
if ( right && (list[right].op1.indexcount != ex->array_spec.dim) )
{ sprintf(errmsg,"Attribute '%s' has %d indexes.\n",
ex->name,ex->array_spec.dim);
kb_error(2498,errmsg,COMMAND_ERROR);
}
list[listtop].stack_delta = -1-ex->array_spec.dim;
}
break;
case SET_WRAP_:
if ( etype != EDGE )
kb_error(2239,"Wrap only for edges.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_COORD_: case SET_COORD_1: case SET_COORD_2:
case SET_COORD_3: case SET_COORD_4: case SET_COORD_5:
case SET_COORD_6: case SET_COORD_7: case SET_COORD_8:
if ( attr_kind-SET_COORD_1 >= SDIM )
kb_error(2543,"Coordinate dimension exceeds space dimension.\n",
COMMAND_ERROR);
if ( etype != VERTEX )
kb_error(1482,"Coordinates only for vertices.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_PARAM_: case SET_PARAM_1: case SET_PARAM_2:
case SET_PARAM_3: case SET_PARAM_4:
if ( etype != VERTEX )
kb_error(1483,"Boundary parameters only for vertices.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_TAG_:
if ( etype != FACET )
kb_error(1484,"Tag only for facets now.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_OPACITY_:
if ( etype != FACET )
kb_error(1485,"Opacity only for facets.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_FRONTCOLOR_:
case SET_BACKCOLOR_:
if ( (etype != FACET) )
kb_error(1304,"Front or back color only for facets.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_FRONTBODY_:
case SET_BACKBODY_:
if ( web.representation == STRING )
{ if ( (etype != FACET) && (etype != EDGE) )
kb_error(1486,
"Frontbody or backbody only for facets or edges in string model.\n",
COMMAND_ERROR);
}
else if (etype != FACET)
kb_error(1308,"Frontbody or backbody only for facets.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_COLOR_:
if ( !((etype == FACET) || (etype == EDGE)) )
kb_error(1487,"Color only for edges or facets.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_VOLCONST_:
if ( etype != BODY )
kb_error(1488,"Volconst only for bodies.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_TARGET_:
if ( etype != BODY )
kb_error(1489,"Target volume only for bodies.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_VOLUME_:
if ( etype != BODY )
kb_error(1490,"Target volume only for bodies.\n",COMMAND_ERROR);
kb_error(1491,
"Volume is read-only. Setting TARGET instead.\n",
WARNING);
list[listtop].op2.attr_kind = SET_TARGET_;
list[listtop].stack_delta = -1;
break;
case SET_PRESSURE_:
if ( etype != BODY )
kb_error(1492,"Pressure only for bodies.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_PHASE_:
case SET_CONSTRAINT_:
case SET_BOUNDARY_:
case SET_ORIGINAL_:
list[listtop].stack_delta = -1;
break;
case SET_DENSITY_:
if ( etype == VERTEX )
kb_error(1493,"No density for vertices.\n",COMMAND_ERROR);
list[listtop].stack_delta = -1;
break;
case SET_FIXED_:
if ( etype == FACETEDGE )
kb_error(2527,"No fixedness for facetedges.\n",COMMAND_ERROR);
if ( etype == BODY )
kb_error(2528,"Use 'set body target ...' to fix volume.\n",
COMMAND_ERROR);
break;
case SET_HIT_PARTNER_:
if ( etype != VERTEX )
kb_error(3002,"Hit_partner is only for vertices.\n",COMMAND_ERROR);
break;
case SET_NO_DISPLAY_:
if ( etype != FACET )
kb_error(1495,"No_display is only for facets.\n",COMMAND_ERROR);
break;
case SET_NO_REFINE_:
if ( etype == BODY || etype == VERTEX )
kb_error(1496,"No no_refine for vertices or bodies.\n",
COMMAND_ERROR);
break;
case SET_NONCONTENT_:
if ( ((web.representation == STRING) && (etype != EDGE)) ||
((web.representation != STRING) && (etype != FACET)) )
kb_error(2903,"Noncontent only applies to edges or facets.\n",
COMMAND_ERROR);
break;
}
/* error checking for arithmetic assigns */
if ( type == SET_ATTRIBUTE_A )
{ switch ( attr_kind )
{ case SET_FIXED_: case SET_TRIPLE_PT_: case SET_TETRA_PT_:
case SET_AXIAL_POINT_:
kb_error(2241,"Cannot assign value to this attribute with :=.\n",
COMMAND_ERROR);
}
if ( assigntype != ASSIGN_ )
switch ( attr_kind )
{ case SET_ORIENTATION_: case SET_PHASE_: case SET_OPACITY_:
case SET_CONSTRAINT_: case SET_ORIGINAL_: case SET_COLOR_:
case SET_FRONTCOLOR_: case SET_BACKCOLOR_: case SET_WRAP_:
case SET_TAG_: case SET_FRONTBODY_: case SET_BACKBODY_:
case SET_BOUNDARY_:
kb_error(2242,
"Cannot use arithmetic assign with this attribute.\n",
COMMAND_ERROR);
}
}
break;
case EQ_:
case NE_:
case GE_:
case LE_:
case GT_:
case LT_:
list[listtop].right = right - listtop;
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
case AND_: /* for short-circuit evaluation, have to move test */
case OR_: /* node between operands */
{ int top;
top = listtop;
list[listtop].type = type;
subtree_swap(&right,&top);
list[top].right = right - top;
list[top].left = left - top;
list[top].op1.skipsize = listtop - top;
listtop++;
list[listtop].type = CONJUNCTION_END;
list[listtop].left = top - listtop;
list[listtop].stack_delta = -1;
list[listtop].datatype = REAL_TYPE;
break;
}
case NOT_:
list[listtop].left = left - listtop;
list[listtop].type = type;
list[listtop].datatype = REAL_TYPE;
break;
default:
sprintf(errmsg,"Internal error: Unknown MAKENODE %d type %s\n",type,tokname(type));
kb_error(1329,errmsg,COMMAND_ERROR);
}
}
/******************************************************************
*
* Function: is_constant()
*
* Purpose: See if tree node type is a constant value.
* Also checks that datatype is REAL_TYPE.
*/
int is_constant ARGS1((node),
int node)
{
if ( list[node].datatype != REAL_TYPE )
kb_error(3711,"Operand datatype is not numeric.\n",
datafile_flag ? DATAFILE_ERROR : COMMAND_ERROR);
switch(list[node].type)
{ case PUSHPI:
case PUSHE:
case PUSHCONST:
return 1;
default:
return 0;
}
}
/**********************************************************************
*
* Function: check_element_type()
*
* purpose: see if attribute is legal for element
*/
void check_element_type ARGS2((attrib,etype),
int attrib,
int etype)
{
switch ( attrib )
{
case GET_TAG_:
if ( etype != FACET )
kb_error(1455,"Tag only for facets now.\n",COMMAND_ERROR);
break;
case GET_MIDV_:
if ( etype != EDGE )
kb_error(1456,"Midv only for quadratic edges.\n",COMMAND_ERROR);
break;
case GET_SQ_MEAN_CURV_:
if ( etype != VERTEX )
kb_error(1457,"Square mean curvature only for vertices.\n",
COMMAND_ERROR);
break;
case GET_FRONTBODY_:
case GET_BACKBODY_:
if ( (etype != FACET) && !((etype==EDGE)&&(web.representation==STRING)))
kb_error(1297,"Frontbody or backbody only for facets, or string model edges.\n",
COMMAND_ERROR);
break;
case GET_FRONTCOLOR_:
case GET_BACKCOLOR_:
if ( (etype != FACET) )
kb_error(1458,"Frontcolor or backcolor only for facets.\n",COMMAND_ERROR);
break;
case GET_COLOR_:
if ( !((etype == FACET) || (etype == EDGE)) )
kb_error(1459,"Color only for edges or facets.\n",COMMAND_ERROR);
break;
case BARE_:
if ( (etype == BODY) || (etype == FACET) )
kb_error(1460,"No bareness for facets or bodies.\n",COMMAND_ERROR);
break;
case GET_SHOW_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(2243,"\"Show\" only for edges or facets.\n",COMMAND_ERROR);
break;
case GET_ORIENTATION_:
if ( (etype != EDGE) && (etype != FACET) )
kb_error(1461,"Orientation only for edges or facets.\n",COMMAND_ERROR);
break;
case GET_LENGTH_:
if ( etype != EDGE )
kb_error(1462,"Length only for edges.\n",COMMAND_ERROR);
break;
case GET_MEANCURV_:
if ( etype != VERTEX )
kb_error(2872,"Mean_curvature only for vertices.\n",COMMAND_ERROR);
if ( web.representation == SIMPLEX )
kb_error(4567,
"Mean_curvature attribute implemented only for string and soapfilm models.\n",
RECOVERABLE);
break;
case GET_VERTEXNORMAL_:
if ( etype != VERTEX )
kb_error(2244,"Facetnormal only for edges.\n",COMMAND_ERROR);
break;
case GET_FIXEDVOL_:
if ( etype != BODY )
kb_error(1463,"Fixedvol only for bodies.\n",COMMAND_ERROR);
break;
case GET_WRAP_:
if ( etype != EDGE )
kb_error(1464,"Wrap only for edges.\n",COMMAND_ERROR);
break;
case GET_MID_EDGE_:
if ( etype != VERTEX )
kb_error(3112,"Mid_edge only for vertices.\n",COMMAND_ERROR);
break;
case GET_MID_FACET_:
if ( etype != VERTEX )
kb_error(3113,"Mid_facet only for vertices.\n",COMMAND_ERROR);
break;
case GET_DIHEDRAL_:
if ( web.representation == SOAPFILM )
{ if (etype != EDGE)
kb_error(1465,"Dihedral only for edges.\n",COMMAND_ERROR);
}
else if ( web.representation == STRING )
{ if (etype != VERTEX)
kb_error(1466,"Dihedral only for vertices.\n",COMMAND_ERROR);
}
else
kb_error(1467,
"Dihedral defined only for STRING and SOAPFILM models.\n",COMMAND_ERROR);
break;
case GET_AREA_:
if ( etype != FACET )
kb_error(1468,"Area only for facets.\n",COMMAND_ERROR);
break;
case GET_EDGE_:
if ( etype != FACETEDGE )
kb_error(1469,"Edge only for facetedges.\n",COMMAND_ERROR);
break;
case GET_FACET_:
if ( etype != FACETEDGE )
kb_error(1470,"Facet only for facetedges.\n",COMMAND_ERROR);
break;
case GET_TARGET_:
if ( etype != BODY )
kb_error(1471,"Target only for bodies.\n",COMMAND_ERROR);
break;
case GET_VOLCONST_:
if ( etype != BODY )
kb_error(1472,"Volconst only for bodies.\n",COMMAND_ERROR);
break;
case GET_VOLUME_:
if ( etype != BODY )
kb_error(1473,"Volume only for bodies.\n",COMMAND_ERROR);
break;
case GET_DENSITY_:
if ( etype == VERTEX )
kb_error(1474,"No density for vertices.\n",COMMAND_ERROR);
break;
case SET_HIT_PARTNER_:
if ( etype != VERTEX )
kb_error(3003,"Hit_partner only for vertices.\n",
COMMAND_ERROR);
break;
case SET_NO_REFINE_:
if ( etype == BODY || etype == VERTEX )
kb_error(1494,"No no_refine for vertices or bodies.\n",
COMMAND_ERROR);
break;
case SET_NO_DISPLAY_:
if ( etype != FACET )
kb_error(1320,"No_display is only for facets.\n",
COMMAND_ERROR);
break;
}
}
/**********************************************************************
*
* function: check_array_dims_same()
*
* purpose: see if two arrays are of the same dimensionality (i.e
* same number of indices, not number of elements).
* Also of same type.
*
* return: 1 if same, 0 if not.
*/
int check_array_dims_same(
int left, /* id number of array */
int right) /* id number of second array */
{
struct array *alvalue;
struct array *arvalue;
int adim,atype,bdim,btype;
if ( (left & GTYPEMASK) == ATTRIBNAME )
{ struct extra *ex = EXTRAS(name_eltype(left)) + (left & GLOBMASK);
alvalue = &(ex->array_spec);
adim = alvalue->dim;
atype = alvalue->datatype;
}
else
{ struct global *glvalue = globals(left);
adim = glvalue->attr.arrayptr->dim;
atype = glvalue->type;
}
if ( (right & GTYPEMASK) == ATTRIBNAME )
{ struct extra *ex = EXTRAS(name_eltype(right)) + (right & GLOBMASK);
arvalue = &(ex->array_spec);
bdim = arvalue->dim;
btype = arvalue->datatype;
}
else
{ struct global *grvalue = globals(right);
arvalue = grvalue->attr.arrayptr;
bdim = grvalue->attr.arrayptr->dim;
btype = grvalue->type;
}
if ( atype != btype )
return 0;
return adim == bdim;
}
/*********************************************************************
*
* function: check_recalc_attr()
*
* Purpose: see if attribute has RECALC_ATTR flag bit set.
*/
int check_recalc_attr(int name_id)
{
if ( (name_id & GTYPEMASK) == ATTRIBNAME )
{ struct extra *ex = EXTRAS(name_eltype(name_id)) + (name_id & GLOBMASK);
return ex->flags & RECALC_ATTR;
}
return 0;
}
/*********************************************************************
*
* function: check_readonly_attr()
*
* purpose: See if left side of assignment is to read-only attribute.
*/
void check_readonly_attr(int name_id)
{
if ( (name_id & GTYPEMASK) == ATTRIBNAME )
{ if ( name_id == set_name_eltype(V_NORMAL_ATTR,VERTEX) )
kb_error(3017,"__vertex_normal is a read-only attribute.\n",
COMMAND_ERROR);
if ( name_id == set_name_eltype(E_VECTOR_ATTR,EDGE) )
kb_error(3016,"__e_vector is a read-only attribute.\n",
COMMAND_ERROR);
if ( name_id == set_name_eltype(F_NORMAL_ATTR,FACET) )
kb_error(3018,"__e_vector is a read-only attribute.\n",
COMMAND_ERROR);
}
} /* end check_readonly_attr() */
/*********************************************************************
*
* function: check_special_attr()
*
* purpose: Tell user that calculated attributes on right side are
* only implemented as lone terms.
*/
void check_special_attr(int name_id)
{
if ( (name_id & GTYPEMASK) == ATTRIBNAME )
{ if ( name_id == set_name_eltype(V_NORMAL_ATTR,VERTEX) )
kb_error(3123,"__vertex_normal term must be lone term on right side.\n",
COMMAND_ERROR);
if ( name_id == set_name_eltype(E_VECTOR_ATTR,EDGE) )
kb_error(3024,"__e_vector term must be lone term on right side.\n",
COMMAND_ERROR);
if ( name_id == set_name_eltype(F_NORMAL_ATTR,FACET) )
kb_error(3124,"__e_vector term must be lone term on right side.\n",
COMMAND_ERROR);
}
}
|