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
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: GdlExpression.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.
Description:
Implement the various kinds of arithmetic and logical expressions that can appear in an
GDL file.
-------------------------------------------------------------------------------*//*:End Ignore*/
/***********************************************************************************************
Include files
***********************************************************************************************/
#include "main.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE
/***********************************************************************************************
Forward declarations
***********************************************************************************************/
/***********************************************************************************************
Local Constants and static variables
***********************************************************************************************/
/***********************************************************************************************
Methods: Parser
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Propagate the line number down to the sub-items.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
{
SetLineAndFile(lnf);
m_pexpOperand->PropagateLineAndFile(lnf);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
{
SetLineAndFile(lnf);
m_pexpOperand1->PropagateLineAndFile(lnf);
m_pexpOperand2->PropagateLineAndFile(lnf);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
{
SetLineAndFile(lnf);
m_pexpTest->PropagateLineAndFile(lnf);
m_pexpTrue->PropagateLineAndFile(lnf);
if (m_pexpFalse)
m_pexpFalse->PropagateLineAndFile(lnf);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
{
SetLineAndFile(lnf);
if (m_pexpSelector)
m_pexpSelector->PropagateLineAndFile(lnf);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
SetLineAndFile(lnf);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
SetLineAndFile(lnf);
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::PropagateLineAndFile(GrpLineAndFile & lnf)
{
if (LineIsZero())
SetLineAndFile(lnf);
}
/***********************************************************************************************
Methods: Post-parser
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Return true if it make sense to add, subtract, or compare two expressions with the given
types.
----------------------------------------------------------------------------------------------*/
bool EquivalentTypes(ExpressionType expt1, ExpressionType expt2)
{
if (expt1 == expt2)
return true;
if (expt1 == kexptZero || expt1 == kexptOne)
{
switch (expt2)
{
case kexptNumber:
case kexptMeas:
case kexptBoolean:
case kexptZero:
case kexptOne:
return true;
default:
break;
}
}
if (expt2 == kexptZero || expt2 == kexptOne)
{
switch (expt1)
{
case kexptNumber:
case kexptMeas:
case kexptBoolean:
case kexptZero:
case kexptOne:
return true;
default:
break;
}
}
return false;
}
/*----------------------------------------------------------------------------------------------
Replace any slot aliases with the corresponding (1-based) index.
Arguments:
prule - the rule that contains the list of slot-alias mappings
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::ReplaceAliases(GdlRule * prule)
{
return m_pexpOperand->ReplaceAliases(prule);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::ReplaceAliases(GdlRule * prule)
{
if (!m_pexpOperand1->ReplaceAliases(prule))
return false;
return m_pexpOperand2->ReplaceAliases(prule);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::ReplaceAliases(GdlRule * prule)
{
if (!m_pexpTest->ReplaceAliases(prule))
return false;
if (!m_pexpTrue->ReplaceAliases(prule))
return false;
if (m_pexpFalse)
return m_pexpFalse->ReplaceAliases(prule);
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::ReplaceAliases(GdlRule * prule)
{
if (m_pexpSelector)
return m_pexpSelector->ReplaceAliases(prule);
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::ReplaceAliases(GdlRule * /*prule*/)
{
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::ReplaceAliases(GdlRule * prule)
{
if (m_srNumber == -1)
{
m_srNumber = prule->LookupAliasIndex(m_staName);
if (m_srNumber < 1)
{
g_errorList.AddError(1101, this,
"Undefined slot alias: ",
m_staName);
m_srNumber = 0;
return false;
}
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::ReplaceAliases(GdlRule * /*prule*/)
{
return true;
}
/*----------------------------------------------------------------------------------------------
Adjust the slot references based on what optional slots were omitted.
Return false if there was a reference to an omitted item.
Arguments:
vfOmit - for each item, was it omitted?
vnNewIndices - for the items that were not omitted, the adjusted index
prule - the rule that contains the list of slot-alias mappings, for
interpreting slot-ref expressions that use names
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::AdjustSlotRefs(std::vector<bool> & vfOmit, std::vector<int> & vnNewIndices,
GdlRule * prule)
{
return m_pexpOperand->AdjustSlotRefs(vfOmit, vnNewIndices, prule);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::AdjustSlotRefs(std::vector<bool> & vfOmit, std::vector<int> & vnNewIndices,
GdlRule * prule)
{
if (!m_pexpOperand1->AdjustSlotRefs(vfOmit, vnNewIndices, prule))
return false;
return m_pexpOperand2->AdjustSlotRefs(vfOmit, vnNewIndices, prule);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::AdjustSlotRefs(std::vector<bool> & vfOmit, std::vector<int> & vnNewIndices,
GdlRule * prule)
{
if (!m_pexpTest->AdjustSlotRefs(vfOmit, vnNewIndices, prule))
return false;
if (!m_pexpTrue->AdjustSlotRefs(vfOmit, vnNewIndices, prule))
return false;
if (m_pexpFalse)
return m_pexpFalse->AdjustSlotRefs(vfOmit, vnNewIndices, prule);
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::AdjustSlotRefs(std::vector<bool> & vfOmit, std::vector<int> & vnNewIndices,
GdlRule * prule)
{
if (m_pexpSelector)
return m_pexpSelector->AdjustSlotRefs(vfOmit, vnNewIndices, prule);
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::AdjustSlotRefs(std::vector<bool> & /*vfOmit*/, std::vector<int> & /*vnNewIndices*/,
GdlRule * /*prule*/)
{
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::AdjustSlotRefs(std::vector<bool> & vfOmit, std::vector<int> & vnNewIndices,
GdlRule * prule)
{
int sr = m_srNumber;
if (m_srNumber == -1)
{
sr = prule->LookupAliasIndex(m_staName);
if (sr < 1)
{
g_errorList.AddError(1102, this,
"Undefined slot alias: ",
m_staName);
return false;
}
}
if (vfOmit[sr-1])
{
if (m_staName == "")
{
char rgch[20];
itoa(m_srNumber, rgch, 10);
g_errorList.AddError(1103, this,
"Optional item referenced: ",
rgch);
}
else
g_errorList.AddError(1103, this,
"Optional item referenced: ",
m_staName);
return false;
}
m_srNumber = vnNewIndices[sr-1];
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::AdjustSlotRefs(std::vector<bool> & /*vfOmit*/, std::vector<int> & /*vnNewIndices*/,
GdlRule * /*prule*/)
{
return true;
}
/*----------------------------------------------------------------------------------------------
Set the return argument to the value of the expression as an integer if it can be
calculated without any context; otherwise return false.
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::ResolveToInteger(int * pnRet, bool fSlotRef)
{
int nTmp;
if (!m_pexpOperand->ResolveToInteger(&nTmp, fSlotRef))
return false;
if (m_psymOperator->MatchesOp("!"))
*pnRet = (nTmp == 0)? 1: 0;
else if (m_psymOperator->MatchesOp("-"))
*pnRet = nTmp * -1;
else
return false;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::ResolveToInteger(int * pnRet, bool fSlotRef)
{
int nTmp1, nTmp2;
if (!m_pexpOperand1->ResolveToInteger(&nTmp1, fSlotRef))
return false;
if (!m_pexpOperand2->ResolveToInteger(&nTmp2, fSlotRef))
return false;
if (m_psymOperator->MatchesOp("+"))
*pnRet = nTmp1 + nTmp2;
else if (m_psymOperator->MatchesOp("-"))
*pnRet = nTmp1 - nTmp2;
else if (m_psymOperator->MatchesOp("*"))
*pnRet = nTmp1 * nTmp2;
else if (m_psymOperator->MatchesOp("/"))
{
if (nTmp2 == 0)
{
g_errorList.AddError(1104, this, "Divide by zero.");
return false;
}
*pnRet = nTmp1 / nTmp2;
}
else if (m_psymOperator->MatchesOp("&&"))
*pnRet = (nTmp1 != 0 && nTmp2 != 0)? 1: 0;
else if (m_psymOperator->MatchesOp("||"))
*pnRet = (nTmp1 != 0 || nTmp2 != 0)? 1: 0;
else if (m_psymOperator->MatchesOp("=="))
*pnRet = (nTmp1 == nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp("!="))
*pnRet = (nTmp1 != nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp("<"))
*pnRet = (nTmp1 < nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp("<="))
*pnRet = (nTmp1 <= nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp(">"))
*pnRet = (nTmp1 > nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp(">="))
*pnRet = (nTmp1 >= nTmp2)? 1: 0;
else if (m_psymOperator->MatchesOp("max"))
*pnRet = max(nTmp1, nTmp2);
else if (m_psymOperator->MatchesOp("min"))
*pnRet = min(nTmp1, nTmp2);
else
return false;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::ResolveToInteger(int * pnRet, bool fSlotRef)
{
int nTmp;
if (m_pexpTest->ResolveToInteger(&nTmp, fSlotRef))
{
if (nTmp == 0)
return m_pexpFalse->ResolveToInteger(pnRet, fSlotRef);
else
return m_pexpTrue->ResolveToInteger(pnRet, fSlotRef);
}
else
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::ResolveToInteger(int * pnRet, bool fSlotRef)
{
if (m_pexpSimplified) // result of SimplifyAndUnscale
return m_pexpSimplified->ResolveToInteger(pnRet, fSlotRef);
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlClassMemberExpression::ResolveToInteger(int * pnRet, bool /*fSlotRef*/)
{
if (m_gid > -1)
{
*pnRet = m_gid;
return true;
}
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::ResolveToInteger(int * pnRet, bool /*fSlotRef*/)
{
*pnRet = m_nValue;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::ResolveToInteger(int * pnRet, bool fSlotRef)
{
if (fSlotRef)
{
*pnRet = m_srNumber;
return true;
}
else
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::ResolveToInteger(int * /*pnRet*/, bool /*fSlotRef*/)
{
return false;
}
/*----------------------------------------------------------------------------------------------
Return the corresponding feature ID. This is the same as ResolveToInteger except that
strings of <= 4 characters can be treated as feature IDs.
----------------------------------------------------------------------------------------------*/
bool GdlExpression::ResolveToFeatureID(unsigned int * pnRet)
{
int nRet;
bool fRet = ResolveToInteger(&nRet, false);
*pnRet = (unsigned int)nRet;
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::ResolveToFeatureID(unsigned int * pnRet)
{
if (m_staValue.length() > 4)
return false;
union {
char rgch[4];
unsigned int n;
} featid;
// The way we do the assignments ensures the characters are left-aligned
// in the 4-byte integer (ie, occupying the most significant bytes).
for (size_t ich = 0; ich < 4; ich++)
featid.rgch[3-ich] = (ich < m_staValue.length()) ? m_staValue[ich] : 0;
*pnRet = featid.n;
return true;
}
/***********************************************************************************************
Methods: Pre-compiler
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Return the type of the expression. If there is inconsistency, return our best guess.
This is used to deduce the type of a glyph attribute from the value put in it.
----------------------------------------------------------------------------------------------*/
ExpressionType GdlUnaryExpression::ExpType()
{
if (m_psymOperator->MatchesOp("!"))
return kexptBoolean;
else if (m_psymOperator->MatchesOp("-"))
return m_pexpOperand->ExpType();
else
return kexptUnknown;
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlBinaryExpression::ExpType()
{
ExpressionType expt1 = m_pexpOperand1->ExpType();
if (m_psymOperator->MatchesOp("+") || m_psymOperator->MatchesOp("-"))
{
return expt1;
}
else if (m_psymOperator->MatchesOp("*"))
{
ExpressionType expt2 = m_pexpOperand2->ExpType();
if (expt1 == kexptMeas || expt2 == kexptMeas)
return kexptMeas;
else
return kexptNumber;
}
else if (m_psymOperator->MatchesOp("/"))
{
return expt1;
}
else if (m_psymOperator->MatchesOp("&&") || m_psymOperator->MatchesOp("||"))
{
return kexptBoolean;
}
else if (m_psymOperator->MatchesOp("==") || m_psymOperator->MatchesOp("!=") ||
m_psymOperator->MatchesOp("<") || m_psymOperator->MatchesOp("<=") ||
m_psymOperator->MatchesOp(">") || m_psymOperator->MatchesOp(">="))
{
return kexptBoolean;
}
else if (m_psymOperator->MatchesOp("max") || m_psymOperator->MatchesOp("min"))
{
return expt1;
}
else
{
return expt1;
}
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlCondExpression::ExpType()
{
return m_pexpTrue->ExpType();
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlLookupExpression::ExpType()
{
return m_psymName->ExpType();
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlNumericExpression::ExpType()
{
if (m_munits == kmunitNone)
{
if (m_nValue == 0)
return kexptZero;
else if (m_nValue == 1)
return kexptOne;
else
return kexptNumber;
}
else
return kexptMeas;
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlSlotRefExpression::ExpType()
{
return kexptSlotRef;
}
/*--------------------------------------------------------------------------------------------*/
ExpressionType GdlStringExpression::ExpType()
{
return kexptString;
}
/*----------------------------------------------------------------------------------------------
Check for matching types and the appropriate presence and absence of scaled numbers.
Record an error if there is a problem. Return true if everything is okay.
----------------------------------------------------------------------------------------------*/
bool GdlExpression::TypeCheck(ExpressionType exptExpected)
{
std::vector<ExpressionType> vnTmp;
vnTmp.push_back(exptExpected);
return TypeCheck(vnTmp);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlExpression::TypeCheck(ExpressionType expt1, ExpressionType expt2, ExpressionType expt3)
{
std::vector<ExpressionType> vnTmp;
vnTmp.push_back(expt1);
vnTmp.push_back(expt2);
vnTmp.push_back(expt3);
return TypeCheck(vnTmp);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlExpression::TypeCheck(std::vector<ExpressionType>& vexptExpected)
{
ExpressionType exptFound;
if (!CheckTypeAndUnits(&exptFound))
return false;
for (size_t i = 0; i < vexptExpected.size(); ++i)
{
ExpressionType exptOkay = vexptExpected[i];
if (exptOkay == exptFound)
return true;
if (exptOkay == kexptUnknown)
return true;
if ((exptFound == kexptZero || exptFound == kexptOne) &&
(exptOkay == kexptMeas || exptOkay == kexptNumber || exptOkay == kexptBoolean ||
exptOkay == kexptZero || exptOkay == kexptOne))
{
return true;
}
}
return false;
}
/*----------------------------------------------------------------------------------------------
Check for matching types in sub-expressions and the appropriate presence and absence of
scaled numbers. Return the expression type in the argument. Return true if the expression
is well-formed enough that it is worth continuing processing with it, false if a fatal
error was recorded.
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
ExpressionType expt;
if (!m_pexpOperand->CheckTypeAndUnits(&expt))
return false;
if (expt == kexptSlotRef)
{
g_errorList.AddError(2101, this,
"Cannot use '",
m_psymOperator->FullName(),
"' operator with slot index");
*pexptRet = expt;
return false;
}
if (m_psymOperator->MatchesOp("!"))
{
if (expt != kexptBoolean && expt != kexptZero && expt != kexptOne)
g_errorList.AddWarning(2501, this,
"Boolean expression expected as target of '!' operator.");
*pexptRet = kexptBoolean;
return true;
}
else if (m_psymOperator->MatchesOp("-"))
{
if (expt != kexptNumber && expt != kexptMeas && expt != kexptZero && expt != kexptOne)
g_errorList.AddWarning(2502, this,
"Numeric expression expected as target of '-' operator.");
*pexptRet = expt;
return true;
}
else
{
g_errorList.AddError(2102, this,
"Invalid unary operator: ",
m_psymOperator->FieldAt(1));
}
return expt;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
ExpressionType expt1;
if (!m_pexpOperand1->CheckTypeAndUnits(&expt1))
return false;
ExpressionType expt2;
if (!m_pexpOperand2->CheckTypeAndUnits(&expt2))
return false;
*pexptRet = expt1; // unless changed below
if (m_psymOperator->MatchesOp("+") || m_psymOperator->MatchesOp("-") ||
m_psymOperator->MatchesOp("*") || m_psymOperator->MatchesOp("/"))
{
// Additive, multiplicative
if (expt1 == kexptSlotRef || expt2 == kexptSlotRef)
{
g_errorList.AddError(2103, this,
"Using '",
m_psymOperator->FullName(),
"' operator with slot indices");
return false;
}
if ((expt1 != kexptNumber && expt1 != kexptMeas &&
expt1 != kexptZero && expt1 != kexptOne) ||
(expt2 != kexptNumber && expt2 != kexptMeas &&
expt2 != kexptZero && expt2 != kexptOne))
{
g_errorList.AddWarning(2503, this,
"Numeric expression expected as target of ",
m_psymOperator->FullName(),
" operator.");
}
if (m_psymOperator->MatchesOp("+") || m_psymOperator->MatchesOp("-"))
{
if (!EquivalentTypes(expt1, expt2) && expt1 != kexptUnknown && expt2 != kexptUnknown)
g_errorList.AddWarning(2504, this,
"Adding measurement to non-measurement");
}
else if (m_psymOperator->MatchesOp("*"))
{
if (expt1 == kexptMeas && expt2 == kexptMeas)
g_errorList.AddWarning(2505, this,
"Multiplying two measurements");
if (expt1 == kexptMeas || expt2 == kexptMeas)
*pexptRet = kexptMeas;
else
*pexptRet = kexptNumber;
}
else if (m_psymOperator->MatchesOp("/"))
{
if (expt2 == kexptMeas)
g_errorList.AddWarning(2506, this, "Divisor is a measurement");
else if (expt2 == kexptZero)
g_errorList.AddError(2104, this, "Dividing by zero");
}
}
else if (m_psymOperator->MatchesOp("&&") || m_psymOperator->MatchesOp("||"))
{
// Logical
if ((expt1 != kexptBoolean && expt1 != kexptZero && expt1 != kexptOne) ||
(expt2 != kexptBoolean && expt2 != kexptZero && expt2 != kexptOne))
{
g_errorList.AddWarning(2507, this,
"Boolean expression expected as target of ",
m_psymOperator->FullName(),
" operator");
}
if (!EquivalentTypes(expt1, expt2) && expt1 != kexptUnknown && expt2 != kexptUnknown)
g_errorList.AddWarning(2508, this,
"Logically combining expressions of different types");
*pexptRet = kexptBoolean;
}
else if (m_psymOperator->MatchesOp("==") || m_psymOperator->MatchesOp("!=") ||
m_psymOperator->MatchesOp("<") || m_psymOperator->MatchesOp("<=") ||
m_psymOperator->MatchesOp(">") || m_psymOperator->MatchesOp(">="))
{
// Comparative
if (!EquivalentTypes(expt1, expt2) && expt1 != kexptUnknown && expt2 != kexptUnknown)
g_errorList.AddWarning(2509, this,
"Comparing expressions of different types");
*pexptRet = kexptBoolean;
}
else if (m_psymOperator->MatchesOp("max") || m_psymOperator->MatchesOp("min"))
{
// Functional
if (expt1 != kexptNumber && expt1 != kexptMeas &&
expt1 != kexptSlotRef && expt1 != kexptZero && expt1 != kexptOne &&
expt2 != kexptNumber && expt2 != kexptMeas &&
expt2 != kexptSlotRef && expt2 != kexptZero && expt2 != kexptOne)
{
g_errorList.AddWarning(2510, this,
"Numeric expression expected as target of ",
m_psymOperator->FullName(),
" function");
}
if (!EquivalentTypes(expt1, expt2) && expt1 != kexptUnknown && expt2 != kexptUnknown)
g_errorList.AddWarning(2511, this,
"Calculating ",
m_psymOperator->FullName(),
" of different expression types");
}
else if (m_psymOperator->MatchesOp("=") ||
m_psymOperator->MatchesOp("+=") || m_psymOperator->MatchesOp("-=") ||
m_psymOperator->MatchesOp("*=") || m_psymOperator->MatchesOp("/="))
{
// Assignment
g_errorList.AddError(2105, this,
m_psymOperator->FullName(),
" assignment operator not permitted in expression");
return false;
}
else
{
g_errorList.AddError(2106, this,
"Invalid binary operator: ",
m_psymOperator->FullName());
return false;
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
ExpressionType exptTest;
if (!m_pexpTest->CheckTypeAndUnits(&exptTest))
return false;
if (exptTest != kexptBoolean)
g_errorList.AddWarning(2512, this, "Boolean expression expected as condition");
ExpressionType expt1;
if (!m_pexpTrue->CheckTypeAndUnits(&expt1))
return false;
ExpressionType expt2;
if (!m_pexpFalse->CheckTypeAndUnits(&expt2))
return false;
if (!EquivalentTypes(expt1, expt2))
{
if (expt1 == kexptSlotRef || expt2 == kexptSlotRef)
// One or the other is sure to be wrong.
g_errorList.AddError(2107, this,
"Inconsistent types in conditional branches");
else
g_errorList.AddWarning(2513, this,
"Non-matching types in conditional branches");
}
if (expt1 == kexptZero || expt1 == kexptOne)
*pexptRet = expt2; // this is more useful than kexptZero
else
*pexptRet = expt1;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
*pexptRet = m_psymName->ExpType();
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlClassMemberExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
*pexptRet = kexptGlyphID;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
if (m_nValue == 0 && m_munits == kmunitNone)
// so that 0 can be treated as equivalent to 0m
*pexptRet = kexptZero;
else if (m_nValue == 1 && m_munits == kmunitNone)
*pexptRet = kexptOne;
else if (m_munits == kmunitNone)
*pexptRet = kexptNumber;
else
*pexptRet = kexptMeas;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
*pexptRet = kexptSlotRef;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::CheckTypeAndUnits(ExpressionType * pexptRet)
{
*pexptRet = kexptString;
return true;
}
/*----------------------------------------------------------------------------------------------
Check that the expression, which is the value of a glyph attribute, does not make use
of slot attributes, features, or slot index references.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::GlyphAttrCheck(Symbol psymAttr)
{
m_pexpOperand->GlyphAttrCheck(psymAttr);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::GlyphAttrCheck(Symbol psymAttr)
{
m_pexpOperand1->GlyphAttrCheck(psymAttr);
m_pexpOperand2->GlyphAttrCheck(psymAttr);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::GlyphAttrCheck(Symbol psymAttr)
{
m_pexpTest->GlyphAttrCheck(psymAttr);
m_pexpTrue->GlyphAttrCheck(psymAttr);
m_pexpFalse->GlyphAttrCheck(psymAttr);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::GlyphAttrCheck(Symbol /*psymAttr*/)
{
if (m_psymName->FitsSymbolType(ksymtGlyphData))
{
// okay
}
else if (m_psymName->FitsSymbolType(ksymtSlotAttr))
{
g_errorList.AddError(2108, this,
"Slot attribute references are not permitted in glyph attribute values");
}
else if (m_psymName->FitsSymbolType(ksymtFeature))
{
g_errorList.AddError(2109, this,
"Feature references are not permitted in glyph attribute values");
}
else if (m_psymName->FitsSymbolType(ksymtProcState))
{
g_errorList.AddError(2110, this,
"Processing-state references are not permitted in glyph attribute values");
}
else
{
g_errorList.AddError(2111, this,
"Unknown attribute: ",
m_psymName->FullName());
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlClassMemberExpression::GlyphAttrCheck(Symbol psymAttr)
{
if (m_psymName == NULL && m_gid != -1)
{
// Assume okay--probably represents a default value.
}
else if (m_psymName->FitsSymbolType(ksymtClass))
{
// Check that the class sizes match.
GdlDefn * pgdl = m_psymName->Data();
GdlGlyphClassDefn * pglfc = dynamic_cast<GdlGlyphClassDefn *>(pgdl);
if (pglfc)
{
int cgidTarget = pglfc->GlyphIDCount();
if (m_cgidClassSize != cgidTarget)
{
g_errorList.AddError(4146, this,
"Size of classes do not match for ", psymAttr->FullName(), " attribute");
}
}
// else give an error in SimplifyAndUnscale
}
else
{
// indexed-lookup-expressions are only created for classes, so this should never
// happen:
g_errorList.AddError(4147, this,
"Invalid value of attribute: ",
m_psymName->FullName());
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::GlyphAttrCheck(Symbol /*psymAttr*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::GlyphAttrCheck(Symbol /*psymAttr*/)
{
g_errorList.AddError(2112, this,
"Slot references are not permitted in glyph attribute values");
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::GlyphAttrCheck(Symbol /*psymAttr*/)
{
}
/*----------------------------------------------------------------------------------------------
Test that any feature settings tests are valid within the context; replace settings
with the corresponding numeric expression.
For instance, suppose we have
ligatures.settings {
none.value = 0;
some.value = 1;
all.value = 2;
}
swashes.settings {
none.value = 0;
basic.value = 1;
most.value = 2;
all.value = 3;
}
Then an expression like "ligatures == all" gets converted to "ligatures == 2";
"swashes <= basic" becomes "swashes <= 1'; "ligatures > basic" is an error.
The special "lang" feature converts its language ID string to an integer.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::FixFeatureTestsInRules(GrcFont *pfont)
{
m_pexpOperand->FixFeatureTestsInRules(pfont);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::FixFeatureTestsInRules(GrcFont *pfont)
{
GdlLookupExpression * pexplookFeature =
dynamic_cast<GdlLookupExpression *>(m_pexpOperand1);
if (m_psymOperator->IsComparativeOp() && pexplookFeature &&
pexplookFeature->NameFitsSymbolType(ksymtFeature))
{
GdlFeatureDefn * pfeat = pexplookFeature->Name()->FeatureDefnData();
Assert(pfeat);
GdlExpression * pexpNew = m_pexpOperand2->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpOperand2)
{
delete m_pexpOperand2;
m_pexpOperand2 = pexpNew;
}
pexpNew = m_pexpOperand2->SimplifyAndUnscale(0xFFFF, pfont);
Assert(pexpNew);
if (pexpNew && pexpNew != m_pexpOperand2)
{
delete m_pexpOperand2;
m_pexpOperand2 = pexpNew;
}
GdlNumericExpression * pexpnum = dynamic_cast<GdlNumericExpression *>(m_pexpOperand2);
if (pexpnum)
{
if (!pfeat->IsLanguageFeature())
{
GdlFeatureSetting * pfset = pfeat->FindSettingWithValue(pexpnum->Value());
if (!pfset)
{
char rgch[20];
itoa(pexpnum->Value(), rgch, 10);
g_errorList.AddWarning(2514, this,
"Feature '",
pfeat->Name(),
"' has no setting with value ",
rgch,
((pexpnum->m_munits >= kmunitDefault) ? "m" : ""));
}
}
}
}
else
{
m_pexpOperand1->FixFeatureTestsInRules(pfont);
m_pexpOperand2->FixFeatureTestsInRules(pfont);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::FixFeatureTestsInRules(GrcFont *pfont)
{
m_pexpTest->FixFeatureTestsInRules(pfont);
m_pexpTrue->FixFeatureTestsInRules(pfont);
m_pexpFalse->FixFeatureTestsInRules(pfont);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::FixFeatureTestsInRules(GrcFont * /*pfont*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::FixFeatureTestsInRules(GrcFont * /*pfont*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::FixFeatureTestsInRules(GrcFont * /*pfont*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::FixFeatureTestsInRules(GrcFont * /*pfont*/)
{
}
/*----------------------------------------------------------------------------------------------
The recipient is the right-hand side of a feature comparison expresion
(eg, ligatures == all).
Return the equivalent expression, with any feature setting value converted to a
numeric expression.
----------------------------------------------------------------------------------------------*/
GdlExpression * GdlUnaryExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
if (pfeat->IsLanguageFeature())
g_errorList.AddWarning(2515, this,
"Arithmetic calculation of language ID value");
GdlExpression * pexpNew = m_pexpOperand->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpOperand)
{
delete m_pexpOperand;
m_pexpOperand = pexpNew;
}
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlBinaryExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
if (pfeat->IsLanguageFeature())
g_errorList.AddWarning(2516, this,
"Arithmetic calculation of language ID value");
GdlExpression * pexpNew;
pexpNew = m_pexpOperand1->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpOperand1)
{
delete m_pexpOperand1;
m_pexpOperand1 = pexpNew;
}
pexpNew = m_pexpOperand2->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpOperand2)
{
delete m_pexpOperand2;
m_pexpOperand2 = pexpNew;
}
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlCondExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
GdlExpression * pexpNew;
pexpNew = m_pexpTest->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpTest)
{
delete m_pexpTest;
m_pexpTest = pexpNew;
}
pexpNew = m_pexpTrue->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpTrue)
{
delete m_pexpTrue;
m_pexpTrue = pexpNew;
}
pexpNew = m_pexpFalse->ConvertFeatureSettingValue(pfeat);
if (pexpNew != m_pexpFalse)
{
delete m_pexpFalse;
m_pexpFalse = pexpNew;
}
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlLookupExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
if (pfeat->IsLanguageFeature())
g_errorList.AddWarning(2517, this,
"Arithmetic calculation of language ID value");
// Note: normally the symbol type will be ksymtInvalid.
if (m_psymName->FieldCount() > 1)
{
g_errorList.AddError(2113, this,
"Invalid feature setting: ",
m_psymName->FullName());
return this;
}
GdlFeatureSetting * pfset = pfeat->FindSetting(std::string(m_psymName->LastField()));
if (!pfset)
{
g_errorList.AddError(2114, this,
"Feature '",
pfeat->Name(),
"' has no setting '",
m_psymName->FullName(),
"'");
return this;
}
// Caller will replace setting expression with numeric value.
GdlNumericExpression * pexpValue = new GdlNumericExpression(pfset->Value());
return pexpValue;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlNumericExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
if (pfeat->IsLanguageFeature())
g_errorList.AddWarning(2518, this,
"Numeric value where language ID string expected");
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlSlotRefExpression::ConvertFeatureSettingValue(GdlFeatureDefn * /*pfeat*/)
{
// Caller will replace slot-ref expression with numeric expression.
char rgch[20];
itoa(m_srNumber, rgch, 10);
g_errorList.AddWarning(2519, this,
"Inappropriate value of feature setting: @",
rgch);
GdlNumericExpression * pexpValue = new GdlNumericExpression(m_srNumber);
return pexpValue;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlStringExpression::ConvertFeatureSettingValue(GdlFeatureDefn * pfeat)
{
if (pfeat->IsLanguageFeature())
{
int nValue = 0;
int cb = m_staValue.length();
if (m_staValue.length() > 4)
{
g_errorList.AddError(2115, this,
"Invalid language ID--must be a 4-byte string");
}
else if (m_staValue.length() < 4)
{
g_errorList.AddWarning(2520, this,
"Possibly invalid language ID--4-byte string expected");
}
gr::byte b1, b2, b3, b4;
b1 = (cb > 0) ? m_staValue[0] : 0;
b2 = (cb > 1) ? m_staValue[1] : 0;
b3 = (cb > 2) ? m_staValue[2] : 0;
b4 = (cb > 3) ? m_staValue[3] : 0;
nValue = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
// Caller will replace original expression with numeric value.
GdlNumericExpression * pexpValue = new GdlNumericExpression(nValue);
return pexpValue;
}
else
{
g_errorList.AddError(2116, this,
"Inappropriate value of feature setting: ",
m_staValue);
}
return this;
}
/*----------------------------------------------------------------------------------------------
Do a final check to make sure that all look-up expressions within a rule are meaningful.
Argument:
fInIf - true if the statement was inside an -if- statement, rather than
inside a rule's context.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::LookupExpCheck(bool fInIf)
{
m_pexpOperand->LookupExpCheck(fInIf);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::LookupExpCheck(bool fInIf)
{
m_pexpOperand1->LookupExpCheck(fInIf);
m_pexpOperand2->LookupExpCheck(fInIf);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::LookupExpCheck(bool fInIf)
{
m_pexpTest->LookupExpCheck(fInIf);
m_pexpTrue->LookupExpCheck(fInIf);
m_pexpFalse->LookupExpCheck(fInIf);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::LookupExpCheck(bool fInIf)
{
if (!m_psymName)
{
g_errorList.AddError(2117, this,
"Undefined attribute");
return;
}
else if (m_psymName->FitsSymbolType(ksymtGlyphMetric))
{
// Okay
}
else if (m_psymName->FitsSymbolType(ksymtGlyphAttr) ||
m_psymName->FitsSymbolType(ksymtSlotAttr) ||
m_psymName->FitsSymbolType(ksymtFeature) ||
m_psymName->FitsSymbolType(ksymtProcState))
{
if (m_nClusterLevel != 0)
g_errorList.AddError(2118, this,
"Composite metric indicator is incompatible with ",
m_psymName->TypeDescriptorString());
}
else if (m_psymName->FitsSymbolType(ksymtInvalidGlyphAttr))
{
g_errorList.AddError(2119, this,
"Incomplete glyph attribute: ",
m_psymName->FullName());
}
else
{
g_errorList.AddError(2120, this,
"Undefined attribute: ",
m_psymName->FullName());
return;
}
if (fInIf)
{
if (!m_psymName->FitsSymbolType(ksymtFeature) &&
!m_psymName->FitsSymbolType(ksymtProcState))
{
g_errorList.AddError(2121, this,
"Only features and the processing state may be tested within 'if' statements; ",
m_psymName->TypeDescriptorString(),
"s not permitted");
}
if (m_pexpSelector)
{
char rgch[20];
itoa(m_pexpSelector->SlotNumber(), rgch, 10);
g_errorList.AddError(2122, this,
"Slot selectors are not permitted in 'if' statements: @",
rgch);
}
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::LookupExpCheck(bool /*fInIf*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::LookupExpCheck(bool /*fInIf*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::LookupExpCheck(bool /*fInIf*/)
{
}
/*----------------------------------------------------------------------------------------------
Simplify any expressions down to integers that can be, returning a new expression
equivalent to the recipient. Convert scaled numbers to absolute (in place).
Return NULL if there was an error in the expression.
Caller is responsible to delete the returned expression.
Arguments:
pgax - glyph attribute maxtrix, for resolving glyph attributes; or NULL
wGlyphID - glyph ID to use in resolving glyph attributes and metrics;
0xFFFF means that glyph attributes are not permitted in
the current context
setpsym - set of glyph attribute symbols encountered; for catching infinite
loops in definitions of glyph attributes
pfont - font, for reading glyph metrics
fGAttrDefChk - check that glyph attributes are defined for the given glyph ID
(this is false within the context of rules, which are checked
elsewhere)
pfCanSub - true means replacement expression is irrespective of the glyph ID,
and therefore can be replaced directly in the enclosing expression;
if false, make a new expression to return, because another glyph ID
may be using the original expression, so it needs to hang around
unmodified.
----------------------------------------------------------------------------------------------*/
GdlExpression * GdlUnaryExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * pgax,
utf16 wGlyphID, SymbolSet & setpsym, GrcFont * pfont, bool fGAttrDefChk,
bool * pfCanSub)
{
bool fCanSubOperand;
GdlExpression * pexpOperandNew =
m_pexpOperand->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont,
fGAttrDefChk, &fCanSubOperand);
if (!pexpOperandNew)
return NULL;
GdlUnaryExpression * pexpunRet = this;
if (pexpOperandNew != m_pexpOperand)
{
if (!fCanSubOperand)
{
pexpunRet = dynamic_cast<GdlUnaryExpression *>(this->Clone());
Assert(pexpunRet);
}
delete pexpunRet->m_pexpOperand;
pexpunRet->m_pexpOperand = pexpOperandNew;
}
*pfCanSub = (pexpunRet == this);
int nValue;
if (this->ResolveToInteger(&nValue, false))
{
GdlExpression * pexpRet = new GdlNumericExpression(nValue);
pexpRet->CopyLineAndFile(*this);
return pexpRet;
}
return pexpunRet;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlBinaryExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * pgax,
utf16 wGlyphID, SymbolSet & setpsym, GrcFont * pfont, bool fGAttrDefChk,
bool * pfCanSub)
{
bool fCanSubOperand1, fCanSubOperand2;
GdlExpression * pexpOperand1New =
m_pexpOperand1->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont,
fGAttrDefChk, &fCanSubOperand1);
GdlExpression * pexpOperand2New =
m_pexpOperand2->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont,
fGAttrDefChk, &fCanSubOperand2);
if (!pexpOperand1New || !pexpOperand2New)
return NULL;
GdlBinaryExpression * pexpbinRet = this;
if (pexpOperand1New && pexpOperand1New != m_pexpOperand1)
{
if (!fCanSubOperand1)
{
pexpbinRet = dynamic_cast<GdlBinaryExpression *>(this->Clone());
Assert(pexpbinRet);
}
delete pexpbinRet->m_pexpOperand1;
pexpbinRet->m_pexpOperand1 = pexpOperand1New;
}
if (pexpOperand2New && pexpOperand2New != m_pexpOperand2)
{
if (!fCanSubOperand2 && pexpbinRet == this)
{
pexpbinRet = dynamic_cast<GdlBinaryExpression *>(this->Clone());
Assert(pexpbinRet);
}
delete pexpbinRet->m_pexpOperand2;
pexpbinRet->m_pexpOperand2 = pexpOperand2New;
}
*pfCanSub = (pexpbinRet == this);
int nValue;
if (this->ResolveToInteger(&nValue, false))
{
GdlExpression * pexpRet = new GdlNumericExpression(nValue);
pexpRet->CopyLineAndFile(*this);
return pexpRet;
}
return pexpbinRet;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlCondExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * pgax,
utf16 wGlyphID, SymbolSet & setpsym, GrcFont * pfont, bool fGAttrDefChk,
bool * pfCanSub)
{
bool fCanSubTest, fCanSubTrue, fCanSubFalse;
GdlExpression * pexpTestNew =
m_pexpTest->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont, fGAttrDefChk,
&fCanSubTest);
GdlExpression * pexpTrueNew =
m_pexpTrue->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont, fGAttrDefChk,
&fCanSubTrue);
GdlExpression * pexpFalseNew =
m_pexpFalse->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont, fGAttrDefChk,
&fCanSubFalse);
if (!pexpTestNew || !pexpTrueNew || !pexpFalseNew)
return NULL;
GdlCondExpression * pexpcondRet = this;
if (pexpTestNew && pexpTestNew != m_pexpTest)
{
if (!fCanSubTest)
{
pexpcondRet = dynamic_cast<GdlCondExpression *>(this->Clone());
Assert(pexpcondRet);
}
delete pexpcondRet->m_pexpTest;
pexpcondRet->m_pexpTest = pexpTestNew;
}
if (pexpTrueNew && pexpTrueNew != m_pexpTrue)
{
if (!fCanSubTrue && pexpcondRet == this)
{
pexpcondRet = dynamic_cast<GdlCondExpression *>(this->Clone());
Assert(pexpcondRet);
}
delete pexpcondRet->m_pexpTrue;
pexpcondRet->m_pexpTrue = pexpTrueNew;
}
if (pexpFalseNew && pexpFalseNew != m_pexpFalse)
{
if (!fCanSubFalse && pexpcondRet == this)
{
pexpcondRet = dynamic_cast<GdlCondExpression *>(this->Clone());
Assert(pexpcondRet);
}
delete pexpcondRet->m_pexpFalse;
pexpcondRet->m_pexpFalse = pexpFalseNew;
}
*pfCanSub = (pexpcondRet == this);
int nValue;
if (this->ResolveToInteger(&nValue, false))
{
GdlExpression * pexpRet = new GdlNumericExpression(nValue);
pexpRet->CopyLineAndFile(*this);
return pexpRet;
}
return pexpcondRet;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlLookupExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * pgax,
utf16 wGlyphID, SymbolSet & setpsym, GrcFont * pfont, bool fGAttrDefChk,
bool * pfCanSub)
{
int nAttrID = -1;
if (!m_psymName->IsGeneric() && pgax
&& (m_psymName->FitsSymbolType(ksymtGlyphAttr)
|| m_psymName->FitsSymbolType(ksymtGlyphMetric)))
{
// A non-generic attribute or metric means the value for the
// first element of the given class.
Symbol psymTmp = m_psymName;
while (psymTmp->ParentSymbol())
psymTmp = psymTmp->ParentSymbol();
GdlGlyphClassDefn * pglfc = psymTmp->GlyphClassDefnData();
if (!pglfc)
{
g_errorList.AddError(2123, this,
"Undefined glyph class: ", psymTmp->FullName());
return NULL;
}
bool fMoreThanOne = false;
unsigned int nGlyphIDFirst = pglfc->FirstGlyphInClass(&fMoreThanOne);
bool fDefined = (nGlyphIDFirst != 0);
if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
{
nAttrID = m_psymName->InternalID();
if (fDefined)
{
Symbol psymGeneric = m_psymName->Generic();
// A predefined glyph attribute such as directionality does not need an
// explicit assignment to be defined.
fDefined = (psymGeneric && !psymGeneric->IsUserDefined());
}
fDefined = (fDefined || pgax->Defined(nGlyphIDFirst, nAttrID));
if (!fDefined)
{
g_errorList.AddError(2124, this,
"Undefined glyph attribute: ", m_psymName->FullName());
return NULL;
}
}
else if (!fDefined)
{
g_errorList.AddError(2125, this,
"Undefined identifier: ", m_psymName->FullName());
}
if (fMoreThanOne)
{
g_errorList.AddWarning(2521, this,
"Class '",
pglfc->Name(),
"' has size > 1; first glyph will be used to evaluate ",
m_psymName->FullName());
}
GdlExpression * pexpRet = NULL;
if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
{
setpsym.insert(m_psymName);
GdlExpression * pexp;
pexp = pgax->GetExpression(nGlyphIDFirst, nAttrID);
if (pexp)
{
pexpRet = pexp->SimplifyAndUnscale(pgax, nGlyphIDFirst, setpsym, pfont,
true, pfCanSub);
if (pexpRet)
pexpRet = pexpRet->Clone();
}
else
{
// Predefined attribute with no explicit value.
pexpRet = new GdlNumericExpression(0);
}
setpsym.erase(m_psymName); // in case we look up this attribute again in the
// same outer expression
}
else if (m_psymName->FitsSymbolType(ksymtGlyphMetric))
{
int gmet = m_psymName->GlyphMetricEngineCodeOp();
int nValue;
if (gmet == -1)
{
g_errorList.AddError(2126, this,
"Invalid glyph metric: ",
m_psymName->FullName());
nValue = 0;
}
else
{
int nActual = g_cman.ActualForPseudo(nGlyphIDFirst);
if (nActual == 0)
nActual = nGlyphIDFirst;
nValue = pfont->GetGlyphMetric(nActual, GlyphMetric(gmet), this);
}
pexpRet = new GdlNumericExpression(nValue);
pexpRet->CopyLineAndFile(*this);
}
m_pexpSimplified = dynamic_cast<GdlNumericExpression *>(pexpRet);
*pfCanSub = true;
if (m_pexpSimplified)
return this;
else
return pexpRet;
}
// A generic glyph attribute or metric refers to the current item.
if (m_psymName->FitsSymbolType(ksymtGlyphMetric))
{
if (wGlyphID == 0xFFFF)
{
g_errorList.AddError(2127, this,
"Illegal use of glyph metric: ",
m_psymName->FullName());
return this;
}
int gmet = m_psymName->GlyphMetricEngineCodeOp();
int nValue;
if (gmet == -1)
{
g_errorList.AddError(2128, this,
"Invalid glyph metric: ",
m_psymName->FullName());
nValue = 0;
}
else
{
int nActual = g_cman.ActualForPseudo(wGlyphID);
if (nActual == 0)
nActual = wGlyphID;
nValue = pfont->GetGlyphMetric(nActual, GlyphMetric(gmet), this);
}
if (m_pexpSelector)
{
// Can't resolve.
*pfCanSub = false;
return NULL;
}
GdlNumericExpression * pexpRet = new GdlNumericExpression(nValue);
pexpRet->CopyLineAndFile(*this);
*pfCanSub = false;
return pexpRet;
}
else if (m_psymName->FitsSymbolType(ksymtGlyphAttr) && pgax)
{
nAttrID = m_psymName->InternalID();
if (!fGAttrDefChk)
{
*pfCanSub = false;
return this;
}
if (!pgax->Defined(wGlyphID, nAttrID))
{
g_errorList.AddError(2129, this,
"The glyph attribute ",
m_psymName->FullName(),
" is not defined for glyph ",
GdlGlyphDefn::GlyphIDString(wGlyphID));
return NULL;
}
else if (setpsym.find(m_psymName) != setpsym.end()) // is a member
{
g_errorList.AddError(2130, this,
"Circular definition of glyph attribute ",
m_psymName->FullName(),
" for glyph ",
GdlGlyphDefn::GlyphIDString(wGlyphID));
return NULL;
}
else
{
setpsym.insert(m_psymName);
GdlExpression * pexp;
GdlExpression * pexpRet;
pexp = pgax->GetExpression(wGlyphID, nAttrID);
pexpRet = pexp->SimplifyAndUnscale(pgax, wGlyphID, setpsym, pfont,
fGAttrDefChk, pfCanSub);
if (pexpRet)
pexpRet = pexpRet->Clone();
setpsym.erase(m_psymName); // in case we look up this attribute again in the
// same outer expression
*pfCanSub = false;
return pexpRet;
}
}
*pfCanSub = true;
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlClassMemberExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * /*pgax*/,
utf16 /*wGlyphID*/, SymbolSet & /*setpsym*/, GrcFont * /*pfont*/, bool /*fGAttrDefChk*/,
bool * pfCanSub)
{
if (m_psymName == NULL && m_gid != -1)
{
// Okay, probably a default value.
return this;
}
else if (m_psymName->FitsSymbolType(ksymtClass))
{
GdlDefn * pgdl = m_psymName->Data();
GdlGlyphClassDefn * pglfc = dynamic_cast<GdlGlyphClassDefn *>(pgdl);
if (!pglfc)
{
g_errorList.AddError(2163, this,
"Undefined glyph class: ", m_psymName->FullName());
return NULL;
}
else
{
std::vector<utf16> vgid;
pglfc->FlattenGlyphList(vgid);
int nValue = 0;
if (m_igid >= (signed)vgid.size())
{
char rgch[20];
itoa(m_igid, rgch, 10);
g_errorList.AddError(2164, this,
"Class sizes do not match; no corresponding glyph in class ", m_psymName->FullName(),
" for glyph #", rgch);
}
else
nValue = vgid[m_igid];
m_gid = nValue;
*pfCanSub = false;
return this;
}
}
else
// error already given
return NULL;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlNumericExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * /*pgax*/,
utf16 /*wGlyphID*/, SymbolSet & /*setpsym*/, GrcFont * pfont, bool /*fGAttrDefChk*/,
bool * pfCanSub)
{
m_nValue = pfont->ScaledToAbsolute(m_nValue, m_munits);
m_munits = (m_munits == kmunitNone) ? kmunitNone : kmunitUnscaled;
*pfCanSub = true;
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlSlotRefExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * /*pgax*/,
utf16 /*wGlyphID*/, SymbolSet & /*setpsym*/, GrcFont * /*pfont*/, bool /*fGAttrDefChk*/,
bool * pfCanSub)
{
*pfCanSub = true;
return this;
}
/*--------------------------------------------------------------------------------------------*/
GdlExpression * GdlStringExpression::SimplifyAndUnscale(GrcGlyphAttrMatrix * /*pgax*/,
utf16 /*wGlyphID*/, SymbolSet & /*setpsym*/, GrcFont * /*pfont*/, bool /*fGAttrDefChk*/,
bool * pfCanSub)
{
*pfCanSub = true;
return this;
}
/*----------------------------------------------------------------------------------------------
Change the value 0 in the expression to a special value. This is needed for the value
of gpoint attributes, because we consistently use 0 to mean "no legitimate value".
----------------------------------------------------------------------------------------------*/
void GdlNumericExpression::SetSpecialZero()
{
Assert(m_nValue == 0);
m_nValue = kGpointZero;
}
/*----------------------------------------------------------------------------------------------
The expression is the value of an attribute setting statement or rule item constraint.
Check that any glyph attributes accessed are defined for the relevant glyph classes
(all of the glyph IDs for the input class).
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::CheckAndFixGlyphAttrsInRules(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit)
{
m_pexpOperand->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::CheckAndFixGlyphAttrsInRules(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit)
{
m_pexpOperand1->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
m_pexpOperand2->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::CheckAndFixGlyphAttrsInRules(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit)
{
m_pexpTest->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
m_pexpTrue->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
m_pexpFalse->CheckAndFixGlyphAttrsInRules(pcman, vpglfcInClasses, irit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::CheckAndFixGlyphAttrsInRules(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit)
{
char rgchItem[20];
itoa(irit+1, rgchItem, 10);
if (m_psymName->FitsSymbolType(ksymtGlyphAttr)
&& !m_psymName->FitsSymbolType(ksymtSlotAttr)) // treat it like a slot attribute
{ // if it could be either
int nSel;
if (m_pexpSelector)
nSel = m_pexpSelector->m_srNumber - 1; // selectors are 1-based
else
nSel = irit;
if (nSel < 0 || nSel >= signed(vpglfcInClasses.size()))
{
g_errorList.AddError(2131, this,
"Item ", rgchItem,
": glyph attribute selector out of range");
return;
}
else if (vpglfcInClasses[nSel] == NULL)
{
g_errorList.AddError(2132, this,
"Item ", rgchItem,
": no input class for selector");
return;
}
m_nInternalID = m_psymName->InternalID();
m_nSubIndex = -1; // never needed for glyph attributes
// Check that the class associated with the glyph attribute matches
// the class in the rule.
//Symbol psymBaseClass = m_psymName->BaseClassDefn();
//if (psymBaseClass)
//{
// GdlGlyphClassDefn * pglfc = psymBaseClass->GlyphClassDefnData();
// if (pglfc != vpglfcInClasses[nSel])
// {
// g_errorList.AddWarning(2522, this,
// "Item ", rgchItem,
// ": Invalid glyph attribute: ",
// m_psymName->FullName());
// }
//}
if (m_psymName->IsGeneric())
// Then it must apply to all the glyphs in the class.
vpglfcInClasses[nSel]->CheckExistenceOfGlyphAttr(this,
pcman->SymbolTable(), pcman->GlyphAttrMatrix(), m_psymName);
}
}
/*------------------------------------------------------s--------------------------------------*/
void GdlNumericExpression::CheckAndFixGlyphAttrsInRules(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::CheckAndFixGlyphAttrsInRules(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::CheckAndFixGlyphAttrsInRules(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/)
{
}
/*----------------------------------------------------------------------------------------------
The expression is the value of an attribute setting statement, specifically setting
an attachment point.
Check that the attachment points are completely defined for the relevant glyph classes
(all of the glyph IDs for the input class).
Arguments:
irit - for an attach.at statement, the value of the attach.to setting;
for an attach.with, the current item; in other words, the item
for which the glyph attribute needs to be defined
pfXY - set to true if there is a glyph that needs to use x / y
pfGpoint - set to true if there is a glyph that needs to use gpoint
note that both *pfXY and *pfGpoint could be true
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::CheckCompleteAttachmentPoint(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit,
bool * pfXY, bool * pfGpoint)
{
m_pexpOperand->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::CheckCompleteAttachmentPoint(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit,
bool * pfXY, bool * pfGpoint)
{
m_pexpOperand1->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
m_pexpOperand2->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::CheckCompleteAttachmentPoint(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit,
bool * pfXY, bool * pfGpoint)
{
m_pexpTest->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
m_pexpTrue->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
m_pexpFalse->CheckCompleteAttachmentPoint(pcman, vpglfcInClasses, irit, pfXY, pfGpoint);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::CheckCompleteAttachmentPoint(GrcManager * pcman,
std::vector<GdlGlyphClassDefn *> & vpglfcInClasses, int irit,
bool * pfXY, bool * pfGpoint)
{
if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
{
int nSel;
if (m_pexpSelector)
nSel = m_pexpSelector->m_srNumber - 1; // selectors are 1-based
else
nSel = irit;
if (nSel < 0 || nSel >= signed(vpglfcInClasses.size()))
{
char rgch[20];
itoa(irit+1, rgch, 10);
g_errorList.AddError(2133, this,
"Item ", rgch,
"slot selector on glyph attribute ",
m_psymName->FullName(),
" out of range");
return;
}
else if (vpglfcInClasses[nSel] == NULL)
{
char rgch[20];
itoa(irit+1, rgch, 10);
g_errorList.AddError(2134, this,
"Item ", rgch,
": no input class for selector on glyph attribute ",
m_psymName->FullName());
return;
}
vpglfcInClasses[nSel]->CheckCompleteAttachmentPoint(this,
pcman->SymbolTable(), pcman->GlyphAttrMatrix(), m_psymName->BasePoint(),
pfXY, pfGpoint);
}
else
LookupExpCheck(false);
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::CheckCompleteAttachmentPoint(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/,
bool * /*pfXY*/, bool * /*pfGpoint*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::CheckCompleteAttachmentPoint(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/,
bool * /*pfXY*/, bool * /*pfGpoint*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::CheckCompleteAttachmentPoint(GrcManager * /*pcman*/,
std::vector<GdlGlyphClassDefn *> & /*vpglfcInClasses*/, int /*irit*/,
bool * /*pfXY*/, bool * /*pfGpoint*/)
{
}
/*----------------------------------------------------------------------------------------------
Create expressions corresponding to the fields of a point. For instance, if the recipient
is "@2.somePoint", return "@2.somePoint.x", "@2.somePoint.y", etc. Any of the arguments
(but most usefully the gpoint, xoffset, and yoffset fields) may be NULL.
Return false if this is not the kind of expression that has obvious equivalents.
Specifically, only glyph attribute lookups in fact do.
Note that if the symbol for one of the fields does not exist in the symbol table,
then there is no slot attribute setting making use of it, so we can afford to just
ignore it at this point. Eventually we may detect an error due to the omission.
----------------------------------------------------------------------------------------------*/
bool GdlExpression::PointFieldEquivalents(GrcManager * /*pcman*/,
GdlExpression ** /*ppexpX*/, GdlExpression ** /*ppexpY*/,
GdlExpression ** /*ppexpGpoint*/, GdlExpression ** /*ppexpXoffset*/, GdlExpression ** /*ppexpYoffset*/)
{
// Only glyph attribute lookups can handle this.
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::PointFieldEquivalents(GrcManager * /*pcman*/,
GdlExpression ** ppexpX, GdlExpression ** ppexpY,
GdlExpression ** ppexpGpoint, GdlExpression ** ppexpXoffset, GdlExpression ** ppexpYoffset)
{
Assert(m_psymName);
if (m_psymName->FitsSymbolType(ksymtSlotAttr))
{
return false;
}
if (m_psymName->FitsSymbolType(ksymtFeature))
{
return false;
}
if (!m_psymName->HasSubFields())
{
if (ppexpX) *ppexpX = NULL;
if (ppexpY) *ppexpY = NULL;
if (ppexpGpoint) *ppexpGpoint = NULL;
if (ppexpXoffset) *ppexpXoffset = NULL;
if (ppexpYoffset) *ppexpYoffset = NULL;
return true;
}
// Generally the symbol type will be ksymtInvalidGlyphAttr, because the name itself is
// undefined, only the subfields are defined.
if (ppexpX)
{
Symbol psymX = m_psymName->SubField("x");
if (psymX && psymX->FitsSymbolType(ksymtGlyphAttr))
{
GdlLookupExpression * pexpX = new GdlLookupExpression(*this);
pexpX->m_psymName = psymX;
pexpX->m_nInternalID = psymX->InternalID();
*ppexpX = pexpX;
}
else
*ppexpX = NULL;
}
if (ppexpY)
{
Symbol psymY = m_psymName->SubField("y");
if (psymY && psymY->FitsSymbolType(ksymtGlyphAttr))
{
GdlLookupExpression * pexpY = new GdlLookupExpression(*this);
pexpY->m_psymName = psymY;
pexpY->m_nInternalID = psymY->InternalID();
*ppexpY = pexpY;
}
else
*ppexpY = NULL;
}
if (ppexpGpoint)
{
Symbol psymGpoint = m_psymName->SubField("gpoint");
if (psymGpoint && psymGpoint->FitsSymbolType(ksymtGlyphAttr))
{
GdlLookupExpression * pexpGpoint = new GdlLookupExpression(*this);
pexpGpoint->m_psymName = psymGpoint;
pexpGpoint->m_nInternalID = psymGpoint->InternalID();
*ppexpGpoint = pexpGpoint;
}
else
*ppexpGpoint = NULL;
}
if (ppexpXoffset)
{
Symbol psymXoffset = m_psymName->SubField("xoffset");
if (psymXoffset && psymXoffset->FitsSymbolType(ksymtGlyphAttr))
{
GdlLookupExpression * pexpXoffset = new GdlLookupExpression(*this);
pexpXoffset->m_psymName = psymXoffset;
pexpXoffset->m_nInternalID = psymXoffset->InternalID();
*ppexpXoffset = pexpXoffset;
}
else
*ppexpXoffset = NULL;
}
if (ppexpYoffset)
{
Symbol psymYoffset = m_psymName->SubField("yoffset");
if (psymYoffset && psymYoffset->FitsSymbolType(ksymtGlyphAttr))
{
GdlLookupExpression * pexpYoffset = new GdlLookupExpression(*this);
pexpYoffset->m_psymName = psymYoffset;
pexpYoffset->m_nInternalID = psymYoffset->InternalID();
*ppexpYoffset = pexpYoffset;
}
else
*ppexpYoffset = NULL;
}
return true;
}
/*----------------------------------------------------------------------------------------------
Do various checks on the expression that is the value of a slot attribute or a constraint:
* legal use of slot references
* not reading a write-only attribute (eg kern)
* not reading the composite value of anything but a glyph metric
* valid user-definable slot attribute
For slot references, check that the expression does not make references to slots that
are out of range, or that represent line-breaks or inserted items.
Assumes that the expression has been type-checked, so we do not need to worry about the
situation of inappropriately performing operations on slot references (eg, adding them
together), or assigning numerical value where a slot reference is expected.
Arguments:
vfLb - vector of flags for each item in rule, true if it is a line-break
vfIns - vector of flags for each item, true if item is an insertion
fValue - true if the expression represents a value of an attribute that is
being set, in which case LB slots are illegal, and we need to
consider fValueIsInputSlot;
false if the expression is simply looking up information from
the input stream (ie in a constraint), so references to inserted
slots are illegal.
fValueIsInputSlot
- true if the expression is the new value of an attribute and any
slot references refer to a slot in the input stream (eg,
comp.X.ref) rather than a slot in the output stream (eg,
attach.to). In the former case, references to deleted slots
are legal but refs to inserted slots are not; in the latter case,
the opposite is true.
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::CheckRuleExpression(GrcFont * pfont, GdlRenderer * prndr,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
bool fValue, bool fValueIsInputSlot)
{
return m_pexpOperand->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
fValue, fValueIsInputSlot);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::CheckRuleExpression(GrcFont * pfont, GdlRenderer * prndr,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
bool fValue, bool fValueIsInputSlot)
{
bool fOkay = m_pexpOperand1->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
fValue, fValueIsInputSlot);
if (!m_pexpOperand2->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
fValue, fValueIsInputSlot))
{
fOkay = false;
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::CheckRuleExpression(GrcFont * pfont, GdlRenderer * prndr,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
bool fValue, bool fValueIsInputSlot)
{
bool fOkay = m_pexpTest->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
false, false);
if (!m_pexpTrue->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
fValue, fValueIsInputSlot))
{
fOkay = false;
}
if (!m_pexpFalse->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
fValue, fValueIsInputSlot))
{
fOkay = false;
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::CheckRuleExpression(GrcFont * /*pfont*/, GdlRenderer * prndr,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & /*vfDel*/,
bool /*fValue*/, bool /*fValueIsInputSlot*/)
{
Assert(m_psymName->FitsSymbolType(ksymtGlyphData) ||
m_psymName->FitsSymbolType(ksymtSlotAttr) ||
m_psymName->FitsSymbolType(ksymtFeature) ||
m_psymName->FitsSymbolType(ksymtInvalid));
if (m_nClusterLevel != 0 && !m_psymName->FitsSymbolType(ksymtGlyphMetric))
g_errorList.AddError(2135, this,
"Composite metrics are only available for glyph metrics");
if (m_psymName->FitsSymbolType(ksymtSlotAttr))
{
if (m_psymName->IsWriteOnlySlotAttr())
g_errorList.AddError(2136, this,
"The '",
m_psymName->FullName(),
"' attribute is write-only");
if (m_psymName->IsIndexedSlotAttr())
{
if (m_psymName->IsUserDefinableSlotAttr())
{
int nIndex = m_psymName->UserDefinableSlotAttrIndex();
if (nIndex < 0)
g_errorList.AddError(2137, this,
"Invalid slot attribute: ", m_psymName->FullName());
else if (nIndex >= kMaxUserDefinableSlotAttrs)
{
char rgch[20];
itoa(kMaxUserDefinableSlotAttrs, rgch, 10);
g_errorList.AddError(2138, this,
"Invalid slot attribute: ", m_psymName->FullName(),
"; maximum is ", rgch);
}
else
{
prndr->SetNumUserDefn(nIndex);
}
}
else
{
g_errorList.AddError(2139, this,
"Not permitted to read the '",
m_psymName->FullName(), "' attribute");
}
}
}
// Ignore fValue and fValueIsInputSlot; because this is a lookup expression,
// act as if fValue = false.
int crit = signed(vfLb.size());
if (m_pexpSelector)
{
int sr = m_pexpSelector->SlotNumber();
char rgchSlotNumber[20];
itoa(sr, rgchSlotNumber, 10);
if (sr < 1 || sr > crit)
{
g_errorList.AddError(2140, this,
"Slot selector out of range: @",
rgchSlotNumber,
".",
m_psymName->FullName());
return false;
}
// Always okay to read the attribute of a line-break item or a deleted item.
// Never okay to read the attribute of an inserted item.
else if (vfIns[sr - 1])
{
g_errorList.AddError(2141, this,
"Slot selector indicates an inserted item: @",
rgchSlotNumber,
".",
m_psymName->FullName());
return false;
}
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::CheckRuleExpression(GrcFont * pfont, GdlRenderer * /*prndr*/,
std::vector<bool> & /*vfLb*/, std::vector<bool> & /*vfIns*/, std::vector<bool> & /*vfDel*/,
bool /*fValue*/, bool /*fValueIsInputSlot*/)
{
m_nValue = pfont->ScaledToAbsolute(m_nValue, m_munits);
m_munits = (m_munits == kmunitNone) ? kmunitNone : kmunitUnscaled;
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::CheckRuleExpression(GrcFont * /*pfont*/, GdlRenderer * /*prndr*/,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
bool fValue, bool fValueIsInputSlot)
{
char rgchSlotNumber[20];
itoa(m_srNumber, rgchSlotNumber, 10);
if (m_srNumber < 1 || m_srNumber > signed(vfLb.size()))
{
g_errorList.AddError(2142, this,
"Slot reference out of range: @",
rgchSlotNumber);
return false;
}
else if (fValue && vfLb[m_srNumber - 1])
{
// Eg, attach.to = @2 or comp.X.ref = @2, where @2 is a LB slot
g_errorList.AddError(2143, this,
"Illegal reference to line-break slot: @",
rgchSlotNumber);
return false;
}
else if ((!fValue || fValueIsInputSlot) && vfIns[m_srNumber - 1])
{
// Eg, @1.bb.width or comp.X.ref = @1, where @1 is being inserted
g_errorList.AddError(2144, this,
"Illegal reference to inserted slot: @",
rgchSlotNumber);
return false;
}
else if (fValue && !fValueIsInputSlot && vfDel[m_srNumber - 1])
{
// Eg, attach.to = @3, where @3 is being deleted
g_errorList.AddError(2145, this,
"Illegal reference to deleted slot: @",
rgchSlotNumber);
return false;
}
else
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::CheckRuleExpression(GrcFont * /*pfont*/, GdlRenderer * /*prndr*/,
std::vector<bool> & /*vfLb*/, std::vector<bool> & /*vfIns*/, std::vector<bool> & /*vfDel*/,
bool /*fValue*/, bool /*fValueIsInputSlot*/)
{
// By this point any value string values (eg, values of the "lang" feature) should
// have been converted to integers.
g_errorList.AddError(2146, this,
"Illegal expression: ",
m_staValue);
return false;
}
/*----------------------------------------------------------------------------------------------
Adjust slot references based on the fact that we have prepended ANYs to the
beginning of the rule.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
m_pexpOperand->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
m_pexpOperand1->AdjustSlotRefsForPreAnys(critPrependedAnys);
m_pexpOperand2->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
m_pexpTest->AdjustSlotRefsForPreAnys(critPrependedAnys);
m_pexpTrue->AdjustSlotRefsForPreAnys(critPrependedAnys);
m_pexpFalse->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
if (m_pexpSelector)
m_pexpSelector->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::AdjustSlotRefsForPreAnys(int /*critPrependedAnys*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
m_srNumber += critPrependedAnys;
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::AdjustSlotRefsForPreAnys(int /*critPrependedAnys*/)
{
}
/*----------------------------------------------------------------------------------------------
Adjust any slot references to use the corresponding value of the vector, which is
either an input index or an output index.
Arguments:
prit - pointer to owning rule item, when expression is an attach.to command;
we store the adjusted index of the target of the attachment in
the rule item for future reference.
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::AdjustToIOIndices(std::vector<int> & virit, GdlRuleItem * prit)
{
Assert(prit == NULL);
m_pexpOperand->AdjustToIOIndices(virit, prit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::AdjustToIOIndices(std::vector<int> & virit, GdlRuleItem * prit)
{
Assert(prit == NULL);
m_pexpOperand1->AdjustToIOIndices(virit, prit);
m_pexpOperand2->AdjustToIOIndices(virit, prit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::AdjustToIOIndices(std::vector<int> & virit, GdlRuleItem * prit)
{
Assert(prit == NULL);
m_pexpTest->AdjustToIOIndices(virit, prit);
m_pexpTrue->AdjustToIOIndices(virit, prit);
m_pexpFalse->AdjustToIOIndices(virit, prit);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::AdjustToIOIndices(std::vector<int> & virit, GdlRuleItem * prit)
{
Assert(prit == NULL);
if (m_pexpSelector)
m_pexpSelector->AdjustToIOIndices(virit, prit);
}
/*--------------------------------------------------------------------------------------------*/
#ifdef NDEBUG
void GdlNumericExpression::AdjustToIOIndices(std::vector<int> &, GdlRuleItem *)
#else
void GdlNumericExpression::AdjustToIOIndices(std::vector<int> & /*virit*/, GdlRuleItem * prit)
#endif
{
Assert(prit == NULL);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::AdjustToIOIndices(std::vector<int> & virit, GdlRuleItem * prit)
{
if (m_srNumber == 0)
m_nIOIndex = -1;
else
m_nIOIndex = virit[m_srNumber - 1];
if (prit)
prit->SetAttachTo(m_nIOIndex);
}
/*--------------------------------------------------------------------------------------------*/
#ifdef NDEBUG
void GdlStringExpression::AdjustToIOIndices(std::vector<int> &, GdlRuleItem *)
#else
void GdlStringExpression::AdjustToIOIndices(std::vector<int> & /*virit*/, GdlRuleItem * prit)
#endif
{
Assert(prit == NULL);
}
/*----------------------------------------------------------------------------------------------
Convert a string-plus-codepage into a Unicode string (UTF-16 is what is required for the
TT name table).
----------------------------------------------------------------------------------------------*/
std::wstring GdlStringExpression::ConvertToUnicode()
{
int cch = m_staValue.length();
const schar * pchs = m_staValue.data();
utf16 * pchw = new utf16[cch + 1];
Platform_8bitToUnicode(m_nCodepage, pchs, cch, pchw, cch);
pchw[cch] = 0;
wchar_t * pchw_wchar = new wchar_t[cch + 1];
std::copy(pchw, pchw + cch + 1, pchw_wchar);
std::wstring stuRet(pchw_wchar);
//#ifdef GR_FW
// StrUni stuRet((wchar_t*)pchw, cch); // something about the new VS compiler needs this :-(
//#else
// StrUni stuRet(pchw, cch);
//#endif // GR_FW
delete[] pchw;
delete[] pchw_wchar;
return stuRet;
}
/*----------------------------------------------------------------------------------------------
Return true if the expression is testing the justification status (JustifyLevel or
JustifyMode).
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::MaxJustificationLevel(int * pnLevel)
{
m_pexpOperand->MaxJustificationLevel(pnLevel);
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::MaxJustificationLevel(int * pnLevel)
{
m_pexpOperand1->MaxJustificationLevel(pnLevel);
m_pexpOperand2->MaxJustificationLevel(pnLevel);
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::MaxJustificationLevel(int * pnLevel)
{
m_pexpTest->MaxJustificationLevel(pnLevel);
m_pexpTrue->MaxJustificationLevel(pnLevel);
m_pexpFalse->MaxJustificationLevel(pnLevel);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::MaxJustificationLevel(int * pnLevel)
{
int n = m_psymName->JustificationLevel();
*pnLevel = max(*pnLevel, n);
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::MaxJustificationLevel(int * /*pnLevel*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::MaxJustificationLevel(int * /*pnLevel*/)
{
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::MaxJustificationLevel(int * /*pnLevel*/)
{
}
/*----------------------------------------------------------------------------------------------
Return true if the expression is testing the justification status (JustifyLevel or
JustifyMode).
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::TestsJustification()
{
return m_pexpOperand->TestsJustification();
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::TestsJustification()
{
if (m_pexpOperand1->TestsJustification())
return true;
return m_pexpOperand2->TestsJustification();
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::TestsJustification()
{
if (m_pexpTest->TestsJustification())
return true;
if (m_pexpTrue->TestsJustification())
return true;
if (m_pexpFalse)
return m_pexpFalse->TestsJustification();
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::TestsJustification()
{
if (!m_psymName->FitsSymbolType(ksymtProcState))
return false;
if (m_psymName->FullName() == "JustifyMode")
return true;
//if (m_psymName->FullName() == "JustifyLevel")
// return true;
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::TestsJustification()
{
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::TestsJustification()
{
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::TestsJustification()
{
return false;
}
/*----------------------------------------------------------------------------------------------
Check that the expression is compatible with the requested version of the Silf table.
If not, return the version required.
----------------------------------------------------------------------------------------------*/
bool GdlUnaryExpression::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
return m_pexpOperand->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool f1 = m_pexpOperand1->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
bool f2 = m_pexpOperand2->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
return (f1 && f2);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlCondExpression::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool fTest = m_pexpTest->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
bool fTrue = m_pexpTrue->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
bool fFalse = m_pexpFalse->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
return (fTest && fTrue && fFalse);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLookupExpression::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded,
int * pfxdCpilrNeeded)
{
bool fRet = true;
if (TestsJustification())
{
*pfxdNeeded = max(*pfxdNeeded, 0x00020000);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00020000);
fRet = (fxdVersion >= 0x00020000);
}
if (m_psymName->IsMeasureAttr())
{
*pfxdNeeded = max(*pfxdNeeded, 0x00020000);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00020000);
fRet = (fxdVersion >= 0x00020000);
}
if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
{
int nID = m_psymName->InternalID();
if (nID >= 0xFF)
{
*pfxdNeeded = max(*pfxdNeeded, 0x00030000);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00030000);
fRet = (fxdVersion >= 0x00030000);
}
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlClassMemberExpression::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded,
int * pfxdCpilrNeeded)
{
bool fRet = (fxdVersion >= 0x00020000);
if (*pfxdNeeded < 0x00030000)
*pfxdNeeded = max(*pfxdNeeded, 0x00020001);
else
*pfxdNeeded = max(*pfxdNeeded, 0x00030002);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00040001);
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlNumericExpression::CompatibleWithVersion(int /*fxdVersion*/, int * /*pfxdNeeded*/,
int * /*pfxdCpilrNeeded*/)
{
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSlotRefExpression::CompatibleWithVersion(int /*fxdVersion*/, int * /*pfxdNeeded*/,
int * /*pfxdCpilrNeeded*/)
{
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlStringExpression::CompatibleWithVersion(int /*fxdVersion*/, int * /*pfxdNeeded*/,
int * /*pfxdCpilrNeeded*/)
{
return true;
}
/*----------------------------------------------------------------------------------------------
Generate an error if they are looking up the value of the attach.to attribute and it is
testing for anything other than zero.
----------------------------------------------------------------------------------------------*/
bool GdlBinaryExpression::CheckAttachToLookup()
{
// Assumes SimplifyAndUnscale has already been called.
GdlLookupExpression * pexpLookupOp1 = dynamic_cast<GdlLookupExpression *>(m_pexpOperand1);
GdlNumericExpression * pexpNumOp2 = dynamic_cast<GdlNumericExpression *>(m_pexpOperand2);
if (pexpLookupOp1 && pexpLookupOp1->m_psymName->FitsSymbolType(ksymtSlotAttr)
&& pexpLookupOp1->m_psymName->IsAttachTo())
{
if (!pexpNumOp2 || pexpNumOp2->m_nValue != 0)
{
g_errorList.AddError(3161, this,
"Illegal use of attach.to attribute; can only test equality with 0");
return false;
}
}
return true;
}
/***********************************************************************************************
Methods: Compiler
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Translate the expression into engine code and append it to the code block.
Arguments:
fxdRuleVersion - version of rule code to generate
vbOutput - vector of bytes, engine code being generated
iritCurrent - current rule item index (0-based); -1 if we are in an -if- statement
pviritInput - vector of input indices for this rule; only relevant when
generating constraints; NULL if we are generating actions
nIIndex - input index of current slot
fAttachAt - true if this the value of an attach.at attribute, in which case
output a special command that will read the value of the attached
slot
iritAttachTo - value of attach.to attribute for current item (0-based, relative
to start of rule)
pnValue - return the value of the slot ref expression for the benefit of
calling code that, if it happens to be an attach.to setter,
needs to decide how to handle the accompanying insert = false;
only slot references need to worry about it
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::GenerateEngineCode(int fxdRuleVersion, std::vector<gr::byte> & vbOutput,
int iritCurrent, std::vector<int> * pviritInput, int nIIndex,
bool fAttachAt, int iritAttachTo, int * pnValue)
{
m_pexpOperand->GenerateEngineCode(fxdRuleVersion, vbOutput, iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, pnValue);
std::string staOp = m_psymOperator->FullName();
if (strcmp(staOp.c_str(), "!") == 0)
vbOutput.push_back(kopNot);
else if (strcmp(staOp.c_str(), "-") == 0)
vbOutput.push_back(kopNeg);
// eventually, perhaps add kopTrunc8 and kopTrunc16
else
{
Assert(false);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::GenerateEngineCode(int fxdRuleVersion, std::vector<gr::byte> & vbOutput,
int iritCurrent, std::vector<int> * pviritInput, int nIIndex,
bool fAttachAt, int iritAttachTo, int * /*pnValue*/)
{
int nBogus;
m_pexpOperand1->GenerateEngineCode(fxdRuleVersion, vbOutput,
iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, &nBogus);
m_pexpOperand2->GenerateEngineCode(fxdRuleVersion, vbOutput,
iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, &nBogus);
std::string staOp = m_psymOperator->FullName();
if (staOp == "+")
vbOutput.push_back(kopAdd);
else if (staOp == "-")
vbOutput.push_back(kopSub);
else if (staOp == "*")
vbOutput.push_back(kopMul);
else if (staOp == "/")
vbOutput.push_back(kopDiv);
else if (staOp == "max")
vbOutput.push_back(kopMax);
else if (staOp == "min")
vbOutput.push_back(kopMin);
else if (staOp == "&&")
vbOutput.push_back(kopAnd);
else if (staOp == "||")
vbOutput.push_back(kopOr);
else if (staOp == "==")
vbOutput.push_back(kopEqual);
else if (staOp == "!=")
vbOutput.push_back(kopNotEq);
else if (staOp == "<")
vbOutput.push_back(kopLess);
else if (staOp == ">")
vbOutput.push_back(kopGtr);
else if (staOp == "<=")
vbOutput.push_back(kopLessEq);
else if (staOp == ">=")
vbOutput.push_back(kopGtrEq);
else
{
Assert(false);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::GenerateEngineCode(int fxdRuleVersion, std::vector<gr::byte> & vbOutput,
int iritCurrent, std::vector<int> * pviritInput, int nIIndex,
bool fAttachAt, int iritAttachTo, int * pnValue)
{
int nBogus;
m_pexpTest->GenerateEngineCode(fxdRuleVersion, vbOutput, iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, &nBogus);
m_pexpTrue->GenerateEngineCode(fxdRuleVersion, vbOutput, iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, pnValue);
m_pexpFalse->GenerateEngineCode(fxdRuleVersion, vbOutput, iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, pnValue);
vbOutput.push_back(kopCond);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::GenerateEngineCode(int fxdRuleVersion, std::vector<gr::byte> & vbOutput,
int iritCurrent, std::vector<int> * pviritInput, int nIIndex,
bool fAttachAt, int iritAttachTo, int * pnValue)
{
if (m_pexpSimplified)
{
m_pexpSimplified->GenerateEngineCode(fxdRuleVersion, vbOutput,
iritCurrent, pviritInput, nIIndex,
fAttachAt, iritAttachTo, pnValue);
return;
}
int nSelOffset;
if (iritCurrent == -1)
{
// In an -if- statement.
Assert(!m_pexpSelector);
nSelOffset = 0; // whatever the current slot of interest is
}
else
{
int nSel;
if (m_pexpSelector)
{
nSel = m_pexpSelector->m_nIOIndex;
if (nSel < 0)
nSel = (nSel + 1) * -1; // inverse of calculation in
// GdlSubstitutionItem::AssignIOIndices()
}
else
nSel = iritCurrent;
// Adjust for constraints when there may be insertions.
int nIIndex2 = nIIndex;
if (pviritInput)
{
nIIndex2 = (*pviritInput)[nIIndex];
nSel = (*pviritInput)[nSel];
}
nSelOffset = nSel - nIIndex2;
}
// Several slot attributes and glyph attributes have the same name; treat these as
// slot attributes, since their values will default to the glyph attributes.
if (m_psymName->FitsSymbolType(ksymtSlotAttr))
{
if (m_psymName->IsIndexedSlotAttr())
{
if (m_psymName->IsUserDefinableSlotAttr())
{
vbOutput.push_back(kopPushISlotAttr);
vbOutput.push_back(m_psymName->SlotAttrEngineCodeOp());
vbOutput.push_back(nSelOffset);
vbOutput.push_back(m_psymName->UserDefinableSlotAttrIndex());
}
else
{
Assert(false); // currently no way to look up the value of a
// component.XXX.ref attr
}
}
else
{
vbOutput.push_back(kopPushSlotAttr);
vbOutput.push_back(m_psymName->SlotAttrEngineCodeOp());
vbOutput.push_back(nSelOffset);
}
}
else if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
{
if (m_psymName->IsIndexedGlyphAttr())
{
Assert(false); // currently no way to look up the value of a component attr;
// eventually use kopPushIGlyphAttr.
}
else
{
int nID = m_psymName->InternalID();
if (fAttachAt)
{
Assert(iritAttachTo != -1);
int nSel = (m_pexpSelector) ? m_pexpSelector->m_nIOIndex : iritAttachTo;
if (fxdRuleVersion <= 0x00020000)
{
// Use old 8-bit version of this command.
vbOutput.push_back(kopPushAttToGAttrV1_2);
vbOutput.push_back(nID);
}
else
{
vbOutput.push_back(kopPushAttToGlyphAttr);
vbOutput.push_back(nID >> 8);
vbOutput.push_back(nID & 0x000000FF);
}
vbOutput.push_back(nSel - iritAttachTo); // relative to attach.to target
}
else
{
if (fxdRuleVersion <= 0x00020000)
{
// Use old 8-bit version of this command.
vbOutput.push_back(kopPushGlyphAttrV1_2);
vbOutput.push_back(nID);
}
else
{
vbOutput.push_back(kopPushGlyphAttr);
vbOutput.push_back(nID >> 8);
vbOutput.push_back(nID & 0x000000FF);
}
vbOutput.push_back(nSelOffset);
}
}
}
else if (m_psymName->FitsSymbolType(ksymtGlyphMetric))
{
if (fAttachAt)
{
Assert(iritAttachTo != -1);
int nSel = (m_pexpSelector) ? m_pexpSelector->m_nIOIndex : iritAttachTo;
vbOutput.push_back(kopPushAttToGlyphMetric);
vbOutput.push_back(m_psymName->GlyphMetricEngineCodeOp());
vbOutput.push_back(nSel - iritAttachTo); // relative to attach.to target
}
else
{
vbOutput.push_back(kopPushGlyphMetric);
vbOutput.push_back(m_psymName->GlyphMetricEngineCodeOp());
vbOutput.push_back(nSelOffset);
}
vbOutput.push_back(m_nClusterLevel);
}
else if (m_psymName->FitsSymbolType(ksymtFeature))
{
Assert(!m_pexpSelector);
vbOutput.push_back(kopPushFeat);
GdlFeatureDefn * pfeat = m_psymName->FeatureDefnData();
Assert(pfeat);
vbOutput.push_back(pfeat->InternalID());
vbOutput.push_back(nSelOffset);
}
else if (m_psymName->FitsSymbolType(ksymtProcState))
{
Assert(!m_pexpSelector);
vbOutput.push_back(kopPushProcState);
if (m_psymName->FullName() == "JustifyMode")
vbOutput.push_back(kpstatJustifyMode);
else if (m_psymName->FullName() == "JustifyLevel")
vbOutput.push_back(kpstatJustifyLevel);
else
{
Assert(false);
}
}
else
{
Assert(false);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::GenerateEngineCode(int /*fxdRuleVersion*/, std::vector<gr::byte> & vbOutput,
int /*iritCurrent*/, std::vector<int> * /*pviritInput*/, int /*nIIndex*/,
bool /*fAttachAt*/, int /*iritAttachTo*/, int * /*pnValue*/)
{
// Output most-significant byte first.
gr::byte b4 = m_nValue & 0x000000FF;
if ((m_nValue & 0xFFFFFF80) == 0 || (m_nValue & 0xFFFFFF80) == 0xFFFFFF80)
{
vbOutput.push_back(kopPushByte);
vbOutput.push_back(b4);
}
else
{
gr::byte b3 = (m_nValue & 0x0000FF00) >> 8;
if ((m_nValue & 0xFFFF8000) == 0 || (m_nValue & 0xFFFF8000) == 0xFFFF8000)
{
vbOutput.push_back(kopPushShort);
vbOutput.push_back(b3);
vbOutput.push_back(b4);
}
else
{
gr::byte b1 = (m_nValue & 0xFF000000) >> 24;
gr::byte b2 = (m_nValue & 0x00FF0000) >> 16;
vbOutput.push_back(kopPushLong);
vbOutput.push_back(b1);
vbOutput.push_back(b2);
vbOutput.push_back(b3);
vbOutput.push_back(b4);
}
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::GenerateEngineCode(int /*fxdRuleVersion*/, std::vector<gr::byte> & vbOutput,
int iritCurrent, std::vector<int> * pviritInput, int /*nIIndex*/,
bool /*fAttachAt*/, int /*iritAttachTo*/, int * pnValue)
{
int nOffset = m_nIOIndex - iritCurrent;
Assert(!pviritInput); // should not be used for constraints
if (pviritInput)
nOffset = (*pviritInput)[m_nIOIndex] - iritCurrent;
char bOffset = (char)nOffset;
Assert((int)bOffset == nOffset); // no truncation error
// If this happens to be the value of an attach.to attribute, current or following
// slot needs to have insert = false set.
*pnValue = nOffset;
vbOutput.push_back(kopPushByte);
vbOutput.push_back(bOffset);
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::GenerateEngineCode(int /*fxdRuleVersion*/, std::vector<gr::byte> & /*vbOutput*/,
int /*iritCurrent*/, std::vector<int> * /*pviritInput*/, int /*nIIndex*/,
bool /*fAttachAt*/, int /*iritAttachTo*/, int * /*pnValue*/)
{
// Should never have string expressions in engine code.
Assert(false);
}
/*----------------------------------------------------------------------------------------------
Generate a pretty-print of the expression.
Arguments:
pcman
strmOut - Stream on which to generate the results
fParens - Put parens around binary expression
----------------------------------------------------------------------------------------------*/
void GdlUnaryExpression::PrettyPrint(GrcManager * pcman, std::ostream & strmOut, bool fXml,
bool /*fParens*/)
{
strmOut << m_psymOperator->FullName().data() << "(";
m_pexpOperand->PrettyPrint(pcman, strmOut, fXml, false);
strmOut << ")";
}
/*--------------------------------------------------------------------------------------------*/
void GdlBinaryExpression::PrettyPrint(GrcManager * pcman, std::ostream & strmOut, bool fXml,
bool fParens)
{
if (fParens)
strmOut << "(";
m_pexpOperand1->PrettyPrint(pcman, strmOut, fXml, true);
if (fXml && strcmp(m_psymOperator->FullName().data(), "&&") == 0)
strmOut << " && ";
else if (fXml && strcmp(m_psymOperator->FullName().data(), "<") == 0)
strmOut << " < ";
else if (fXml && strcmp(m_psymOperator->FullName().data(), "<=") == 0)
strmOut << " <= ";
else if (fXml && strcmp(m_psymOperator->FullName().data(), ">") == 0)
strmOut << " > ";
else if (fXml && strcmp(m_psymOperator->FullName().data(), ">=") == 0)
strmOut << " >= ";
else
strmOut << " " << m_psymOperator->FullName().data() << " ";
m_pexpOperand2->PrettyPrint(pcman, strmOut, fXml, true);
if (fParens)
strmOut << ")";
}
/*--------------------------------------------------------------------------------------------*/
void GdlCondExpression::PrettyPrint(GrcManager * pcman, std::ostream & strmOut, bool fXml,
bool /*fParens*/)
{
strmOut << "(";
m_pexpTest->PrettyPrint(pcman, strmOut, fXml, true);
strmOut << ") ? ";
m_pexpTrue->PrettyPrint(pcman, strmOut, fXml, true);
strmOut << " : ";
m_pexpFalse->PrettyPrint(pcman, strmOut, fXml, true);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLookupExpression::PrettyPrint(GrcManager * pcman, std::ostream & strmOut, bool fXml,
bool /*fParens*/)
{
if (m_pexpSelector)
{
m_pexpSelector->PrettyPrint(pcman, strmOut, fXml, true);
strmOut << ".";
}
strmOut << m_psymName->FullAbbrev().data();
}
/*--------------------------------------------------------------------------------------------*/
void GdlNumericExpression::PrettyPrint(GrcManager * /*pcman*/, std::ostream & strmOut,
bool /*fXml*/, bool /*fParens*/)
{
strmOut << m_nValue;
}
/*--------------------------------------------------------------------------------------------*/
void GdlSlotRefExpression::PrettyPrint(GrcManager * /*pcman*/, std::ostream & strmOut,
bool /*fXml*/, bool /*fParens*/)
{
strmOut << "@" << m_srNumber;
}
/*--------------------------------------------------------------------------------------------*/
void GdlStringExpression::PrettyPrint(GrcManager * /*pcman*/, std::ostream & strmOut,
bool /*fXml*/, bool /*fParens*/)
{
strmOut << m_staValue;
}
|