/usr/share/fpcsrc/2.6.2/compiler/ninl.pas is in fpc-source-2.6.2 2.6.2-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 | {
Copyright (c) 1998-2007 by Florian Klaempfl
Type checking and register allocation for inline nodes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit ninl;
{$i fpcdefs.inc}
interface
uses
node,htypechk,cpuinfo,symtype;
{$i compinnr.inc}
type
tinlinenode = class(tunarynode)
inlinenumber : byte;
constructor create(number : byte;is_const:boolean;l : tnode);virtual;
constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
procedure ppuwrite(ppufile:tcompilerppufile);override;
function dogetcopy : tnode;override;
function pass_1 : tnode;override;
function pass_typecheck:tnode;override;
function simplify(forinline : boolean): tnode;override;
function docompare(p: tnode): boolean; override;
{ pack and unpack are changed into for-loops by the compiler }
function first_pack_unpack: tnode; virtual;
{ All the following routines currently
call compilerprocs, unless they are
overridden in which case, the code
generator handles them.
}
function first_pi: tnode ; virtual;
function first_arctan_real: tnode; virtual;
function first_abs_real: tnode; virtual;
function first_sqr_real: tnode; virtual;
function first_sqrt_real: tnode; virtual;
function first_ln_real: tnode; virtual;
function first_cos_real: tnode; virtual;
function first_sin_real: tnode; virtual;
function first_exp_real: tnode; virtual;
function first_frac_real: tnode; virtual;
function first_round_real: tnode; virtual;
function first_trunc_real: tnode; virtual;
function first_int_real: tnode; virtual;
function first_abs_long: tnode; virtual;
private
function handle_str: tnode;
function handle_reset_rewrite_typed: tnode;
function handle_text_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
function handle_typed_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
function handle_read_write: tnode;
function handle_val: tnode;
end;
tinlinenodeclass = class of tinlinenode;
var
cinlinenode : tinlinenodeclass = tinlinenode;
function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
implementation
uses
verbose,globals,systems,constexp,
globtype, cutils,
symconst,symdef,symsym,symtable,paramgr,defutil,
pass_1,
ncal,ncon,ncnv,nadd,nld,nbas,nflw,nmem,nmat,nutils,
nobjc,objcdef,
cgbase,procinfo
;
function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
begin
geninlinenode:=cinlinenode.create(number,is_const,l);
end;
{*****************************************************************************
TINLINENODE
*****************************************************************************}
constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
begin
inherited create(inlinen,l);
if is_const then
include(flags,nf_inlineconst);
inlinenumber:=number;
end;
constructor tinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
begin
inherited ppuload(t,ppufile);
inlinenumber:=ppufile.getbyte;
end;
procedure tinlinenode.ppuwrite(ppufile:tcompilerppufile);
begin
inherited ppuwrite(ppufile);
ppufile.putbyte(inlinenumber);
end;
function tinlinenode.dogetcopy : tnode;
var
n : tinlinenode;
begin
n:=tinlinenode(inherited dogetcopy);
n.inlinenumber:=inlinenumber;
result:=n;
end;
function tinlinenode.handle_str : tnode;
var
lenpara,
fracpara,
newparas,
tmppara,
dest,
source : tcallparanode;
procname: string;
is_real,is_enum : boolean;
rt : aint;
begin
result := cerrornode.create;
{ get destination string }
dest := tcallparanode(left);
{ get source para (number) }
source := dest;
while assigned(source.right) do
source := tcallparanode(source.right);
{ destination parameter must be a normal (not a colon) parameter, this
check is needed because str(v:len) also has 2 parameters }
if (source=dest) or
(cpf_is_colon_para in tcallparanode(dest).callparaflags) then
begin
CGMessage1(parser_e_wrong_parameter_size,'Str');
exit;
end;
{ in case we are in a generic definition, we cannot
do all checks, the parameters might be type parameters }
if df_generic in current_procinfo.procdef.defoptions then
begin
result.Free;
result:=nil;
resultdef:=voidtype;
exit;
end;
is_real:=(source.resultdef.typ = floatdef) or is_currency(source.resultdef);
is_enum:=source.left.resultdef.typ=enumdef;
if ((dest.left.resultdef.typ<>stringdef) and
not(is_chararray(dest.left.resultdef))) or
not(is_real or is_enum or
(source.left.resultdef.typ=orddef)) then
begin
CGMessagePos(fileinfo,parser_e_illegal_expression);
exit;
end;
{ get len/frac parameters }
lenpara := nil;
fracpara := nil;
if (cpf_is_colon_para in tcallparanode(dest.right).callparaflags) then
begin
lenpara := tcallparanode(dest.right);
{ we can let the callnode do the type checking of these parameters too, }
{ but then the error messages aren't as nice }
if not is_integer(lenpara.resultdef) then
begin
CGMessagePos1(lenpara.fileinfo,
type_e_integer_expr_expected,lenpara.resultdef.typename);
exit;
end;
if (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
begin
{ parameters are in reverse order! }
fracpara := lenpara;
lenpara := tcallparanode(lenpara.right);
if not is_real then
begin
CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
exit
end;
if not is_integer(lenpara.resultdef) then
begin
CGMessagePos1(lenpara.fileinfo,
type_e_integer_expr_expected,lenpara.resultdef.typename);
exit;
end;
end;
end;
{ generate the parameter list for the compilerproc }
newparas := dest;
{ if we have a float parameter, insert the realtype, len and fracpara parameters }
if is_real then
begin
{ insert realtype parameter }
if not is_currency(source.resultdef) then
begin
rt:=ord(tfloatdef(source.left.resultdef).floattype);
newparas.right := ccallparanode.create(cordconstnode.create(
rt,s32inttype,true),newparas.right);
tmppara:=tcallparanode(newparas.right);
end
else
tmppara:=newparas;
{ if necessary, insert a fraction parameter }
if not assigned(fracpara) then
begin
tmppara.right := ccallparanode.create(
cordconstnode.create(int64(-1),s32inttype,false),
tmppara.right);
fracpara := tcallparanode(tmppara.right);
end;
{ if necessary, insert a length para }
if not assigned(lenpara) then
fracpara.right := ccallparanode.create(
cordconstnode.create(int64(-32767),s32inttype,false),
fracpara.right);
end
else if is_enum then
begin
{Insert a reference to the ord2string index.}
newparas.right:=Ccallparanode.create(
Caddrnode.create_internal(
Crttinode.create(Tenumdef(source.left.resultdef),fullrtti,rdt_normal)
),
newparas.right);
{Insert a reference to the typinfo.}
newparas.right:=Ccallparanode.create(
Caddrnode.create_internal(
Crttinode.create(Tenumdef(source.left.resultdef),fullrtti,rdt_ord2str)
),
newparas.right);
{Insert a type conversion from the enumeration to longint.}
source.left:=Ctypeconvnode.create_internal(source.left,s32inttype);
typecheckpass(source.left);
{ if necessary, insert a length para }
if not assigned(lenpara) then
Tcallparanode(Tcallparanode(newparas.right).right).right:=
Ccallparanode.create(
cordconstnode.create(int64(-1),s32inttype,false),
Tcallparanode(Tcallparanode(newparas.right).right).right
);
end
else
{ for a normal parameter, insert a only length parameter if one is missing }
if not assigned(lenpara) then
newparas.right := ccallparanode.create(cordconstnode.create(int64(-1),s32inttype,false),
newparas.right);
{ remove the parameters from the original node so they won't get disposed, }
{ since they're reused }
left := nil;
{ create procedure name }
if is_chararray(dest.resultdef) then
procname:='fpc_chararray_'
else
procname := 'fpc_' + tstringdef(dest.resultdef).stringtypname+'_';
if is_real then
if is_currency(source.resultdef) then
procname := procname + 'currency'
else
procname := procname + 'float'
else if is_enum then
procname:=procname+'enum'
else
case torddef(source.resultdef).ordtype of
{$ifdef cpu64bitaddr}
u64bit:
procname := procname + 'uint';
{$else}
u32bit:
procname := procname + 'uint';
u64bit:
procname := procname + 'qword';
scurrency,
s64bit:
procname := procname + 'int64';
pasbool8,pasbool16,pasbool32,pasbool64,
bool8bit,bool16bit,bool32bit,bool64bit:
procname := procname + 'bool';
{$endif}
else
procname := procname + 'sint';
end;
{ free the errornode we generated in the beginning }
result.free;
{ create the call node, }
result := ccallnode.createintern(procname,newparas);
end;
function tinlinenode.handle_reset_rewrite_typed: tnode;
begin
{ since this is a "in_xxxx_typedfile" node, we can be sure we have }
{ a typed file as argument and we don't have to check it again (JM) }
{ add the recsize parameter }
{ note: for some reason, the parameter of intern procedures with only one }
{ parameter is gets lifted out of its original tcallparanode (see round }
{ line 1306 of ncal.pas), so recreate a tcallparanode here (JM) }
left := ccallparanode.create(cordconstnode.create(
tfiledef(left.resultdef).typedfiledef.size,s32inttype,true),
ccallparanode.create(left,nil));
{ create the correct call }
if m_iso in current_settings.modeswitches then
begin
if inlinenumber=in_reset_typedfile then
result := ccallnode.createintern('fpc_reset_typed_iso',left)
else
result := ccallnode.createintern('fpc_rewrite_typed_iso',left);
end
else
begin
if inlinenumber=in_reset_typedfile then
result := ccallnode.createintern('fpc_reset_typed',left)
else
result := ccallnode.createintern('fpc_rewrite_typed',left);
end;
{ make sure left doesn't get disposed, since we use it in the new call }
left := nil;
end;
procedure maybe_convert_to_string(var n: tnode);
begin
{ stringconstnodes are arrays of char. It's much more }
{ efficient to write a constant string, so convert }
{ either to shortstring or ansistring depending on }
{ length }
if (n.nodetype=stringconstn) then
if is_chararray(n.resultdef) then
if (tstringconstnode(n).len<=255) then
inserttypeconv(n,cshortstringtype)
else
inserttypeconv(n,cansistringtype)
else if is_widechararray(n.resultdef) then
inserttypeconv(n,cwidestringtype);
end;
function Tinlinenode.handle_text_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
{Read(ln)/write(ln) for text files.}
const procprefixes:array[boolean] of string[15]=('fpc_write_text_','fpc_read_text_');
var error_para,is_real,special_handling,found_error,do_read:boolean;
p1:Tnode;
nextpara,
indexpara,
lenpara,
para,
fracpara:Tcallparanode;
temp:Ttempcreatenode;
readfunctype:Tdef;
name:string[63];
begin
para:=Tcallparanode(params);
found_error:=false;
do_read:=inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
while assigned(para) do
begin
{ is this parameter faulty? }
error_para:=false;
{ is this parameter a real? }
is_real:=false;
{ type used for the read(), this is used to check
whether a temp is needed for range checking }
readfunctype:=nil;
{ can't read/write types }
if (para.left.nodetype=typen) and not(ttypenode(para.left).typedef.typ=undefineddef) then
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end;
{ support writeln(procvar) }
if para.left.resultdef.typ=procvardef then
begin
p1:=ccallnode.create_procvar(nil,para.left);
typecheckpass(p1);
para.left:=p1;
end;
if inlinenumber in [in_write_x,in_writeln_x] then
{ prefer strings to chararrays }
maybe_convert_to_string(para.left);
case para.left.resultdef.typ of
stringdef :
name:=procprefixes[do_read]+tstringdef(para.left.resultdef).stringtypname;
pointerdef :
begin
if (not is_pchar(para.left.resultdef)) or do_read then
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end
else
name:=procprefixes[do_read]+'pchar_as_pointer';
end;
floatdef :
begin
is_real:=true;
if Tfloatdef(para.left.resultdef).floattype=s64currency then
name := procprefixes[do_read]+'currency'
else
begin
name := procprefixes[do_read]+'float';
readfunctype:=pbestrealtype^;
end;
end;
enumdef:
begin
name:=procprefixes[do_read]+'enum';
readfunctype:=s32inttype;
end;
orddef :
begin
case Torddef(para.left.resultdef).ordtype of
{$ifdef cpu64bitaddr}
s64bit,
{$endif cpu64bitaddr}
s8bit,
s16bit,
s32bit :
begin
name := procprefixes[do_read]+'sint';
readfunctype:=sinttype;
end;
{$ifdef cpu64bitaddr}
u64bit,
{$endif cpu64bitaddr}
u8bit,
u16bit,
u32bit :
begin
name := procprefixes[do_read]+'uint';
readfunctype:=uinttype;
end;
uchar :
begin
name := procprefixes[do_read]+'char';
{ iso pascal needs a different handler }
if (m_iso in current_settings.modeswitches) and do_read then
name:=name+'_iso';
readfunctype:=cchartype;
end;
uwidechar :
begin
name := procprefixes[do_read]+'widechar';
readfunctype:=cwidechartype;
end;
{$ifndef cpu64bitaddr}
s64bit :
begin
name := procprefixes[do_read]+'int64';
readfunctype:=s64inttype;
end;
u64bit :
begin
name := procprefixes[do_read]+'qword';
readfunctype:=u64inttype;
end;
{$endif not cpu64bitaddr}
scurrency:
begin
name := procprefixes[do_read]+'currency';
readfunctype:=s64currencytype;
is_real:=true;
end;
pasbool8,
pasbool16,
pasbool32,
pasbool64,
bool8bit,
bool16bit,
bool32bit,
bool64bit:
if do_read then
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end
else
begin
name := procprefixes[do_read]+'boolean';
readfunctype:=pasbool8type;
end
else
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end;
end;
end;
variantdef :
name:=procprefixes[do_read]+'variant';
arraydef :
begin
if is_chararray(para.left.resultdef) then
name := procprefixes[do_read]+'pchar_as_array'
else
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end
end;
{ generic parameter }
undefineddef:
{ don't try to generate any code for a writeln on a generic parameter }
error_para:=true;
else
begin
CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
error_para := true;
end;
end;
{ iso pascal needs a different handler }
if (m_iso in current_settings.modeswitches) and not(do_read) then
name:=name+'_iso';
{ check for length/fractional colon para's }
fracpara:=nil;
lenpara:=nil;
indexpara:=nil;
if assigned(para.right) and
(cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
begin
lenpara := tcallparanode(para.right);
if assigned(lenpara.right) and
(cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
fracpara:=tcallparanode(lenpara.right);
end;
{ get the next parameter now already, because we're going }
{ to muck around with the pointers }
if assigned(fracpara) then
nextpara := tcallparanode(fracpara.right)
else if assigned(lenpara) then
nextpara := tcallparanode(lenpara.right)
else
nextpara := tcallparanode(para.right);
{ check if a fracpara is allowed }
if assigned(fracpara) and not is_real then
begin
CGMessagePos(fracpara.fileinfo,parser_e_illegal_colon_qualifier);
error_para := true;
end
else if assigned(lenpara) and do_read then
begin
{ I think this is already filtered out by parsing, but I'm not sure (JM) }
CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
error_para := true;
end;
{ adjust found_error }
found_error := found_error or error_para;
if not error_para then
begin
special_handling:=false;
{ create dummy frac/len para's if necessary }
if not do_read then
begin
{ difference in default value for floats and the rest :( }
if not is_real then
begin
if not assigned(lenpara) then
begin
if m_iso in current_settings.modeswitches then
lenpara := ccallparanode.create(
cordconstnode.create(-1,s32inttype,false),nil)
else
lenpara := ccallparanode.create(
cordconstnode.create(0,s32inttype,false),nil);
end
else
{ make sure we don't pass the successive }
{ parameters too. We also already have a }
{ reference to the next parameter in }
{ nextpara }
lenpara.right := nil;
end
else
begin
if not assigned(lenpara) then
lenpara := ccallparanode.create(
cordconstnode.create(int64(-32767),s32inttype,false),nil);
{ also create a default fracpara if necessary }
if not assigned(fracpara) then
fracpara := ccallparanode.create(
cordconstnode.create(int64(-1),s32inttype,false),nil);
{ add it to the lenpara }
lenpara.right := fracpara;
if not is_currency(para.left.resultdef) then
begin
{ and add the realtype para (this also removes the link }
{ to any parameters coming after it) }
fracpara.right := ccallparanode.create(
cordconstnode.create(ord(tfloatdef(para.left.resultdef).floattype),
s32inttype,true),nil);
end
else
fracpara.right:=nil;
end;
if para.left.resultdef.typ=enumdef then
begin
{To write(ln) an enum we need a some extra parameters.}
{Insert a reference to the ord2string index.}
indexpara:=Ccallparanode.create(
Caddrnode.create_internal(
Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_normal)
),
nil);
{Insert a reference to the typinfo.}
indexpara:=Ccallparanode.create(
Caddrnode.create_internal(
Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_ord2str)
),
indexpara);
{Insert a type conversion to to convert the enum to longint.}
para.left:=Ctypeconvnode.create_internal(para.left,s32inttype);
typecheckpass(para.left);
end;
end
else
begin
{To read(ln) an enum we need a an extra parameter.}
if para.left.resultdef.typ=enumdef then
begin
{Insert a reference to the string2ord index.}
indexpara:=Ccallparanode.create(Caddrnode.create_internal(
Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_str2ord)
),nil);
{Insert a type conversion to to convert the enum to longint.}
para.left:=Ctypeconvnode.create_internal(para.left,s32inttype);
typecheckpass(para.left);
end;
{ special handling of reading small numbers, because the helpers }
{ expect a longint/card/bestreal var parameter. Use a temp. can't }
{ use functions because then the call to FPC_IOCHECK destroys }
{ their result before we can store it }
if (readfunctype<>nil) and (para.left.resultdef<>readfunctype) then
special_handling:=true;
end;
if special_handling then
begin
{ since we're not going to pass the parameter as var-parameter }
{ to the read function, manually check whether the parameter }
{ can be used as var-parameter (e.g., whether it isn't a }
{ property) }
valid_for_var(para.left,true);
{ create the parameter list: the temp ... }
temp := ctempcreatenode.create(readfunctype,readfunctype.size,tt_persistent,false);
addstatement(Tstatementnode(newstatement),temp);
{ ... and the file }
p1 := ccallparanode.create(ctemprefnode.create(temp),
filepara.getcopy);
Tcallparanode(Tcallparanode(p1).right).right:=indexpara;
{ create the call to the helper }
addstatement(Tstatementnode(newstatement),
ccallnode.createintern(name,tcallparanode(p1)));
{ assign the result to the original var (this automatically }
{ takes care of range checking) }
addstatement(Tstatementnode(newstatement),
cassignmentnode.create(para.left,
ctemprefnode.create(temp)));
{ release the temp location }
addstatement(Tstatementnode(newstatement),ctempdeletenode.create(temp));
{ statement of para is used }
para.left := nil;
{ free the enclosing tcallparanode, but not the }
{ parameters coming after it }
para.right := nil;
para.free;
end
else
{ read of non s/u-8/16bit, or a write }
begin
{ add the filepara to the current parameter }
para.right := filepara.getcopy;
{Add the lenpara and the indexpara(s) (fracpara and realtype are
already linked with the lenpara if necessary).}
if indexpara=nil then
Tcallparanode(para.right).right:=lenpara
else
begin
if lenpara=nil then
Tcallparanode(para.right).right:=indexpara
else
begin
Tcallparanode(para.right).right:=lenpara;
lenpara.right:=indexpara;
end;
{ indexpara.right:=lenpara;}
end;
{ in case of writing a chararray, add whether it's }
{ zero-based }
if para.left.resultdef.typ=arraydef then
para := ccallparanode.create(cordconstnode.create(
ord(tarraydef(para.left.resultdef).lowrange=0),pasbool8type,false),para);
{ create the call statement }
addstatement(Tstatementnode(newstatement),
ccallnode.createintern(name,para));
end
end
else
{ error_para = true }
begin
{ free the parameter, since it isn't referenced anywhere anymore }
para.right := nil;
para.free;
if assigned(lenpara) then
begin
lenpara.right := nil;
lenpara.free;
end;
if assigned(fracpara) then
begin
fracpara.right := nil;
fracpara.free;
end;
end;
{ process next parameter }
para := nextpara;
end;
{ if no error, add the write(ln)/read(ln) end calls }
if not found_error then
begin
case inlinenumber of
in_read_x,
in_readstr_x:
name:='fpc_read_end';
in_write_x,
in_writestr_x:
name:='fpc_write_end';
in_readln_x:
begin
name:='fpc_readln_end';
if m_iso in current_settings.modeswitches then
name:=name+'_iso';
end;
in_writeln_x:
name:='fpc_writeln_end';
end;
addstatement(Tstatementnode(newstatement),ccallnode.createintern(name,filepara));
end;
handle_text_read_write:=found_error;
end;
function Tinlinenode.handle_typed_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
{Read/write for typed files.}
const procprefixes:array[boolean] of string[15]=('fpc_typed_write','fpc_typed_read');
procnamesdisplay:array[boolean,boolean] of string[8] = (('Write','Read'),('WriteStr','ReadStr'));
var found_error,do_read,is_rwstr:boolean;
para,nextpara:Tcallparanode;
p1:Tnode;
temp:Ttempcreatenode;
begin
found_error:=false;
para:=Tcallparanode(params);
do_read:=inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
is_rwstr := inlinenumber in [in_readstr_x,in_writestr_x];
{ add the typesize to the filepara }
if filepara.resultdef.typ=filedef then
filepara.right := ccallparanode.create(cordconstnode.create(
tfiledef(filepara.resultdef).typedfiledef.size,s32inttype,true),nil);
{ check for "no parameters" (you need at least one extra para for typed files) }
if not assigned(para) then
begin
CGMessage1(parser_e_wrong_parameter_size,procnamesdisplay[is_rwstr,do_read]);
found_error := true;
end;
{ process all parameters }
while assigned(para) do
begin
{ check if valid parameter }
if para.left.nodetype=typen then
begin
CGMessagePos(para.left.fileinfo,type_e_cant_read_write_type);
found_error := true;
end;
{ support writeln(procvar) }
if (para.left.resultdef.typ=procvardef) then
begin
p1:=ccallnode.create_procvar(nil,para.left);
typecheckpass(p1);
para.left:=p1;
end;
if filepara.resultdef.typ=filedef then
inserttypeconv(para.left,tfiledef(filepara.resultdef).typedfiledef);
if assigned(para.right) and
(cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
begin
CGMessagePos(para.right.fileinfo,parser_e_illegal_colon_qualifier);
{ skip all colon para's }
nextpara := tcallparanode(tcallparanode(para.right).right);
while assigned(nextpara) and (cpf_is_colon_para in nextpara.callparaflags) do
nextpara := tcallparanode(nextpara.right);
found_error := true;
end
else
{ get next parameter }
nextpara := tcallparanode(para.right);
{ When we have a call, we have a problem: you can't pass the }
{ result of a call as a formal const parameter. Solution: }
{ assign the result to a temp and pass this temp as parameter }
{ This is not very efficient, but write(typedfile,x) is }
{ already slow by itself anyway (no buffering) (JM) }
{ Actually, thge same goes for every non-simple expression }
{ (such as an addition, ...) -> put everything but load nodes }
{ into temps (JM) }
{ of course, this must only be allowed for writes!!! (JM) }
if not(do_read) and (para.left.nodetype <> loadn) then
begin
{ create temp for result }
temp := ctempcreatenode.create(para.left.resultdef,
para.left.resultdef.size,tt_persistent,false);
addstatement(Tstatementnode(newstatement),temp);
{ assign result to temp }
addstatement(Tstatementnode(newstatement),
cassignmentnode.create(ctemprefnode.create(temp),
para.left));
{ replace (reused) paranode with temp }
para.left := ctemprefnode.create(temp);
end;
{ add fileparameter }
para.right := filepara.getcopy;
{ create call statment }
{ since the parameters are in the correct order, we have to insert }
{ the statements always at the end of the current block }
addstatement(Tstatementnode(newstatement),
Ccallnode.createintern(procprefixes[do_read],para
));
{ if we used a temp, free it }
if para.left.nodetype = temprefn then
addstatement(Tstatementnode(newstatement),ctempdeletenode.create(temp));
{ process next parameter }
para := nextpara;
end;
{ free the file parameter }
filepara.free;
handle_typed_read_write:=found_error;
end;
function tinlinenode.handle_read_write: tnode;
var
filepara,
nextpara,
params : tcallparanode;
newstatement : tstatementnode;
newblock : tblocknode;
filetemp : Ttempcreatenode;
name : string[31];
textsym : ttypesym;
is_typed,
do_read,
is_rwstr,
found_error : boolean;
begin
filepara := nil;
is_typed := false;
filetemp := nil;
do_read := inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
is_rwstr := inlinenumber in [in_readstr_x,in_writestr_x];
{ if we fail, we can quickly exit this way. We must generate something }
{ instead of the inline node, because firstpass will bomb with an }
{ internalerror if it encounters a read/write }
result := cerrornode.create;
{ reverse the parameters (needed to get the colon parameters in the }
{ correct order when processing write(ln) }
left := reverseparameters(tcallparanode(left));
if is_rwstr then
begin
filepara := tcallparanode(left);
{ needs at least two parameters: source/dest string + min. 1 value }
if not(assigned(filepara)) or
not(assigned(filepara.right)) then
begin
CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'ReadStr/WriteStr');
exit;
end
else if (filepara.resultdef.typ <> stringdef) then
begin
{ convert chararray to string, or give an appropriate error message }
{ (if you want to optimize to use shortstring, keep in mind that }
{ readstr internally always uses ansistring, and to account for }
{ chararrays with > 255 characters) }
inserttypeconv(filepara.left,cansistringtype);
filepara.resultdef:=filepara.left.resultdef;
if codegenerror then
exit;
end
end
else if assigned(left) then
begin
{ check if we have a file parameter and if yes, what kind it is }
filepara := tcallparanode(left);
if (filepara.resultdef.typ=filedef) then
begin
if (tfiledef(filepara.resultdef).filetyp=ft_untyped) then
begin
CGMessagePos(fileinfo,type_e_no_read_write_for_untyped_file);
exit;
end
else
begin
if (tfiledef(filepara.resultdef).filetyp=ft_typed) then
begin
if (inlinenumber in [in_readln_x,in_writeln_x]) then
begin
CGMessagePos(fileinfo,type_e_no_readln_writeln_for_typed_file);
exit;
end;
is_typed := true;
end
end;
end
else
filepara := nil;
end;
{ create a blocknode in which the successive write/read statements will be }
{ put, since they belong together. Also create a dummy statement already to }
{ make inserting of additional statements easier }
newblock:=internalstatements(newstatement);
{ if we don't have a filepara, create one containing the default }
if not assigned(filepara) or
is_rwstr then
begin
{ since the input/output variables are threadvars loading them into
a temp once is faster. Create a temp which will hold a pointer to the file }
filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
addstatement(newstatement,filetemp);
{ make sure the resultdef of the temp (and as such of the }
{ temprefs coming after it) is set (necessary because the }
{ temprefs will be part of the filepara, of which we need }
{ the resultdef later on and temprefs can only be }
{ typecheckpassed if the resultdef of the temp is known) }
typecheckpass(tnode(filetemp));
if not is_rwstr then
begin
{ assign the address of the file to the temp }
if do_read then
name := 'input'
else
name := 'output';
addstatement(newstatement,
cassignmentnode.create(ctemprefnode.create(filetemp),
ccallnode.createintern('fpc_get_'+name,nil)));
end
else
begin
if (do_read) then
name := 'fpc_setupreadstr_'
else
name := 'fpc_setupwritestr_';
name:=name+tstringdef(filepara.resultdef).stringtypname;
{ remove the source/destination string parameter from the }
{ parameter chain }
left:=filepara.right;
filepara.right:=nil;
{ pass the source/destination string to the setup routine, which }
{ will store the string's address in the returned textrec }
addstatement(newstatement,
cassignmentnode.create(ctemprefnode.create(filetemp),
ccallnode.createintern(name,filepara)));
end;
{ create a new fileparameter as follows: file_type(temp^) }
{ (so that we pass the value and not the address of the temp }
{ to the read/write routine) }
textsym:=search_system_type('TEXT');
filepara := ccallparanode.create(ctypeconvnode.create_internal(
cderefnode.create(ctemprefnode.create(filetemp)),textsym.typedef),nil);
end
else
{ remove filepara from the parameter chain }
begin
left := filepara.right;
filepara.right := nil;
{ the file para is a var parameter, but it must be valid already }
set_varstate(filepara.left,vs_readwritten,[vsf_must_be_valid]);
{ check if we should make a temp to store the result of a complex }
{ expression (better heuristics, anyone?) (JM) }
if (filepara.left.nodetype <> loadn) then
begin
{ create a temp which will hold a pointer to the file }
filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
{ add it to the statements }
addstatement(newstatement,filetemp);
{ make sure the resultdef of the temp (and as such of the }
{ temprefs coming after it) is set (necessary because the }
{ temprefs will be part of the filepara, of which we need }
{ the resultdef later on and temprefs can only be }
{ typecheckpassed if the resultdef of the temp is known) }
typecheckpass(tnode(filetemp));
{ assign the address of the file to the temp }
addstatement(newstatement,
cassignmentnode.create(ctemprefnode.create(filetemp),
caddrnode.create_internal(filepara.left)));
typecheckpass(newstatement.left);
{ create a new fileparameter as follows: file_type(temp^) }
{ (so that we pass the value and not the address of the temp }
{ to the read/write routine) }
nextpara := ccallparanode.create(ctypeconvnode.create_internal(
cderefnode.create(ctemprefnode.create(filetemp)),filepara.left.resultdef),nil);
{ replace the old file para with the new one }
filepara.left := nil;
filepara.free;
filepara := nextpara;
end;
end;
{ the resultdef of the filepara must be set since it's }
{ used below }
filepara.get_paratype;
{ now, filepara is nowhere referenced anymore, so we can safely dispose it }
{ if something goes wrong or at the end of the procedure }
{ we're going to reuse the paranodes, so make sure they don't get freed }
{ twice }
params:=Tcallparanode(left);
left := nil;
if is_typed then
found_error:=handle_typed_read_write(filepara,Ttertiarynode(params),tnode(newstatement))
else
found_error:=handle_text_read_write(filepara,Ttertiarynode(params),tnode(newstatement));
{ if we found an error, simply delete the generated blocknode }
if found_error then
newblock.free
else
begin
{ deallocate the temp for the file para if we used one }
if assigned(filetemp) then
addstatement(newstatement,ctempdeletenode.create(filetemp));
{ otherwise return the newly generated block of instructions, }
{ but first free the errornode we generated at the beginning }
result.free;
result := newblock
end;
end;
function tinlinenode.handle_val: tnode;
var
procname,
suffix : string[31];
sourcepara,
destpara,
codepara,
sizepara,
newparas : tcallparanode;
orgcode,tc : tnode;
newstatement : tstatementnode;
newblock : tblocknode;
tempcode : ttempcreatenode;
begin
{ for easy exiting if something goes wrong }
result := cerrornode.create;
{ check the amount of parameters }
if not(assigned(left)) or
not(assigned(tcallparanode(left).right)) then
begin
CGMessage1(parser_e_wrong_parameter_size,'Val');
exit;
end;
{ in case we are in a generic definition, we cannot
do all checks, the parameters might be type parameters }
if df_generic in current_procinfo.procdef.defoptions then
begin
result.Free;
result:=nil;
resultdef:=voidtype;
exit;
end;
{ reverse parameters for easier processing }
left := reverseparameters(tcallparanode(left));
{ get the parameters }
tempcode := nil;
orgcode := nil;
sizepara := nil;
sourcepara := tcallparanode(left);
destpara := tcallparanode(sourcepara.right);
codepara := tcallparanode(destpara.right);
{ check if codepara is valid }
if assigned(codepara) and
(
not is_integer(codepara.resultdef)
{$ifndef cpu64bitaddr}
or is_64bitint(codepara.resultdef)
{$endif not cpu64bitaddr}
) then
begin
CGMessagePos1(codepara.fileinfo,type_e_integer_expr_expected,codepara.resultdef.typename);
exit;
end;
{ check if dest para is valid }
if not is_integer(destpara.resultdef) and
not is_currency(destpara.resultdef) and
not(destpara.resultdef.typ in [floatdef,enumdef]) then
begin
CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected);
exit;
end;
{ we're going to reuse the exisiting para's, so make sure they }
{ won't be disposed }
left := nil;
{ create the blocknode which will hold the generated statements + }
{ an initial dummy statement }
newblock:=internalstatements(newstatement);
{ do we need a temp for code? Yes, if no code specified, or if }
{ code is not a 32bit parameter (we already checked whether the }
{ the code para, if specified, was an orddef) }
if not assigned(codepara) or
(codepara.resultdef.size<>sinttype.size) then
begin
tempcode := ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
addstatement(newstatement,tempcode);
{ set the resultdef of the temp (needed to be able to get }
{ the resultdef of the tempref used in the new code para) }
typecheckpass(tnode(tempcode));
{ create a temp codepara, but save the original code para to }
{ assign the result to later on }
if assigned(codepara) then
begin
orgcode := codepara.left;
codepara.left := ctemprefnode.create(tempcode);
end
else
codepara := ccallparanode.create(ctemprefnode.create(tempcode),nil);
{ we need its resultdef later on }
codepara.get_paratype;
end
else if (torddef(codepara.resultdef).ordtype = torddef(sinttype).ordtype) then
{ because code is a var parameter, it must match types exactly }
{ however, since it will return values in [0..255], both longints }
{ and cardinals are fine. Since the formal code para type is }
{ longint, insert a typecoversion to longint for cardinal para's }
begin
codepara.left := ctypeconvnode.create_internal(codepara.left,sinttype);
{ make it explicit, oterwise you may get a nonsense range }
{ check error if the cardinal already contained a value }
{ > $7fffffff }
codepara.get_paratype;
end;
{ create the procedure name }
procname := 'fpc_val_';
case destpara.resultdef.typ of
orddef:
begin
case torddef(destpara.resultdef).ordtype of
{$ifdef cpu64bitaddr}
s64bit,
{$endif cpu64bitaddr}
s8bit,
s16bit,
s32bit:
begin
suffix := 'sint_';
{ we also need a destsize para in this case }
sizepara := ccallparanode.create(cordconstnode.create
(destpara.resultdef.size,s32inttype,true),nil);
end;
{$ifdef cpu64bitaddr}
u64bit,
{$endif cpu64bitaddr}
u8bit,
u16bit,
u32bit:
suffix := 'uint_';
{$ifndef cpu64bitaddr}
s64bit: suffix := 'int64_';
u64bit: suffix := 'qword_';
{$endif not cpu64bitaddr}
scurrency: suffix := 'currency_';
else
internalerror(200304225);
end;
end;
floatdef:
suffix:='real_';
enumdef:
begin
suffix:='enum_';
sizepara:=Ccallparanode.create(Caddrnode.create_internal(
Crttinode.create(Tenumdef(destpara.resultdef),fullrtti,rdt_str2ord)
),nil);
end;
end;
procname := procname + suffix;
{ play a trick to have tcallnode handle invalid source parameters: }
{ the shortstring-longint val routine by default }
if (sourcepara.resultdef.typ = stringdef) then
procname := procname + tstringdef(sourcepara.resultdef).stringtypname
{ zero-based arrays (of char) can be implicitely converted to ansistring }
else if is_zero_based_array(sourcepara.resultdef) then
procname := procname + 'ansistr'
else
procname := procname + 'shortstr';
{ set up the correct parameters for the call: the code para... }
newparas := codepara;
{ and the source para }
codepara.right := sourcepara;
{ sizepara either contains nil if none is needed (which is ok, since }
{ then the next statement severes any possible links with other paras }
{ that sourcepara may have) or it contains the necessary size para and }
{ its right field is nil }
sourcepara.right := sizepara;
{ create the call and assign the result to dest (val helpers are functions).
Use a trick to prevent a type size mismatch warning to be generated by the
assignment node. First convert implicitly to the resultdef. This will insert
the range check. The Second conversion is done explicitly to hide the implicit conversion
for the assignment node and therefor preventing the warning (PFV)
The implicit conversion is avoided for enums because implicit conversion between
longint (which is what fpc_val_enum_shortstr returns) and enumerations is not
possible. (DM).
The implicit conversion is also avoided for COMP type if it is handled by FPU (x86)
to prevent warning about automatic type conversion. }
if (destpara.resultdef.typ=enumdef) or
((destpara.resultdef.typ=floatdef) and (tfloatdef(destpara.resultdef).floattype=s64comp))
then
tc:=ccallnode.createintern(procname,newparas)
else
tc:=ctypeconvnode.create(ccallnode.createintern(procname,newparas),destpara.left.resultdef);
addstatement(newstatement,cassignmentnode.create(
destpara.left,ctypeconvnode.create_internal(tc,destpara.left.resultdef)));
{ dispose of the enclosing paranode of the destination }
destpara.left := nil;
destpara.right := nil;
destpara.free;
{ check if we used a temp for code and whether we have to store }
{ it to the real code parameter }
if assigned(orgcode) then
addstatement(newstatement,cassignmentnode.create(
orgcode,
ctypeconvnode.create_internal(
ctemprefnode.create(tempcode),orgcode.resultdef)));
{ release the temp if we allocated one }
if assigned(tempcode) then
addstatement(newstatement,ctempdeletenode.create(tempcode));
{ free the errornode }
result.free;
{ and return it }
result := newblock;
end;
{$maxfpuregisters 0}
function getpi : bestreal;
begin
{$ifdef x86}
{ x86 has pi in hardware }
result:=pi;
{$else x86}
{$ifdef cpuextended}
result:=MathPiExtended.Value;
{$else cpuextended}
result:=MathPi.Value;
{$endif cpuextended}
{$endif x86}
end;
function tinlinenode.simplify(forinline : boolean): tnode;
function do_lowhigh(def:tdef) : tnode;
var
v : tconstexprint;
enum : tenumsym;
hp : tnode;
i : integer;
begin
case def.typ of
orddef:
begin
set_varstate(left,vs_read,[]);
if inlinenumber=in_low_x then
v:=torddef(def).low
else
v:=torddef(def).high;
hp:=cordconstnode.create(v,def,true);
typecheckpass(hp);
do_lowhigh:=hp;
end;
enumdef:
begin
set_varstate(left,vs_read,[]);
if inlinenumber=in_high_x then
v:=tenumdef(def).maxval
else
v:=tenumdef(def).minval;
enum:=nil;
for i := 0 to tenumdef(def).symtable.SymList.Count - 1 do
if tenumsym(tenumdef(def).symtable.SymList[i]).value=v then
begin
enum:=tenumsym(tenumdef(def).symtable.SymList[i]);
break;
end;
if not assigned(enum) then
internalerror(309993)
else
hp:=genenumnode(enum);
do_lowhigh:=hp;
end;
else
internalerror(87);
end;
end;
function getconstrealvalue : bestreal;
begin
case left.nodetype of
ordconstn:
getconstrealvalue:=tordconstnode(left).value;
realconstn:
getconstrealvalue:=trealconstnode(left).value_real;
else
internalerror(309992);
end;
end;
procedure setconstrealvalue(r : bestreal);
begin
result:=crealconstnode.create(r,pbestrealtype^);
end;
function handle_ln_const(r : bestreal) : tnode;
begin
if r<=0.0 then
if floating_point_range_check_error then
begin
result:=crealconstnode.create(0,pbestrealtype^);
CGMessage(type_e_wrong_math_argument)
end
else
begin
if r=0.0 then
result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
else
result:=crealconstnode.create(MathNegInf.Value,pbestrealtype^)
end
else
result:=crealconstnode.create(ln(r),pbestrealtype^)
end;
function handle_sqrt_const(r : bestreal) : tnode;
begin
if r<0.0 then
if floating_point_range_check_error then
begin
result:=crealconstnode.create(0,pbestrealtype^);
CGMessage(type_e_wrong_math_argument)
end
else
result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
else
result:=crealconstnode.create(sqrt(r),pbestrealtype^)
end;
function handle_const_sar : tnode;
var
vl,vl2 : TConstExprInt;
bits,shift: integer;
mask : qword;
def : tdef;
begin
result:=nil;
if (left.nodetype=ordconstn) or ((left.nodetype=callparan) and (tcallparanode(left).left.nodetype=ordconstn)) then
begin
if (left.nodetype=callparan) and
assigned(tcallparanode(left).right) then
begin
if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
begin
def:=tcallparanode(tcallparanode(left).right).left.resultdef;
vl:=tordconstnode(tcallparanode(left).left).value;
vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
end
else
exit;
end
else
begin
def:=left.resultdef;
vl:=1;
vl2:=tordconstnode(left).value;
end;
bits:=def.size*8;
shift:=vl.svalue and (bits-1);
case bits of
8:
mask:=$ff;
16:
mask:=$ffff;
32:
mask:=$ffffffff;
64:
mask:=qword($ffffffffffffffff);
else
mask:=qword(1 shl bits)-1;
end;
{$push}
{$r-,q-}
if shift=0 then
result:=cordconstnode.create(vl2.svalue,def,false)
else if vl2.svalue<0 then
result:=cordconstnode.create(((vl2.svalue shr shift) or (mask shl (bits-shift))) and mask,def,false)
else
result:=cordconstnode.create((vl2.svalue shr shift) and mask,def,false);
{$pop}
end
else
end;
function handle_const_rox : tnode;
var
vl,vl2 : TConstExprInt;
bits,shift: integer;
def : tdef;
begin
result:=nil;
if (left.nodetype=ordconstn) or ((left.nodetype=callparan) and (tcallparanode(left).left.nodetype=ordconstn)) then
begin
if (left.nodetype=callparan) and
assigned(tcallparanode(left).right) then
begin
if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
begin
def:=tcallparanode(tcallparanode(left).right).left.resultdef;
vl:=tordconstnode(tcallparanode(left).left).value;
vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
end
else
exit;
end
else
begin
def:=left.resultdef;
vl:=1;
vl2:=tordconstnode(left).value;
end;
bits:=def.size*8;
shift:=vl.svalue and (bits-1);
{$push}
{$r-,q-}
if shift=0 then
result:=cordconstnode.create(vl2.svalue,def,false)
else
case inlinenumber of
in_ror_x,in_ror_x_y:
case def.size of
1:
result:=cordconstnode.create(RorByte(Byte(vl2.svalue),shift),def,false);
2:
result:=cordconstnode.create(RorWord(Word(vl2.svalue),shift),def,false);
4:
result:=cordconstnode.create(RorDWord(DWord(vl2.svalue),shift),def,false);
8:
result:=cordconstnode.create(RorQWord(QWord(vl2.svalue),shift),def,false);
else
internalerror(2011061903);
end;
in_rol_x,in_rol_x_y:
case def.size of
1:
result:=cordconstnode.create(RolByte(Byte(vl2.svalue),shift),def,false);
2:
result:=cordconstnode.create(RolWord(Word(vl2.svalue),shift),def,false);
4:
result:=cordconstnode.create(RolDWord(DWord(vl2.svalue),shift),def,false);
8:
result:=cordconstnode.create(RolQWord(QWord(vl2.svalue),shift),def,false);
else
internalerror(2011061902);
end;
else
internalerror(2011061901);
end;
end;
end;
var
hp : tnode;
vl,vl2 : TConstExprInt;
vr : bestreal;
begin { simplify }
result:=nil;
{ handle intern constant functions in separate case }
if nf_inlineconst in flags then
begin
{ no parameters? }
if not assigned(left) then
internalerror(200501231)
else
begin
vl:=0;
vl2:=0; { second parameter Ex: ptr(vl,vl2) }
case left.nodetype of
realconstn :
begin
{ Real functions are all handled with internproc below }
CGMessage1(type_e_integer_expr_expected,left.resultdef.typename)
end;
ordconstn :
vl:=tordconstnode(left).value;
callparan :
begin
{ both exists, else it was not generated }
vl:=tordconstnode(tcallparanode(left).left).value;
vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
end;
else
CGMessage(parser_e_illegal_expression);
end;
case inlinenumber of
in_const_abs :
if vl.signed then
hp:=create_simplified_ord_const(abs(vl.svalue),resultdef,forinline)
else
hp:=create_simplified_ord_const(vl.uvalue,resultdef,forinline);
in_const_sqr:
if vl.signed then
hp:=create_simplified_ord_const(sqr(vl.svalue),resultdef,forinline)
else
hp:=create_simplified_ord_const(sqr(vl.uvalue),resultdef,forinline);
in_const_odd :
hp:=cordconstnode.create(qword(odd(int64(vl))),pasbool8type,true);
in_const_swap_word :
hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resultdef,true);
in_const_swap_long :
hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resultdef,true);
in_const_swap_qword :
hp:=cordconstnode.create((vl and $ffff) shl 32+(vl shr 32),left.resultdef,true);
in_const_ptr:
begin
{Don't construct pointers from negative values.}
if (vl.signed and (vl.svalue<0)) or (vl2.signed and (vl2.svalue<0)) then
cgmessage(parser_e_range_check_error);
hp:=cpointerconstnode.create((vl2.uvalue shl 4)+vl.uvalue,voidfarpointertype);
end
else
internalerror(88);
end;
end;
if hp=nil then
hp:=cerrornode.create;
result:=hp;
end
else
begin
case inlinenumber of
in_lo_long,
in_hi_long,
in_lo_qword,
in_hi_qword,
in_lo_word,
in_hi_word :
begin
if left.nodetype=ordconstn then
begin
case inlinenumber of
in_lo_word :
result:=cordconstnode.create(tordconstnode(left).value and $ff,u8inttype,true);
in_hi_word :
result:=cordconstnode.create(tordconstnode(left).value shr 8,u8inttype,true);
in_lo_long :
result:=cordconstnode.create(tordconstnode(left).value and $ffff,u16inttype,true);
in_hi_long :
result:=cordconstnode.create(tordconstnode(left).value shr 16,u16inttype,true);
in_lo_qword :
result:=cordconstnode.create(tordconstnode(left).value and $ffffffff,u32inttype,true);
in_hi_qword :
result:=cordconstnode.create(tordconstnode(left).value shr 32,u32inttype,true);
end;
end;
end;
in_ord_x:
begin
case left.resultdef.typ of
orddef :
begin
case torddef(left.resultdef).ordtype of
pasbool8,
uchar:
begin
{ change to byte() }
result:=ctypeconvnode.create_internal(left,u8inttype);
left:=nil;
end;
pasbool16,
uwidechar :
begin
{ change to word() }
result:=ctypeconvnode.create_internal(left,u16inttype);
left:=nil;
end;
pasbool32 :
begin
{ change to dword() }
result:=ctypeconvnode.create_internal(left,u32inttype);
left:=nil;
end;
pasbool64 :
begin
{ change to qword() }
result:=ctypeconvnode.create_internal(left,u64inttype);
left:=nil;
end;
bool8bit:
begin
{ change to shortint() }
result:=ctypeconvnode.create_internal(left,s8inttype);
left:=nil;
end;
bool16bit :
begin
{ change to smallint() }
result:=ctypeconvnode.create_internal(left,s16inttype);
left:=nil;
end;
bool32bit :
begin
{ change to longint() }
result:=ctypeconvnode.create_internal(left,s32inttype);
left:=nil;
end;
bool64bit :
begin
{ change to int64() }
result:=ctypeconvnode.create_internal(left,s64inttype);
left:=nil;
end;
uvoid :
CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
else
begin
{ all other orddef need no transformation }
result:=left;
left:=nil;
end;
end;
end;
enumdef :
begin
result:=ctypeconvnode.create_internal(left,s32inttype);
left:=nil;
end;
pointerdef :
begin
if m_mac in current_settings.modeswitches then
begin
result:=ctypeconvnode.create_internal(left,ptruinttype);
left:=nil;
end
end;
end;
(*
if (left.nodetype=ordconstn) then
begin
result:=cordconstnode.create(
tordconstnode(left).value,sinttype,true);
end
else if (m_mac in current_settings.modeswitches) and
(left.ndoetype=pointerconstn) then
result:=cordconstnode.create(
tpointerconstnode(left).value,ptruinttype,true);
*)
end;
in_chr_byte:
begin
{ convert to explicit char() }
result:=ctypeconvnode.create_internal(left,cchartype);
left:=nil;
end;
in_length_x:
begin
case left.resultdef.typ of
stringdef :
begin
if (left.nodetype=stringconstn) then
begin
result:=cordconstnode.create(
tstringconstnode(left).len,sinttype,true);
end;
end;
orddef :
begin
{ length of char is always one }
if is_char(left.resultdef) or
is_widechar(left.resultdef) then
begin
result:=cordconstnode.create(1,sinttype,false);
end
end;
arraydef :
begin
if (left.nodetype=stringconstn) then
begin
result:=cordconstnode.create(
tstringconstnode(left).len,sinttype,true);
end
else if not is_open_array(left.resultdef) and
not is_array_of_const(left.resultdef) and
not is_dynamic_array(left.resultdef) then
result:=cordconstnode.create(tarraydef(left.resultdef).highrange-
tarraydef(left.resultdef).lowrange+1,
sinttype,true);
end;
end;
end;
in_assigned_x:
begin
if is_constnode(tcallparanode(left).left) or
(tcallparanode(left).left.nodetype = pointerconstn) then
begin
{ let an add node figure it out }
result:=caddnode.create(unequaln,tcallparanode(left).left,cnilnode.create);
tcallparanode(left).left := nil;
end;
end;
in_pred_x,
in_succ_x:
begin
if (left.nodetype=ordconstn) then
begin
if (inlinenumber=in_succ_x) then
vl:=tordconstnode(left).value+1
else
vl:=tordconstnode(left).value-1;
if is_integer(left.resultdef) then
{ the type of the original integer constant is irrelevant,
it should be automatically adapted to the new value
(except when inlining) }
result:=create_simplified_ord_const(vl,resultdef,forinline)
else
{ check the range for enums, chars, booleans }
result:=cordconstnode.create(vl,left.resultdef,true)
end
end;
in_low_x,
in_high_x:
begin
case left.resultdef.typ of
orddef,
enumdef:
begin
result:=do_lowhigh(left.resultdef);
end;
setdef:
begin
result:=do_lowhigh(tsetdef(left.resultdef).elementdef);
end;
arraydef:
begin
if (inlinenumber=in_low_x) then
begin
result:=cordconstnode.create(int64(tarraydef(
left.resultdef).lowrange),tarraydef(left.resultdef).rangedef,true);
end
else if not is_open_array(left.resultdef) and
not is_array_of_const(left.resultdef) and
not is_dynamic_array(left.resultdef) then
result:=cordconstnode.create(int64(tarraydef(left.resultdef).highrange),
tarraydef(left.resultdef).rangedef,true);
end;
stringdef:
begin
if inlinenumber=in_low_x then
begin
result:=cordconstnode.create(0,u8inttype,false);
end
else if not is_ansistring(left.resultdef) and
not is_wide_or_unicode_string(left.resultdef) then
result:=cordconstnode.create(tstringdef(left.resultdef).len,u8inttype,true)
end;
end;
end;
in_exp_real :
begin
if left.nodetype in [ordconstn,realconstn] then
begin
result:=crealconstnode.create(exp(getconstrealvalue),pbestrealtype^);
if (trealconstnode(result).value_real=MathInf.Value) and
floating_point_range_check_error then
begin
result:=crealconstnode.create(0,pbestrealtype^);
CGMessage(parser_e_range_check_error);
end;
end
end;
in_trunc_real :
begin
if left.nodetype in [ordconstn,realconstn] then
begin
vr:=getconstrealvalue;
if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
begin
CGMessage(parser_e_range_check_error);
result:=cordconstnode.create(1,s64inttype,false)
end
else
result:=cordconstnode.create(trunc(vr),s64inttype,true)
end
end;
in_round_real :
begin
{ can't evaluate while inlining, may depend on fpu setting }
if (not forinline) and
(left.nodetype in [ordconstn,realconstn]) then
begin
vr:=getconstrealvalue;
if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
begin
CGMessage(parser_e_range_check_error);
result:=cordconstnode.create(1,s64inttype,false)
end
else
result:=cordconstnode.create(round(vr),s64inttype,true)
end
end;
in_frac_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(frac(getconstrealvalue))
end;
in_int_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(int(getconstrealvalue));
end;
in_pi_real :
begin
if block_type=bt_const then
setconstrealvalue(getpi)
end;
in_cos_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(cos(getconstrealvalue))
end;
in_sin_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(sin(getconstrealvalue))
end;
in_arctan_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(arctan(getconstrealvalue))
end;
in_abs_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(abs(getconstrealvalue))
end;
in_abs_long:
begin
if left.nodetype=ordconstn then
begin
if tordconstnode(left).value<0 then
result:=cordconstnode.create((-tordconstnode(left).value),s32inttype,false)
else
result:=cordconstnode.create((tordconstnode(left).value),s32inttype,false);
end
end;
in_sqr_real :
begin
if left.nodetype in [ordconstn,realconstn] then
setconstrealvalue(sqr(getconstrealvalue))
end;
in_sqrt_real :
begin
if left.nodetype in [ordconstn,realconstn] then
begin
vr:=getconstrealvalue;
if vr<0.0 then
result:=handle_sqrt_const(vr)
else
setconstrealvalue(sqrt(vr));
end
end;
in_ln_real :
begin
if left.nodetype in [ordconstn,realconstn] then
begin
vr:=getconstrealvalue;
if vr<=0.0 then
result:=handle_ln_const(vr)
else
setconstrealvalue(ln(vr));
end
end;
in_assert_x_y :
begin
if not(cs_do_assertion in current_settings.localswitches) then
{ we need a valid node, so insert a nothingn }
result:=cnothingnode.create;
end;
in_sar_x,
in_sar_x_y :
begin
result:=handle_const_sar;
end;
in_rol_x,
in_rol_x_y,
in_ror_x,
in_ror_x_y :
result:=handle_const_rox;
end;
end;
end;
function tinlinenode.pass_typecheck:tnode;
procedure setfloatresultdef;
begin
if (left.resultdef.typ=floatdef) and
(tfloatdef(left.resultdef).floattype in [s32real,s64real,s80real,sc80real,s128real]) then
resultdef:=left.resultdef
else
begin
if (left.nodetype <> ordconstn) then
inserttypeconv(left,pbestrealtype^);
resultdef:=pbestrealtype^;
end;
end;
procedure handle_pack_unpack;
var
source, target, index: tcallparanode;
unpackedarraydef, packedarraydef: tarraydef;
tempindex: TConstExprInt;
begin
resultdef:=voidtype;
unpackedarraydef := nil;
packedarraydef := nil;
source := tcallparanode(left);
if (inlinenumber = in_unpack_x_y_z) then
begin
target := tcallparanode(source.right);
index := tcallparanode(target.right);
{ source must be a packed array }
if not is_packed_array(source.left.resultdef) then
CGMessagePos2(source.left.fileinfo,type_e_got_expected_packed_array,'1',source.left.resultdef.typename)
else
packedarraydef := tarraydef(source.left.resultdef);
{ target can be any kind of array, as long as it's not packed }
if (target.left.resultdef.typ <> arraydef) or
is_packed_array(target.left.resultdef) then
CGMessagePos2(target.left.fileinfo,type_e_got_expected_unpacked_array,'2',target.left.resultdef.typename)
else
unpackedarraydef := tarraydef(target.left.resultdef);
end
else
begin
index := tcallparanode(source.right);
target := tcallparanode(index.right);
{ source can be any kind of array, as long as it's not packed }
if (source.left.resultdef.typ <> arraydef) or
is_packed_array(source.left.resultdef) then
CGMessagePos2(source.left.fileinfo,type_e_got_expected_unpacked_array,'1',source.left.resultdef.typename)
else
unpackedarraydef := tarraydef(source.left.resultdef);
{ target must be a packed array }
if not is_packed_array(target.left.resultdef) then
CGMessagePos2(target.left.fileinfo,type_e_got_expected_packed_array,'3',target.left.resultdef.typename)
else
packedarraydef := tarraydef(target.left.resultdef);
end;
if assigned(unpackedarraydef) then
begin
{ index must be compatible with the unpacked array's indextype }
inserttypeconv(index.left,unpackedarraydef.rangedef);
{ range check at compile time if possible }
if assigned(packedarraydef) and
(index.left.nodetype = ordconstn) and
not is_special_array(unpackedarraydef) then
begin
testrange(unpackedarraydef,tordconstnode(index.left).value,false,false);
tempindex := tordconstnode(index.left).value + packedarraydef.highrange-packedarraydef.lowrange;
testrange(unpackedarraydef,tempindex,false,false);
end;
end;
{ source array is read and must be valid }
set_varstate(source.left,vs_read,[vsf_must_be_valid]);
{ target array is written }
valid_for_assignment(target.left,true);
set_varstate(target.left,vs_written,[]);
{ index in the unpacked array is read and must be valid }
set_varstate(index.left,vs_read,[vsf_must_be_valid]);
{ if the size of the arrays is 0 (array of empty records), }
{ do nothing }
if (source.resultdef.size = 0) then
result:=cnothingnode.create;
end;
function handle_objc_encode: tnode;
var
encodedtype: ansistring;
errordef: tdef;
begin
encodedtype:='';
if not objctryencodetype(left.resultdef,encodedtype,errordef) then
Message1(type_e_objc_type_unsupported,errordef.typename);
result:=cstringconstnode.createpchar(ansistring2pchar(encodedtype),length(encodedtype));
end;
var
hightree,
hp : tnode;
begin
result:=nil;
{ when handling writeln "left" contains no valid address }
if assigned(left) then
begin
if left.nodetype=callparan then
tcallparanode(left).get_paratype
else
typecheckpass(left);
end;
if not(nf_inlineconst in flags) then
begin
case inlinenumber of
in_lo_long,
in_hi_long,
in_lo_qword,
in_hi_qword,
in_lo_word,
in_hi_word :
begin
{ give warning for incompatibility with tp and delphi }
if (inlinenumber in [in_lo_long,in_hi_long,in_lo_qword,in_hi_qword]) and
((m_tp7 in current_settings.modeswitches) or
(m_delphi in current_settings.modeswitches)) then
CGMessage(type_w_maybe_wrong_hi_lo);
set_varstate(left,vs_read,[vsf_must_be_valid]);
if not is_integer(left.resultdef) then
CGMessage1(type_e_integer_expr_expected,left.resultdef.typename);
case inlinenumber of
in_lo_word,
in_hi_word :
resultdef:=u8inttype;
in_lo_long,
in_hi_long :
resultdef:=u16inttype;
in_lo_qword,
in_hi_qword :
resultdef:=u32inttype;
end;
end;
in_sizeof_x:
begin
{ the constant evaluation of in_sizeof_x happens in pexpr where possible }
set_varstate(left,vs_read,[]);
if paramanager.push_high_param(vs_value,left.resultdef,current_procinfo.procdef.proccalloption) then
begin
hightree:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
if assigned(hightree) then
begin
hp:=caddnode.create(addn,hightree,
cordconstnode.create(1,sinttype,false));
if (left.resultdef.typ=arraydef) then
if not is_packed_array(tarraydef(left.resultdef)) then
begin
if (tarraydef(left.resultdef).elesize<>1) then
hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(
left.resultdef).elesize,sinttype,true));
end
else if (tarraydef(left.resultdef).elepackedbitsize <> 8) then
begin
{ no packed open array support yet }
if (hp.nodetype <> ordconstn) then
internalerror(2006081511);
hp.free;
hp := cordconstnode.create(left.resultdef.size,sinttype,true);
{
hp:=
ctypeconvnode.create_explicit(sinttype,
cmoddivnode.create(divn,
caddnode.create(addn,
caddnode.create(muln,hp,cordconstnode.create(tarraydef(
left.resultdef).elepackedbitsize,s64inttype,true)),
cordconstnode.create(a,s64inttype,true)),
cordconstnode.create(8,s64inttype,true)),
sinttype);
}
end;
result:=hp;
end;
end
else
resultdef:=sinttype;
end;
in_typeof_x:
begin
set_varstate(left,vs_read,[]);
resultdef:=voidpointertype;
end;
in_ord_x:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
case left.resultdef.typ of
orddef,
enumdef :
;
pointerdef :
begin
if not(m_mac in current_settings.modeswitches) then
CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
end
else
CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
end;
end;
in_chr_byte:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
end;
in_length_x:
begin
if ((left.resultdef.typ=arraydef) and
(not is_special_array(left.resultdef) or
is_open_array(left.resultdef))) or
(left.resultdef.typ=orddef) then
set_varstate(left,vs_read,[])
else
set_varstate(left,vs_read,[vsf_must_be_valid]);
case left.resultdef.typ of
variantdef:
begin
inserttypeconv(left,cansistringtype);
end;
stringdef :
begin
{ we don't need string convertions here, }
{ except if from widestring to ansistring }
{ and vice versa (that can change the }
{ length) }
if (left.nodetype=typeconvn) and
(ttypeconvnode(left).left.resultdef.typ=stringdef) and
not(is_wide_or_unicode_string(left.resultdef) xor
is_wide_or_unicode_string(ttypeconvnode(left).left.resultdef)) then
begin
hp:=ttypeconvnode(left).left;
ttypeconvnode(left).left:=nil;
left.free;
left:=hp;
end;
end;
orddef :
begin
{ will be handled in simplify }
if not is_char(left.resultdef) and
not is_widechar(left.resultdef) then
CGMessage(type_e_mismatch);
end;
pointerdef :
begin
if is_pchar(left.resultdef) then
begin
hp := ccallparanode.create(left,nil);
result := ccallnode.createintern('fpc_pchar_length',hp);
{ make sure the left node doesn't get disposed, since it's }
{ reused in the new node (JM) }
left:=nil;
exit;
end
else if is_pwidechar(left.resultdef) then
begin
hp := ccallparanode.create(left,nil);
result := ccallnode.createintern('fpc_pwidechar_length',hp);
{ make sure the left node doesn't get disposed, since it's }
{ reused in the new node (JM) }
left:=nil;
exit;
end
else
CGMessage(type_e_mismatch);
end;
arraydef :
begin
if is_open_array(left.resultdef) or
is_array_of_const(left.resultdef) then
begin
hightree:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
if assigned(hightree) then
result:=caddnode.create(addn,hightree,
cordconstnode.create(1,sinttype,false));
exit;
end
else if is_dynamic_array(left.resultdef) then
begin
hp := ccallparanode.create(ctypeconvnode.create_internal(left,voidpointertype),nil);
result := ccallnode.createintern('fpc_dynarray_length',hp);
{ make sure the left node doesn't get disposed, since it's }
{ reused in the new node (JM) }
left:=nil;
exit;
end
else
begin
{ will be handled in simplify }
end;
end
else
CGMessage(type_e_mismatch);
end;
{ shortstring return an 8 bit value as the length
is the first byte of the string }
if is_shortstring(left.resultdef) then
resultdef:=u8inttype
else
resultdef:=sinttype;
end;
in_typeinfo_x:
begin
if (left.resultdef.typ=enumdef) and
(tenumdef(left.resultdef).has_jumps) then
CGMessage(type_e_no_type_info);
set_varstate(left,vs_read,[vsf_must_be_valid]);
resultdef:=voidpointertype;
end;
in_assigned_x:
begin
{ the parser has already made sure the expression is valid }
{ in case of a complex procvar, only check the "code" pointer }
if (tcallparanode(left).left.resultdef.typ=procvardef) and
not tprocvardef(tcallparanode(left).left.resultdef).is_addressonly then
begin
inserttypeconv_explicit(tcallparanode(left).left,search_system_type('TMETHOD').typedef);
tcallparanode(left).left:=csubscriptnode.create(tsym(tabstractrecorddef(tcallparanode(left).left.resultdef).symtable.find('CODE')),tcallparanode(left).left);
tcallparanode(left).get_paratype;
end;
{ converting to an add node is tricky because of differences
in procvar handling between FPC and Delphi handling, so
handle specially }
set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
resultdef:=pasbool8type;
end;
in_ofs_x :
internalerror(2000101001);
in_seg_x :
begin
set_varstate(left,vs_read,[]);
result:=cordconstnode.create(0,s32inttype,false);
end;
in_pred_x,
in_succ_x:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
resultdef:=left.resultdef;
if not is_ordinal(resultdef) then
CGMessage(type_e_ordinal_expr_expected)
else
begin
if (resultdef.typ=enumdef) and
(tenumdef(resultdef).has_jumps) and
not(m_delphi in current_settings.modeswitches) then
CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
end;
end;
in_initialize_x,
in_finalize_x,
in_setlength_x:
begin
{ inlined from pinline }
internalerror(200204231);
end;
in_inc_x,
in_dec_x:
begin
resultdef:=voidtype;
if assigned(left) then
begin
{ first param must be var }
valid_for_var(tcallparanode(left).left,true);
set_varstate(tcallparanode(left).left,vs_readwritten,[vsf_must_be_valid]);
if (left.resultdef.typ in [enumdef,pointerdef]) or
is_ordinal(left.resultdef) or
is_currency(left.resultdef) then
begin
{ value of left gets changed -> must be unique }
set_unique(tcallparanode(left).left);
{ two paras ? }
if assigned(tcallparanode(left).right) then
begin
if is_integer(tcallparanode(left).right.resultdef) then
begin
set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
{ when range/overflow checking is on, we
convert this to a regular add, and for proper
checking we need the original type }
if ([cs_check_range,cs_check_overflow]*current_settings.localswitches=[]) then
if (tcallparanode(left).left.resultdef.typ=pointerdef) then
begin
{ don't convert values added to pointers into the pointer types themselves,
because that will turn signed values into unsigned ones, which then
goes wrong when they have to be multiplied with the size of the elements
to which the pointer points in ncginl (mantis #17342) }
if is_signed(tcallparanode(tcallparanode(left).right).left.resultdef) then
inserttypeconv(tcallparanode(tcallparanode(left).right).left,ptrsinttype)
else
inserttypeconv(tcallparanode(tcallparanode(left).right).left,ptruinttype)
end
else if is_integer(tcallparanode(left).left.resultdef) then
inserttypeconv(tcallparanode(tcallparanode(left).right).left,tcallparanode(left).left.resultdef)
else
inserttypeconv_internal(tcallparanode(tcallparanode(left).right).left,tcallparanode(left).left.resultdef);
if assigned(tcallparanode(tcallparanode(left).right).right) then
{ should be handled in the parser (JM) }
internalerror(2006020901);
end
else
CGMessagePos(tcallparanode(left).right.fileinfo,type_e_ordinal_expr_expected);
end;
end
else
begin
hp:=self;
if isunaryoverloaded(hp) then
begin
{ inc(rec) and dec(rec) assigns result value to argument }
result:=cassignmentnode.create(tcallparanode(left).left.getcopy,hp);
exit;
end
else
CGMessagePos(left.fileinfo,type_e_ordinal_expr_expected);
end;
end
else
CGMessagePos(fileinfo,type_e_mismatch);
end;
in_read_x,
in_readln_x,
in_readstr_x,
in_write_x,
in_writeln_x,
in_writestr_x :
begin
result := handle_read_write;
end;
in_settextbuf_file_x :
begin
resultdef:=voidtype;
{ now we know the type of buffer }
hp:=ccallparanode.create(cordconstnode.create(
tcallparanode(left).left.resultdef.size,s32inttype,true),left);
result:=ccallnode.createintern('SETTEXTBUF',hp);
left:=nil;
end;
{ the firstpass of the arg has been done in firstcalln ? }
in_reset_typedfile,
in_rewrite_typedfile :
begin
result := handle_reset_rewrite_typed;
end;
in_str_x_string :
begin
result:=handle_str;
end;
in_val_x :
begin
result:=handle_val;
end;
in_include_x_y,
in_exclude_x_y:
begin
resultdef:=voidtype;
{ the parser already checks whether we have two (and exactly two) }
{ parameters (JM) }
{ first param must be var }
valid_for_var(tcallparanode(left).left,true);
set_varstate(tcallparanode(left).left,vs_readwritten,[vsf_must_be_valid]);
{ check type }
if (left.resultdef.typ=setdef) then
begin
{ insert a type conversion }
{ to the type of the set elements }
set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
inserttypeconv(tcallparanode(tcallparanode(left).right).left,
tsetdef(left.resultdef).elementdef);
end
else
CGMessage(type_e_mismatch);
end;
in_pack_x_y_z,
in_unpack_x_y_z :
begin
handle_pack_unpack;
end;
in_slice_x:
begin
result:=nil;
resultdef:=tcallparanode(left).left.resultdef;
if (resultdef.typ <> arraydef) then
CGMessagePos(left.fileinfo,type_e_mismatch)
else if is_packed_array(resultdef) then
CGMessagePos2(left.fileinfo,type_e_got_expected_unpacked_array,'1',resultdef.typename);
if not(is_integer(tcallparanode(tcallparanode(left).right).left.resultdef)) then
CGMessagePos1(tcallparanode(left).right.fileinfo,
type_e_integer_expr_expected,
tcallparanode(tcallparanode(left).right).left.resultdef.typename);
end;
in_low_x,
in_high_x:
begin
case left.resultdef.typ of
orddef,
enumdef,
setdef:
;
arraydef:
begin
if (inlinenumber=in_low_x) then
set_varstate(left,vs_read,[])
else
begin
if is_open_array(left.resultdef) or
is_array_of_const(left.resultdef) then
begin
set_varstate(left,vs_read,[]);
result:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
end
else
if is_dynamic_array(left.resultdef) then
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
{ can't use inserttypeconv because we need }
{ an explicit type conversion (JM) }
hp := ccallparanode.create(ctypeconvnode.create_internal(left,voidpointertype),nil);
result := ccallnode.createintern('fpc_dynarray_high',hp);
{ make sure the left node doesn't get disposed, since it's }
{ reused in the new node (JM) }
left:=nil;
end
else
begin
set_varstate(left,vs_read,[]);
end;
end;
end;
stringdef:
begin
if inlinenumber=in_low_x then
begin
set_varstate(left,vs_read,[]);
end
else
begin
if is_open_string(left.resultdef) then
begin
set_varstate(left,vs_read,[]);
result:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry))
end
else if is_ansistring(left.resultdef) or
is_wide_or_unicode_string(left.resultdef) then
CGMessage(type_e_mismatch)
end;
end;
else
CGMessage(type_e_mismatch);
end;
end;
in_exp_real,
in_frac_real,
in_int_real,
in_cos_real,
in_sin_real,
in_arctan_real,
in_abs_real,
in_ln_real :
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
{ converting an int64 to double on platforms without }
{ extended can cause precision loss }
if not(left.nodetype in [ordconstn,realconstn]) then
inserttypeconv(left,pbestrealtype^);
resultdef:=pbestrealtype^;
end;
in_trunc_real,
in_round_real :
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
{ for direct float rounding, no best real type cast should be necessary }
if not((left.resultdef.typ=floatdef) and
(tfloatdef(left.resultdef).floattype in [s32real,s64real,s80real,sc80real,s128real])) and
{ converting an int64 to double on platforms without }
{ extended can cause precision loss }
not(left.nodetype in [ordconstn,realconstn]) then
inserttypeconv(left,pbestrealtype^);
resultdef:=s64inttype;
end;
in_pi_real :
begin
resultdef:=pbestrealtype^;
end;
in_abs_long:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
inserttypeconv(left,s32inttype);
resultdef:=s32inttype;
end;
in_sqr_real,
in_sqrt_real :
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
setfloatresultdef;
end;
{$ifdef SUPPORT_MMX}
in_mmx_pcmpeqb..in_mmx_pcmpgtw:
begin
end;
{$endif SUPPORT_MMX}
in_unaligned_x:
begin
resultdef:=left.resultdef;
end;
in_assert_x_y :
begin
resultdef:=voidtype;
if assigned(left) then
begin
set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
{ check type }
if is_boolean(left.resultdef) then
begin
set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
{ must always be a string }
inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
end
else
CGMessage1(type_e_boolean_expr_expected,left.resultdef.typename);
end
else
CGMessage(type_e_mismatch);
if (cs_do_assertion in current_settings.localswitches) then
include(current_procinfo.flags,pi_do_call);
end;
in_prefetch_var:
resultdef:=voidtype;
in_get_frame,
in_get_caller_frame,
in_get_caller_addr:
begin
resultdef:=voidpointertype;
end;
in_rol_x,
in_ror_x,
in_sar_x:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
resultdef:=left.resultdef;
end;
in_rol_x_y,
in_ror_x_y,
in_sar_x_y:
begin
set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
resultdef:=tcallparanode(tcallparanode(left).right).left.resultdef;
end;
in_bsf_x,
in_bsr_x:
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
if not is_integer(left.resultdef) then
CGMessage1(type_e_integer_expr_expected,left.resultdef.typename);
if torddef(left.resultdef).ordtype in [u64bit, s64bit] then
resultdef:=u64inttype
else
resultdef:=u32inttype
end;
in_objc_selector_x:
begin
result:=cobjcselectornode.create(left);
{ reused }
left:=nil;
end;
in_objc_protocol_x:
begin
result:=cobjcprotocolnode.create(left);
{ reused }
left:=nil;
end;
in_objc_encode_x:
begin
result:=handle_objc_encode;
end;
else
internalerror(8);
end;
end;
if not assigned(result) and not
codegenerror then
result:=simplify(false);
end;
function tinlinenode.pass_1 : tnode;
var
hp,hpp,resultnode : tnode;
shiftconst: longint;
tempnode: ttempcreatenode;
newstatement: tstatementnode;
newblock: tblocknode;
begin
result:=nil;
{ if we handle writeln; left contains no valid address }
if assigned(left) then
begin
if left.nodetype=callparan then
tcallparanode(left).firstcallparan
else
firstpass(left);
end;
{ intern const should already be handled }
if nf_inlineconst in flags then
internalerror(200104044);
case inlinenumber of
in_lo_qword,
in_hi_qword,
in_lo_long,
in_hi_long,
in_lo_word,
in_hi_word:
begin
shiftconst := 0;
case inlinenumber of
in_hi_qword:
shiftconst := 32;
in_hi_long:
shiftconst := 16;
in_hi_word:
shiftconst := 8;
end;
if shiftconst <> 0 then
result := ctypeconvnode.create_internal(cshlshrnode.create(shrn,left,
cordconstnode.create(shiftconst,u32inttype,false)),resultdef)
else
result := ctypeconvnode.create_internal(left,resultdef);
left := nil;
firstpass(result);
end;
in_sizeof_x:
begin
expectloc:=LOC_REGISTER;
end;
in_typeof_x:
begin
expectloc:=LOC_REGISTER;
end;
in_length_x:
begin
if is_shortstring(left.resultdef) then
expectloc:=left.expectloc
else
begin
{ ansi/wide string }
expectloc:=LOC_REGISTER;
end;
end;
in_typeinfo_x:
begin
expectloc:=LOC_REGISTER;
end;
in_assigned_x:
begin
expectloc := LOC_JUMP;
end;
in_pred_x,
in_succ_x:
begin
expectloc:=LOC_REGISTER;
{ in case of range/overflow checking, use a regular addnode
because it's too complex to handle correctly otherwise }
if ([cs_check_overflow,cs_check_range]*current_settings.localswitches)<>[] then
begin
{ create constant 1 }
hp:=cordconstnode.create(1,left.resultdef,false);
typecheckpass(hp);
if not is_integer(hp.resultdef) then
inserttypeconv_internal(hp,sinttype);
{ avoid type errors from the addn/subn }
if not is_integer(left.resultdef) then
inserttypeconv_internal(left,sinttype);
{ addition/substraction depending on succ/pred }
if inlinenumber=in_succ_x then
hp:=caddnode.create(addn,left,hp)
else
hp:=caddnode.create(subn,left,hp);
{ assign result of addition }
if not(is_integer(resultdef)) then
inserttypeconv(hp,torddef.create(
{$ifdef cpu64bitaddr}
s64bit,
{$else cpu64bitaddr}
s32bit,
{$endif cpu64bitaddr}
get_min_value(resultdef),
get_max_value(resultdef)))
else
inserttypeconv(hp,resultdef);
{ avoid any possible errors/warnings }
inserttypeconv_internal(hp,resultdef);
{ firstpass it }
firstpass(hp);
{ left is reused }
left:=nil;
{ return new node }
result:=hp;
end;
end;
in_setlength_x,
in_initialize_x,
in_finalize_x:
begin
expectloc:=LOC_VOID;
end;
in_inc_x,
in_dec_x:
begin
expectloc:=LOC_VOID;
{ range/overflow checking doesn't work properly }
{ with the inc/dec code that's generated (JM) }
if (current_settings.localswitches * [cs_check_overflow,cs_check_range] <> []) and
{ No overflow check for pointer operations, because inc(pointer,-1) will always
trigger an overflow. For uint32 it works because then the operation is done
in 64bit. Range checking is not applicable to pointers either }
(tcallparanode(left).left.resultdef.typ<>pointerdef) then
{ convert to simple add (JM) }
begin
newblock := internalstatements(newstatement);
{ extra parameter? }
if assigned(tcallparanode(left).right) then
begin
{ Yes, use for add node }
hpp := tcallparanode(tcallparanode(left).right).left;
tcallparanode(tcallparanode(left).right).left := nil;
if assigned(tcallparanode(tcallparanode(left).right).right) then
CGMessage(parser_e_illegal_expression);
end
else
begin
{ no, create constant 1 }
hpp := cordconstnode.create(1,tcallparanode(left).left.resultdef,false);
end;
typecheckpass(hpp);
{ make sure we don't call functions part of the left node twice (and generally }
{ optimize the code generation) }
if node_complexity(tcallparanode(left).left) > 1 then
begin
tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
addstatement(newstatement,tempnode);
addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
caddrnode.create_internal(tcallparanode(left).left.getcopy)));
hp := cderefnode.create(ctemprefnode.create(tempnode));
inserttypeconv_internal(hp,tcallparanode(left).left.resultdef);
end
else
begin
hp := tcallparanode(left).left.getcopy;
tempnode := nil;
end;
resultnode := hp.getcopy;
{ avoid type errors from the addn/subn }
if not is_integer(resultnode.resultdef) then
begin
inserttypeconv_internal(hp,sinttype);
inserttypeconv_internal(hpp,sinttype);
end;
{ addition/substraction depending on inc/dec }
if inlinenumber = in_inc_x then
hpp := caddnode.create(addn,hp,hpp)
else
hpp := caddnode.create(subn,hp,hpp);
{ assign result of addition }
if not(is_integer(resultnode.resultdef)) then
inserttypeconv(hpp,torddef.create(
{$ifdef cpu64bitaddr}
s64bit,
{$else cpu64bitaddr}
s32bit,
{$endif cpu64bitaddr}
get_min_value(resultnode.resultdef),
get_max_value(resultnode.resultdef)))
else
inserttypeconv(hpp,resultnode.resultdef);
{ avoid any possible warnings }
inserttypeconv_internal(hpp,resultnode.resultdef);
addstatement(newstatement,cassignmentnode.create(resultnode,hpp));
{ deallocate the temp }
if assigned(tempnode) then
addstatement(newstatement,ctempdeletenode.create(tempnode));
{ firstpass it }
firstpass(tnode(newblock));
{ return new node }
result := newblock;
end;
end;
in_include_x_y,
in_exclude_x_y:
begin
expectloc:=LOC_VOID;
end;
in_pack_x_y_z,
in_unpack_x_y_z:
begin
result:=first_pack_unpack;
end;
in_exp_real:
begin
result:= first_exp_real;
end;
in_round_real:
begin
result:= first_round_real;
end;
in_trunc_real:
begin
result:= first_trunc_real;
end;
in_int_real:
begin
result:= first_int_real;
end;
in_frac_real:
begin
result:= first_frac_real;
end;
in_cos_real:
begin
result:= first_cos_real;
end;
in_sin_real:
begin
result := first_sin_real;
end;
in_arctan_real:
begin
result := first_arctan_real;
end;
in_pi_real :
begin
result := first_pi;
end;
in_abs_real:
begin
result := first_abs_real;
end;
in_abs_long:
begin
result := first_abs_long;
end;
in_sqr_real:
begin
result := first_sqr_real;
end;
in_sqrt_real:
begin
result := first_sqrt_real;
end;
in_ln_real:
begin
result := first_ln_real;
end;
{$ifdef SUPPORT_MMX}
in_mmx_pcmpeqb..in_mmx_pcmpgtw:
begin
end;
{$endif SUPPORT_MMX}
in_assert_x_y :
begin
expectloc:=LOC_VOID;
{$ifdef i386}
{ hack: on i386, the fourth parameter is passed via memory ->
we have to allocate enough stack space for it on targets that
use a fixed stack }
current_procinfo.allocate_push_parasize(4);
{$endif}
end;
in_low_x,
in_high_x:
internalerror(200104047);
in_slice_x:
internalerror(2005101501);
in_ord_x,
in_chr_byte:
begin
{ should not happend as it's converted to typeconv }
internalerror(200104045);
end;
in_ofs_x :
internalerror(2000101001);
in_seg_x :
internalerror(200104046);
in_settextbuf_file_x,
in_reset_typedfile,
in_rewrite_typedfile,
in_str_x_string,
in_val_x,
in_read_x,
in_readln_x,
in_write_x,
in_writeln_x :
begin
{ should be handled by pass_typecheck }
internalerror(200108234);
end;
in_get_frame:
begin
include(current_procinfo.flags,pi_needs_stackframe);
expectloc:=LOC_CREGISTER;
end;
in_get_caller_frame:
begin
expectloc:=LOC_REGISTER;
end;
in_get_caller_addr:
begin
expectloc:=LOC_REGISTER;
end;
in_prefetch_var:
begin
expectloc:=LOC_VOID;
end;
in_unaligned_x:
begin
expectloc:=tcallparanode(left).left.expectloc;
end;
in_rol_x,
in_rol_x_y,
in_ror_x,
in_ror_x_y,
in_sar_x,
in_sar_x_y,
in_bsf_x,
in_bsr_x:
expectloc:=LOC_REGISTER;
else
internalerror(89);
end;
end;
{$maxfpuregisters default}
function tinlinenode.docompare(p: tnode): boolean;
begin
docompare :=
inherited docompare(p) and
(inlinenumber = tinlinenode(p).inlinenumber);
end;
function tinlinenode.first_pi : tnode;
begin
result:=crealconstnode.create(getpi,pbestrealtype^);
end;
function tinlinenode.first_arctan_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_arctan_real := ccallnode.createintern('fpc_arctan_real',
ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_abs_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_abs_real := ccallnode.createintern('fpc_abs_real',
ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_sqr_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_sqr_real := ctypeconvnode.create(ccallnode.createintern('fpc_sqr_real',
ccallparanode.create(left,nil)),resultdef);
left := nil;
end;
function tinlinenode.first_sqrt_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_sqrt_real := ctypeconvnode.create(ccallnode.createintern('fpc_sqrt_real',
ccallparanode.create(left,nil)),resultdef);
left := nil;
end;
function tinlinenode.first_ln_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_ln_real := ccallnode.createintern('fpc_ln_real',
ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_cos_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_cos_real := ccallnode.createintern('fpc_cos_real',
ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_sin_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
first_sin_real := ccallnode.createintern('fpc_sin_real',
ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_exp_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
result := ccallnode.createintern('fpc_exp_real',ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_int_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
result := ccallnode.createintern('fpc_int_real',ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_frac_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
result := ccallnode.createintern('fpc_frac_real',ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_round_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
result := ccallnode.createintern('fpc_round_real',ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_trunc_real : tnode;
begin
{ create the call to the helper }
{ on entry left node contains the parameter }
result := ccallnode.createintern('fpc_trunc_real',ccallparanode.create(left,nil));
left := nil;
end;
function tinlinenode.first_abs_long : tnode;
begin
expectloc:=LOC_REGISTER;
result:=nil;
end;
function tinlinenode.first_pack_unpack: tnode;
var
loopstatement : tstatementnode;
loop : tblocknode;
loopvar : ttempcreatenode;
tempnode,
source,
target,
index,
unpackednode,
packednode,
sourcevecindex,
targetvecindex,
loopbody : tnode;
temprangedef : tdef;
ulorange,
uhirange,
plorange,
phirange : TConstExprInt;
begin
{ transform into a for loop which assigns the data of the (un)packed }
{ array to the other one }
source := left;
if (inlinenumber = in_unpack_x_y_z) then
begin
target := tcallparanode(source).right;
index := tcallparanode(target).right;
packednode := tcallparanode(source).left;
unpackednode := tcallparanode(target).left;
end
else
begin
index := tcallparanode(source).right;
target := tcallparanode(index).right;
packednode := tcallparanode(target).left;
unpackednode := tcallparanode(source).left;
end;
source := tcallparanode(source).left;
target := tcallparanode(target).left;
index := tcallparanode(index).left;
loop := internalstatements(loopstatement);
loopvar := ctempcreatenode.create(
tarraydef(packednode.resultdef).rangedef,
tarraydef(packednode.resultdef).rangedef.size,
tt_persistent,true);
addstatement(loopstatement,loopvar);
{ For range checking: we have to convert to an integer type (in case the index type }
{ is an enum), add the index and loop variable together, convert the result }
{ implicitly to an orddef with range equal to the rangedef to get range checking }
{ and finally convert it explicitly back to the actual rangedef to avoid type }
{ errors }
temprangedef:=nil;
getrange(unpackednode.resultdef,ulorange,uhirange);
getrange(packednode.resultdef,plorange,phirange);
temprangedef:=torddef.create(torddef(sinttype).ordtype,ulorange,uhirange);
sourcevecindex := ctemprefnode.create(loopvar);
targetvecindex := ctypeconvnode.create_internal(index.getcopy,sinttype);
targetvecindex := caddnode.create(subn,targetvecindex,cordconstnode.create(plorange,sinttype,true));
targetvecindex := caddnode.create(addn,targetvecindex,ctemprefnode.create(loopvar));
targetvecindex := ctypeconvnode.create(targetvecindex,temprangedef);
targetvecindex := ctypeconvnode.create_explicit(targetvecindex,tarraydef(unpackednode.resultdef).rangedef);
if (inlinenumber = in_pack_x_y_z) then
begin
{ swap source and target vec indices }
tempnode := sourcevecindex;
sourcevecindex := targetvecindex;
targetvecindex := tempnode;
end;
{ create the assignment in the loop body }
loopbody :=
cassignmentnode.create(
cvecnode.create(target.getcopy,targetvecindex),
cvecnode.create(source.getcopy,sourcevecindex)
);
{ create the actual for loop }
tempnode := cfornode.create(
ctemprefnode.create(loopvar),
cinlinenode.create(in_low_x,false,packednode.getcopy),
cinlinenode.create(in_high_x,false,packednode.getcopy),
loopbody,
false);
addstatement(loopstatement,tempnode);
{ free the loop counter }
addstatement(loopstatement,ctempdeletenode.create(loopvar));
result := loop;
end;
end.
|