1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710
|
// parse tree functions
// Copyright (C) 2005-2016 Red Hat Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
#include "config.h"
#include "staptree.h"
#include "parse.h"
#include "util.h"
#include "session.h"
#include "stringtable.h"
#include <iostream>
#include <typeinfo>
#include <sstream>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
visitable::~visitable ()
{
}
expression::expression ():
type (pe_unknown), tok (0)
{
}
expression::~expression ()
{
}
statement::statement ():
tok (0)
{
}
statement::statement (const token* tok):
tok (tok)
{
}
null_statement::null_statement (const token* tok):
statement(tok)
{
}
statement::~statement ()
{
}
symbol::symbol ():
referent (0)
{
}
arrayindex::arrayindex ():
base (0)
{
}
functioncall::functioncall ()
{
}
symboldecl::symboldecl ():
tok (0), systemtap_v_conditional (0),
type (pe_unknown)
{
}
symboldecl::~symboldecl ()
{
}
probe_point::probe_point (std::vector<component*> const & comps):
components(comps), optional (false), sufficient (false),
well_formed (false), condition (0)
{
}
// NB: shallow-copy of compoonents & condition!
probe_point::probe_point (const probe_point& pp):
components(pp.components), optional (pp.optional), sufficient (pp.sufficient),
well_formed (pp.well_formed), condition (pp.condition), auto_path (pp.auto_path)
{
}
probe_point::probe_point ():
optional (false), sufficient (false), well_formed (false), condition (0)
{
}
bool
probe_point::from_globby_comp(const std::string& comp)
{
vector<component*>::const_iterator it;
for (it = components.begin(); it != components.end(); it++)
if ((*it)->functor == comp)
return (*it)->from_glob;
return false;
}
unsigned probe::last_probeidx = 0;
probe::probe ():
body (0), base (0), tok (0), systemtap_v_conditional (0), privileged (false),
synthetic (false), id (last_probeidx ++)
{
}
// Copy constructor, but with overriding probe-point. To be used when
// mapping script-level probe points to another one, early during pass
// 2. There should be no symbol resolution done yet.
probe::probe(probe* p, probe_point* l):
locations (1, l), body (deep_copy_visitor::deep_copy (p->body)),
base (p), tok (p->tok), systemtap_v_conditional (p->systemtap_v_conditional),
privileged (p->privileged), synthetic (p->synthetic), id (last_probeidx ++)
{
assert (p->locals.size() == 0);
assert (p->unused_locals.size() == 0);
}
string
probe::name () const
{
return string ("probe_") + lex_cast(id);
}
probe_point::component::component ():
arg (0), from_glob(false), tok(0)
{
}
probe_point::component::component (interned_string f,
literal * a, bool from_glob):
functor(f), arg(a), from_glob(from_glob), tok(0)
{
}
vardecl::vardecl ():
arity_tok(0), arity (-1), maxsize(0), init(NULL), synthetic(false), wrap(false),
char_ptr_arg(false)
{
}
void
vardecl::set_arity (int a, const token* t)
{
if (a < 0)
return;
if (a == 0 && maxsize > 0)
throw SEMANTIC_ERROR (_("inconsistent arity"), tok);
if (arity != a && arity >= 0)
{
semantic_error err (ERR_SRC, _F("inconsistent arity (%s vs %d)",
lex_cast(arity).c_str(), a), t?:tok);
if (arity_tok)
{
semantic_error chain(ERR_SRC, _F("arity %s first inferred here",
lex_cast(arity).c_str()), arity_tok);
err.set_chain(chain);
}
throw err;
}
if (arity != a)
{
arity_tok = t;
arity = a;
index_types.resize (arity);
for (int i=0; i<arity; i++)
index_types[i] = pe_unknown;
}
}
bool
vardecl::compatible_arity (int a)
{
if (a == 0 && maxsize > 0)
return false;
if (arity == -1 || a == -1)
return true;
return arity == a;
}
functiondecl::functiondecl ():
body (0), synthetic (false), mangle_oldstyle (false), has_next(false),
priority(1)
{
}
void
functiondecl::join (systemtap_session& s)
{
if (!synthetic)
throw SEMANTIC_ERROR (_("internal error, joining a non-synthetic function"), tok);
if (!s.functions.insert (make_pair (name, this)).second)
throw SEMANTIC_ERROR (_F("synthetic function '%s' conflicts with an existing function",
name.to_string().c_str()), tok);
tok->location.file->functions.push_back (this);
}
literal_number::literal_number (int64_t v, bool hex)
{
value = v;
print_hex = hex;
type = pe_long;
}
literal_string::literal_string (interned_string v)
{
value = v;
type = pe_string;
}
ostream&
operator << (ostream& o, const exp_type& e)
{
switch (e)
{
case pe_unknown: o << "unknown"; break;
case pe_long: o << "long"; break;
case pe_string: o << "string"; break;
case pe_stats: o << "stats"; break;
default: o << "???"; break;
}
return o;
}
void
target_symbol::assert_no_components(const std::string& tapset, bool pretty_ok)
{
if (components.empty())
return;
const string& name = this->name;
switch (components[0].type)
{
case comp_literal_array_index:
case comp_expression_array_index:
throw SEMANTIC_ERROR(_F("%s variable '%s' may not be used as array",
tapset.c_str(), name.c_str()), components[0].tok);
case comp_struct_member:
throw SEMANTIC_ERROR(_F("%s variable '%s' may not be used as a structure",
tapset.c_str(), name.c_str()), components[0].tok);
case comp_pretty_print:
if (!pretty_ok)
throw SEMANTIC_ERROR(_F("%s variable '%s' may not be pretty-printed",
tapset.c_str(), name.c_str()), components[0].tok);
return;
default:
throw SEMANTIC_ERROR (_F("invalid use of %s variable '%s'",
tapset.c_str(), name.c_str()), components[0].tok);
}
}
size_t
target_symbol::pretty_print_depth () const
{
if (! components.empty ())
{
const component& last = components.back ();
if (last.type == comp_pretty_print)
return last.member.length ();
}
return 0;
}
bool
target_symbol::check_pretty_print (bool lvalue) const
{
if (pretty_print_depth () == 0)
return false;
if (lvalue)
throw SEMANTIC_ERROR(_("cannot write to pretty-printed variable"), tok);
return true;
}
void target_symbol::chain (const semantic_error &er)
{
semantic_error* e = new semantic_error(er);
if (!e->tok1)
e->tok1 = this->tok;
assert (e->get_chain() == 0);
if (this->saved_conversion_error)
{
e->set_chain(*this->saved_conversion_error);
delete this->saved_conversion_error;
}
this->saved_conversion_error = e;
}
string target_symbol::sym_name ()
{
return (string)name.substr(1);
}
string atvar_op::sym_name ()
{
if (cu_name == "")
return target_name;
else
return (string)target_name.substr(0, target_name.length() - cu_name.length() - 1);
}
bool
embedded_expr::tagged_p (const char *tag) const
{
return code.find(tag) != interned_string::npos;
}
bool
embedded_expr::tagged_p (const interned_string& tag) const
{
return code.find(tag) != interned_string::npos;
}
bool
embeddedcode::tagged_p (const char *tag) const
{
return code.find(tag) != interned_string::npos;
}
bool
embeddedcode::tagged_p (const interned_string& tag) const
{
return code.find(tag) != interned_string::npos;
}
// ------------------------------------------------------------------------
// parse tree printing
ostream& operator << (ostream& o, const expression& k)
{
k.print (o);
return o;
}
void literal_string::print (ostream& o) const
{
o << '"';
for (unsigned i=0; i<value.size(); i++)
if (value[i] == '"') // or other escapeworthy characters?
o << '\\' << '"';
else
o << value[i];
o << '"';
}
void literal_number::print (ostream& o) const
{
if (print_hex)
o << hex << showbase;
o << value;
if (print_hex)
o << dec << noshowbase;
}
void embedded_expr::print (ostream& o) const
{
o << "%{ " << code << " %}";
}
void binary_expression::print (ostream& o) const
{
o << "(" << *left << ") "
<< op
<< " (" << *right << ")";
}
void regex_query::print (ostream& o) const
{
// NB: we need a custom printer, because the parser does not accept
// a parenthesized RHS.
o << "(" << *left << ") "
<< op
<< " " << *right;
}
void unary_expression::print (ostream& o) const
{
o << op << '(' << *operand << ")";
}
void array_in::print (ostream& o) const
{
o << "[";
for (unsigned i=0; i<operand->indexes.size(); i++)
{
if (i > 0) o << ", ";
if (operand->indexes[i])
operand->indexes[i]->print (o);
else
o << "*";
}
o << "] in ";
operand->base->print (o);
}
void post_crement::print (ostream& o) const
{
o << '(' << *operand << ")" << op;
}
void ternary_expression::print (ostream& o) const
{
o << "(" << *cond << ")?("
<< *truevalue << "):("
<< *falsevalue << ")";
}
void symbol::print (ostream& o) const
{
o << name;
}
void target_symbol::component::print (ostream& o) const
{
switch (type)
{
case comp_pretty_print:
case comp_struct_member:
o << "->" << member;
break;
case comp_literal_array_index:
o << '[' << num_index << ']';
break;
case comp_expression_array_index:
o << '[' << *expr_index << ']';
break;
}
}
std::ostream& operator << (std::ostream& o, const target_symbol::component& c)
{
c.print (o);
return o;
}
void target_symbol::print (ostream& o) const
{
if (addressof)
o << "&";
o << name;
for (unsigned i = 0; i < components.size(); ++i)
o << components[i];
}
void atvar_op::print (ostream& o) const
{
if (addressof)
o << "&";
o << name << "(\"" << target_name << "\")";
for (unsigned i = 0; i < components.size(); ++i)
o << components[i];
}
void cast_op::print (ostream& o) const
{
if (addressof)
o << "&";
o << name << '(' << *operand;
o << ", " << lex_cast_qstring (type_name);
if (module.length() > 0)
o << ", " << lex_cast_qstring (module);
o << ')';
for (unsigned i = 0; i < components.size(); ++i)
o << components[i];
}
void autocast_op::print (ostream& o) const
{
if (addressof)
o << "&";
o << '(' << *operand << ')';
for (unsigned i = 0; i < components.size(); ++i)
o << components[i];
}
void defined_op::print (ostream& o) const
{
o << "@defined(" << *operand << ")";
}
void entry_op::print (ostream& o) const
{
o << "@entry(" << *operand << ")";
}
void perf_op::print (ostream& o) const
{
o << "@perf(" << *operand << ")";
}
void vardecl::print (ostream& o) const
{
o << unmangled_name;
if(wrap)
o << "%";
if (maxsize > 0)
o << "[" << maxsize << "]";
if (arity > 0 || index_types.size() > 0)
o << "[...]";
if (init)
{
o << " = ";
init->print(o);
}
}
void vardecl::printsig (ostream& o) const
{
if (unmangled_name != "")
o << unmangled_name;
else
o << name;
if(wrap)
o << "%";
if (maxsize > 0)
o << "[" << maxsize << "]";
o << ":" << type;
if (index_types.size() > 0)
{
o << " [";
for (unsigned i=0; i<index_types.size(); i++)
o << (i>0 ? ", " : "") << index_types[i];
o << "]";
}
}
void functiondecl::print (ostream& o) const
{
o << "function " << unmangled_name << " (";
for (unsigned i=0; i<formal_args.size(); i++)
o << (i>0 ? ", " : "") << *formal_args[i];
o << ")" << endl;
body->print(o);
}
void functiondecl::printsig (ostream& o) const
{
o << unmangled_name << ":" << type << " (";
for (unsigned i=0; i<formal_args.size(); i++)
o << (i>0 ? ", " : "")
<< *formal_args[i]
<< ":"
<< formal_args[i]->type;
o << ")";
}
embedded_tags_visitor::embedded_tags_visitor(bool all_tags)
{
// populate the set of tags that could appear in embedded code/expressions
available_tags.insert("/* guru */");
available_tags.insert("/* unprivileged */");
available_tags.insert("/* myproc-unprivileged */");
if (all_tags)
{
available_tags.insert("/* pure */");
available_tags.insert("/* unmangled */");
available_tags.insert("/* unmodified-fnargs */");
available_tags.insert("/* stable */");
}
}
void embedded_tags_visitor::visit_embeddedcode (embeddedcode *s)
{
for (auto tag = available_tags.begin(); tag != available_tags.end(); ++tag)
if (s->tagged_p(*tag))
tags.insert(*tag);
}
void embedded_tags_visitor::visit_embedded_expr (embedded_expr *e)
{
for (auto tag = available_tags.begin(); tag != available_tags.end(); ++tag)
if (e->tagged_p(*tag))
tags.insert(*tag);
}
void functiondecl::printsigtags (ostream& o, bool all_tags) const
{
this->printsig(o);
// Visit the function's body to see if there's any embedded_code or
// embeddedexpr that have special tags (e.g. /* guru */)
embedded_tags_visitor etv(all_tags);
this->body->visit(&etv);
for (auto tag = etv.tags.begin(); tag != etv.tags.end(); ++tag)
o << " " << *tag;
}
void arrayindex::print (ostream& o) const
{
base->print (o);
o << "[";
for (unsigned i=0; i<indexes.size(); i++)
{
o << (i>0 ? ", " : "");
if (indexes[i]==0)
o << "*";
else
o << *indexes[i];
}
o << "]";
}
void functioncall::print (ostream& o) const
{
o << function << "(";
for (unsigned i=0; i<args.size(); i++)
o << (i>0 ? ", " : "") << *args[i];
o << ")";
}
print_format*
print_format::create(const token *t, const char *n)
{
bool stream, format, delim, newline, _char;
interned_string type;
string str_type;
if (n == NULL)
{
type = t->content;
str_type = type;
n = str_type.c_str();
}
else
type = n;
stream = true;
format = delim = newline = _char = false;
if (strcmp(n, "print_char") == 0)
_char = true;
else
{
if (*n == 's')
{
stream = false;
++n;
}
if (0 != strncmp(n, "print", 5))
return NULL;
n += 5;
if (*n == 'f')
{
format = true;
++n;
}
else
{
if (*n == 'd')
{
delim = true;
++n;
}
if (*n == 'l' && *(n+1) == 'n')
{
newline = true;
n += 2;
}
}
if (*n != '\0')
return NULL;
}
print_format *pf = new print_format(stream, format, delim, newline, _char, type);
pf->tok = t;
return pf;
}
string
print_format::components_to_string(vector<format_component> const & components)
{
ostringstream oss;
for (vector<format_component>::const_iterator i = components.begin();
i != components.end(); ++i)
{
assert (i->type != conv_unspecified);
if (i->type == conv_literal)
{
assert(!i->literal_string.empty());
for (interned_string::const_iterator j = i->literal_string.begin();
j != i->literal_string.end(); ++j)
{
// See also: c_unparser::visit_literal_string and lex_cast_qstring
if (*j == '%')
oss << '%';
else if(*j == '"')
oss << '\\';
oss << *j;
}
}
else
{
oss << '%';
if (i->test_flag (fmt_flag_zeropad))
oss << '0';
if (i->test_flag (fmt_flag_plus))
oss << '+';
if (i->test_flag (fmt_flag_space))
oss << ' ';
if (i->test_flag (fmt_flag_left))
oss << '-';
if (i->test_flag (fmt_flag_special))
oss << '#';
if (i->widthtype == width_dynamic)
oss << '*';
else if (i->widthtype != width_unspecified && i->width > 0)
oss << i->width;
if (i->prectype == prec_dynamic)
oss << ".*";
else if (i->prectype != prec_unspecified && i->precision > 0)
oss << '.' << i->precision;
switch (i->type)
{
case conv_binary:
oss << "b";
break;
case conv_char:
oss << "llc";
break;
case conv_number:
if (i->base == 16)
{
if (i->test_flag (fmt_flag_large))
oss << "llX";
else
oss << "llx";
}
else if (i->base == 8)
oss << "llo";
else if (i->test_flag (fmt_flag_sign))
oss << "lld";
else
oss << "llu";
break;
case conv_pointer:
oss << "p";
break;
case conv_string:
oss << 's';
break;
case conv_memory:
oss << 'm';
break;
case conv_memory_hex:
oss << 'M';
break;
default:
break;
}
}
}
return oss.str ();
}
vector<print_format::format_component>
print_format::string_to_components(string const & str)
{
format_component curr;
vector<format_component> res;
curr.clear();
string::const_iterator i = str.begin();
string literal_str;
while (i != str.end())
{
if (*i != '%')
{
assert (curr.type == conv_unspecified || curr.type == conv_literal);
curr.type = conv_literal;
literal_str += *i;
++i;
continue;
}
else if (i+1 == str.end() || *(i+1) == '%')
{
assert(*i == '%');
// *i == '%' and *(i+1) == '%'; append only one '%' to the literal string
assert (curr.type == conv_unspecified || curr.type == conv_literal);
curr.type = conv_literal;
literal_str += '%';
i += 2;
continue;
}
else
{
assert(*i == '%');
if (curr.type != conv_unspecified)
{
// Flush any component we were previously accumulating
assert (curr.type == conv_literal);
curr.literal_string = literal_str;
res.push_back(curr);
literal_str.clear();
curr.clear();
}
}
++i;
if (i == str.end())
break;
// Now we are definitely parsing a conversion.
// Begin by parsing flags (which are optional).
switch (*i)
{
case '0':
curr.set_flag (fmt_flag_zeropad);
++i;
break;
case '+':
curr.set_flag (fmt_flag_plus);
++i;
break;
case '-':
curr.set_flag (fmt_flag_left);
++i;
break;
case ' ':
curr.set_flag (fmt_flag_space);
++i;
break;
case '#':
curr.set_flag (fmt_flag_special);
++i;
break;
default:
break;
}
if (i == str.end())
break;
// Parse optional width
if (*i == '*')
{
curr.widthtype = width_dynamic;
++i;
}
else if (isdigit(*i))
{
curr.widthtype = width_static;
curr.width = 0;
do
{
curr.width *= 10;
curr.width += (*i - '0');
++i;
}
while (i != str.end() && isdigit(*i));
}
if (i == str.end())
break;
// Parse optional precision
if (*i == '.')
{
++i;
if (i == str.end())
break;
if (*i == '*')
{
curr.prectype = prec_dynamic;
++i;
}
else if (isdigit(*i))
{
curr.prectype = prec_static;
curr.precision = 0;
do
{
curr.precision *= 10;
curr.precision += (*i - '0');
++i;
}
while (i != str.end() && isdigit(*i));
}
}
if (i == str.end())
break;
// Parse the type modifier
switch (*i)
{
case 'l':
++i;
break;
}
if (i == str.end())
break;
// Parse the actual conversion specifier (bcsmdioupxXn)
switch (*i)
{
// Valid conversion types
case 'b':
curr.type = conv_binary;
break;
case 'c':
curr.type = conv_char;
break;
case 's':
curr.type = conv_string;
break;
case 'm':
curr.type = conv_memory;
break;
case 'M':
curr.type = conv_memory_hex;
break;
case 'd':
case 'i':
curr.set_flag (fmt_flag_sign);
/* Fallthrough */
case 'u':
curr.type = conv_number;
curr.base = 10;
break;
case 'o':
curr.type = conv_number;
curr.base = 8;
break;
case 'X':
curr.set_flag (fmt_flag_large);
/* Fallthrough */
case 'x':
curr.type = conv_number;
curr.base = 16;
break;
case 'p':
// Since stap 1.3, %p == %#x.
curr.set_flag (fmt_flag_special);
curr.type = conv_pointer;
curr.base = 16;
// Oddness for stap < 1.3 is handled in translation
break;
default:
break;
}
if (curr.type == conv_unspecified)
throw PARSE_ERROR(_("invalid or missing conversion specifier"));
++i;
curr.literal_string = literal_str;
res.push_back(curr);
literal_str.clear();
curr.clear();
}
// If there's a remaining partly-composed conversion, fail.
if (!curr.is_empty())
{
if (curr.type == conv_literal)
{
curr.literal_string = literal_str;
res.push_back(curr);
// no need to clear curr / literal_str; we're leaving
}
else
throw PARSE_ERROR(_("trailing incomplete print format conversion"));
}
return res;
}
void print_format::print (ostream& o) const
{
o << print_format_type << "(";
if (print_with_format)
o << lex_cast_qstring (raw_components);
if (print_with_delim)
o << lex_cast_qstring (delimiter);
if (hist)
hist->print(o);
for (vector<expression*>::const_iterator i = args.begin();
i != args.end(); ++i)
{
if (i != args.begin() || print_with_format || print_with_delim)
o << ", ";
(*i)->print(o);
}
o << ")";
}
void stat_op::print (ostream& o) const
{
o << '@';
switch (ctype)
{
case sc_average:
o << "avg(";
break;
case sc_count:
o << "count(";
break;
case sc_sum:
o << "sum(";
break;
case sc_min:
o << "min(";
break;
case sc_max:
o << "max(";
break;
case sc_variance:
o << "variance(";
break;
case sc_none:
assert (0); // should not happen, as sc_none is only used in foreach sorts
break;
}
stat->print(o);
if (ctype == sc_variance && params.size() == 1)
o << ", " << params[0];
o << ")";
}
void
hist_op::print (ostream& o) const
{
o << '@';
switch (htype)
{
case hist_linear:
assert(params.size() == 3);
o << "hist_linear(";
stat->print(o);
for (size_t i = 0; i < params.size(); ++i)
{
o << ", " << params[i];
}
o << ")";
break;
case hist_log:
assert(params.size() == 0);
o << "hist_log(";
stat->print(o);
o << ")";
break;
}
}
ostream& operator << (ostream& o, const statement& k)
{
k.print (o);
return o;
}
void embeddedcode::print (ostream &o) const
{
o << "%{";
o << code;
o << "%}";
}
void block::print (ostream& o) const
{
o << "{" << endl;
for (unsigned i=0; i<statements.size(); i++)
o << *statements [i] << ";" << endl;
o << "}";
}
block::block (statement* car, statement* cdr)
{
statements.push_back(car);
statements.push_back(cdr);
this->tok = car->tok;
}
void try_block::print (ostream& o) const
{
o << "try {" << endl;
if (try_block) o << *try_block << endl;
o << "} catch ";
if (catch_error_var) o << "(" << *catch_error_var << ") ";
o << "{" << endl;
if (catch_block) o << *catch_block << endl;
o << "}" << endl;
}
void for_loop::print (ostream& o) const
{
o << "for (";
if (init) init->print (o);
o << "; ";
cond->print (o);
o << "; ";
if (incr) incr->print (o);
o << ") ";
block->print (o);
}
void foreach_loop::print (ostream& o) const
{
o << "foreach (";
if (value)
{
value->print (o);
o << " = ";
}
o << "[";
for (unsigned i=0; i<indexes.size(); i++)
{
if (i > 0) o << ", ";
indexes[i]->print (o);
if (sort_direction != 0 && sort_column == i+1)
o << (sort_direction > 0 ? "+" : "-");
}
o << "] in ";
base->print (o);
if (!array_slice.empty())
{
o << "[";
for (unsigned i=0; i<array_slice.size(); i++)
{
if (i > 0) o << ", ";
if (array_slice[i])
array_slice[i]->print (o);
else
o << "*";
}
o << "]";
}
if (sort_direction != 0 && sort_column == 0)
{
switch (sort_aggr)
{
case sc_count: o << " @count"; break;
case sc_average: o << " @avg"; break;
case sc_min: o << " @min"; break;
case sc_max: o << " @max"; break;
case sc_sum: o << " @sum"; break;
case sc_none:
default:
;
}
o << (sort_direction > 0 ? "+" : "-");
}
if (limit)
{
o << " limit ";
limit->print (o);
}
o << ") ";
block->print (o);
}
void null_statement::print (ostream& o) const
{
o << ";";
}
void expr_statement::print (ostream& o) const
{
o << *value;
}
void return_statement::print (ostream& o) const
{
o << "return " << *value;
}
void delete_statement::print (ostream& o) const
{
o << "delete " << *value;
}
void next_statement::print (ostream& o) const
{
o << "next";
}
void break_statement::print (ostream& o) const
{
o << "break";
}
void continue_statement::print (ostream& o) const
{
o << "continue";
}
void if_statement::print (ostream& o) const
{
o << "if (" << *condition << ") "
<< *thenblock << endl;
if (elseblock)
o << "else " << *elseblock << endl;
}
void stapfile::print (ostream& o) const
{
o << "# file " << name << endl;
for (unsigned i=0; i<embeds.size(); i++)
embeds[i]->print (o);
for (unsigned i=0; i<globals.size(); i++)
{
o << "global ";
globals[i]->print (o);
o << endl;
}
for (unsigned i=0; i<aliases.size(); i++)
{
aliases[i]->print (o);
o << endl;
}
for (unsigned i=0; i<probes.size(); i++)
{
probes[i]->print (o);
o << endl;
}
for (unsigned j = 0; j < functions.size(); j++)
{
functions[j]->print (o);
o << endl;
}
}
void probe::print (ostream& o) const
{
o << "probe ";
printsig (o);
o << *body;
}
void probe::printsig (ostream& o) const
{
const probe_alias *alias = get_alias ();
if (alias)
{
alias->printsig (o);
return;
}
for (unsigned i=0; i<locations.size(); i++)
{
if (i > 0) o << ",";
locations[i]->print (o);
}
}
void
probe::collect_derivation_chain (std::vector<probe*> &probes_list) const
{
probes_list.push_back(const_cast<probe*>(this));
if (base)
base->collect_derivation_chain(probes_list);
}
void
probe::collect_derivation_pp_chain (std::vector<probe_point*> &pp_list) const
{
pp_list.push_back(const_cast<probe_point*>(this->locations[0]));
if (base)
base->collect_derivation_pp_chain(pp_list);
}
void probe_point::print (ostream& o, bool print_extras) const
{
for (unsigned i=0; i<components.size(); i++)
{
if (i>0) o << ".";
probe_point::component* c = components[i];
if (!c)
{
// We might like to excise this weird 0 pointer, just in
// case some recursion during the error-handling path, but
// can't, because what we have here is a const *this.
static int been_here = 0;
if (been_here == 0) {
been_here ++;
throw SEMANTIC_ERROR (_("internal error: missing probe point component"));
} else
continue; // ... sad panda decides to skip the bad boy
}
o << c->functor;
if (c->arg)
o << "(" << *c->arg << ")";
}
if (!print_extras)
return;
if (sufficient)
o << "!";
else if (optional) // sufficient implies optional
o << "?";
if (condition)
o<< " if (" << *condition << ")";
}
string probe_point::str (bool print_extras) const
{
ostringstream o;
print(o, print_extras);
return o.str();
}
probe_alias::probe_alias(std::vector<probe_point*> const & aliases):
probe (), alias_names (aliases), epilogue_style(false)
{
}
void probe_alias::printsig (ostream& o) const
{
for (unsigned i=0; i<alias_names.size(); i++)
{
o << (i>0 ? " = " : "");
alias_names[i]->print (o);
}
o << (epilogue_style ? " += " : " = ");
for (unsigned i=0; i<locations.size(); i++)
{
if (i > 0) o << ", ";
locations[i]->print (o);
}
}
ostream& operator << (ostream& o, const probe_point& k)
{
k.print (o);
return o;
}
ostream& operator << (ostream& o, const symboldecl& k)
{
k.print (o);
return o;
}
// ------------------------------------------------------------------------
// visitors
void
block::visit (visitor* u)
{
u->visit_block (this);
}
void
try_block::visit (visitor* u)
{
u->visit_try_block (this);
}
void
embeddedcode::visit (visitor* u)
{
u->visit_embeddedcode (this);
}
void
for_loop::visit (visitor* u)
{
u->visit_for_loop (this);
}
void
foreach_loop::visit (visitor* u)
{
u->visit_foreach_loop (this);
}
void
null_statement::visit (visitor* u)
{
u->visit_null_statement (this);
}
void
expr_statement::visit (visitor* u)
{
u->visit_expr_statement (this);
}
void
return_statement::visit (visitor* u)
{
u->visit_return_statement (this);
}
void
delete_statement::visit (visitor* u)
{
u->push_active_lvalue (this->value);
u->visit_delete_statement (this);
u->pop_active_lvalue ();
}
void
if_statement::visit (visitor* u)
{
u->visit_if_statement (this);
}
void
next_statement::visit (visitor* u)
{
u->visit_next_statement (this);
}
void
break_statement::visit (visitor* u)
{
u->visit_break_statement (this);
}
void
continue_statement::visit (visitor* u)
{
u->visit_continue_statement (this);
}
void
literal_string::visit(visitor* u)
{
u->visit_literal_string (this);
}
void
literal_number::visit(visitor* u)
{
u->visit_literal_number (this);
}
void
binary_expression::visit (visitor* u)
{
u->visit_binary_expression (this);
}
void
embedded_expr::visit (visitor* u)
{
u->visit_embedded_expr (this);
}
void
unary_expression::visit (visitor* u)
{
u->visit_unary_expression (this);
}
void
pre_crement::visit (visitor* u)
{
u->push_active_lvalue (this->operand);
u->visit_pre_crement (this);
u->pop_active_lvalue ();
}
void
post_crement::visit (visitor* u)
{
u->push_active_lvalue (this->operand);
u->visit_post_crement (this);
u->pop_active_lvalue ();
}
void
logical_or_expr::visit (visitor* u)
{
u->visit_logical_or_expr (this);
}
void
logical_and_expr::visit (visitor* u)
{
u->visit_logical_and_expr (this);
}
void
array_in::visit (visitor* u)
{
u->visit_array_in (this);
}
void
regex_query::visit (visitor* u)
{
u->visit_regex_query (this);
}
void
comparison::visit (visitor* u)
{
u->visit_comparison (this);
}
void
concatenation::visit (visitor* u)
{
u->visit_concatenation (this);
}
void
ternary_expression::visit (visitor* u)
{
u->visit_ternary_expression (this);
}
void
assignment::visit (visitor* u)
{
u->push_active_lvalue (this->left);
u->visit_assignment (this);
u->pop_active_lvalue ();
}
void
symbol::visit (visitor* u)
{
u->visit_symbol (this);
}
void
target_symbol::visit (visitor* u)
{
u->visit_target_symbol(this);
}
void
target_symbol::visit_components (visitor* u)
{
for (unsigned i = 0; i < components.size(); ++i)
if (components[i].type == comp_expression_array_index)
components[i].expr_index->visit (u);
}
void
target_symbol::visit_components (update_visitor* u)
{
for (unsigned i = 0; i < components.size(); ++i)
if (components[i].type == comp_expression_array_index)
u->replace (components[i].expr_index);
}
void
cast_op::visit (visitor* u)
{
u->visit_cast_op(this);
}
void
autocast_op::visit (visitor* u)
{
u->visit_autocast_op(this);
}
void
atvar_op::visit (visitor* u)
{
u->visit_atvar_op(this);
}
void
defined_op::visit (visitor* u)
{
u->visit_defined_op(this);
}
void
entry_op::visit (visitor* u)
{
u->visit_entry_op(this);
}
void
perf_op::visit (visitor* u)
{
u->visit_perf_op(this);
}
void
arrayindex::visit (visitor* u)
{
u->visit_arrayindex (this);
}
void
functioncall::visit (visitor* u)
{
u->visit_functioncall (this);
}
void
print_format::visit (visitor *u)
{
u->visit_print_format (this);
}
void
stat_op::visit (visitor *u)
{
u->visit_stat_op (this);
}
void
hist_op::visit (visitor *u)
{
u->visit_hist_op (this);
}
bool
expression::is_symbol(symbol *& sym_out)
{
sym_out = NULL;
return false;
}
bool
indexable::is_symbol(symbol *& sym_out)
{
sym_out = NULL;
return false;
}
bool
indexable::is_hist_op(hist_op *& hist_out)
{
hist_out = NULL;
return false;
}
bool
symbol::is_symbol(symbol *& sym_out)
{
sym_out = this;
return true;
}
bool
hist_op::is_hist_op(hist_op *& hist_out)
{
hist_out = this;
return true;
}
void
classify_indexable(indexable* ix,
symbol *& array_out,
hist_op *& hist_out)
{
array_out = NULL;
hist_out = NULL;
assert(ix != NULL);
if (!(ix->is_symbol (array_out) || ix->is_hist_op (hist_out)))
throw SEMANTIC_ERROR(_("Expecting symbol or histogram operator"), ix->tok);
if (!(hist_out || array_out))
throw SEMANTIC_ERROR(_("Failed to classify indexable"), ix->tok);
}
// ------------------------------------------------------------------------
bool
visitor::is_active_lvalue(expression *e)
{
for (unsigned i = 0; i < active_lvalues.size(); ++i)
{
if (active_lvalues[i] == e)
return true;
}
return false;
}
void
visitor::push_active_lvalue(expression *e)
{
active_lvalues.push_back(e);
}
void
visitor::pop_active_lvalue()
{
assert(!active_lvalues.empty());
active_lvalues.pop_back();
}
// ------------------------------------------------------------------------
void
traversing_visitor::visit_block (block* s)
{
for (unsigned i=0; i<s->statements.size(); i++)
s->statements[i]->visit (this);
}
void
traversing_visitor::visit_try_block (try_block* s)
{
if (s->try_block)
s->try_block->visit (this);
if (s->catch_error_var)
s->catch_error_var->visit (this);
if (s->catch_block)
s->catch_block->visit (this);
}
void
traversing_visitor::visit_embeddedcode (embeddedcode*)
{
}
void
traversing_visitor::visit_null_statement (null_statement*)
{
}
void
traversing_visitor::visit_expr_statement (expr_statement* s)
{
s->value->visit (this);
}
void
traversing_visitor::visit_if_statement (if_statement* s)
{
s->condition->visit (this);
s->thenblock->visit (this);
if (s->elseblock)
s->elseblock->visit (this);
}
void
traversing_visitor::visit_for_loop (for_loop* s)
{
if (s->init) s->init->visit (this);
s->cond->visit (this);
if (s->incr) s->incr->visit (this);
s->block->visit (this);
}
void
traversing_visitor::visit_foreach_loop (foreach_loop* s)
{
s->base->visit(this);
for (unsigned i=0; i<s->indexes.size(); i++)
s->indexes[i]->visit (this);
if (s->value)
s->value->visit (this);
if (s->limit)
s->limit->visit (this);
s->block->visit (this);
}
void
traversing_visitor::visit_return_statement (return_statement* s)
{
s->value->visit (this);
}
void
traversing_visitor::visit_delete_statement (delete_statement* s)
{
s->value->visit (this);
}
void
traversing_visitor::visit_next_statement (next_statement*)
{
}
void
traversing_visitor::visit_break_statement (break_statement*)
{
}
void
traversing_visitor::visit_continue_statement (continue_statement*)
{
}
void
traversing_visitor::visit_literal_string (literal_string*)
{
}
void
traversing_visitor::visit_literal_number (literal_number*)
{
}
void
traversing_visitor::visit_embedded_expr (embedded_expr*)
{
}
void
traversing_visitor::visit_binary_expression (binary_expression* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_unary_expression (unary_expression* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_pre_crement (pre_crement* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_post_crement (post_crement* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_logical_or_expr (logical_or_expr* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_logical_and_expr (logical_and_expr* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_array_in (array_in* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_regex_query (regex_query* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_comparison (comparison* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_concatenation (concatenation* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_ternary_expression (ternary_expression* e)
{
e->cond->visit (this);
e->truevalue->visit (this);
e->falsevalue->visit (this);
}
void
traversing_visitor::visit_assignment (assignment* e)
{
e->left->visit (this);
e->right->visit (this);
}
void
traversing_visitor::visit_symbol (symbol*)
{
}
void
traversing_visitor::visit_target_symbol (target_symbol* e)
{
e->visit_components (this);
}
void
traversing_visitor::visit_cast_op (cast_op* e)
{
e->operand->visit (this);
e->visit_components (this);
}
void
traversing_visitor::visit_autocast_op (autocast_op* e)
{
e->operand->visit (this);
e->visit_components (this);
}
void
traversing_visitor::visit_atvar_op (atvar_op* e)
{
e->visit_components (this);
}
void
traversing_visitor::visit_defined_op (defined_op* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_entry_op (entry_op* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_perf_op (perf_op* e)
{
e->operand->visit (this);
}
void
traversing_visitor::visit_arrayindex (arrayindex* e)
{
for (unsigned i=0; i<e->indexes.size(); i++)
if (e->indexes[i])
e->indexes[i]->visit (this);
e->base->visit(this);
}
void
traversing_visitor::visit_functioncall (functioncall* e)
{
for (unsigned i=0; i<e->args.size(); i++)
e->args[i]->visit (this);
}
void
traversing_visitor::visit_print_format (print_format* e)
{
for (unsigned i=0; i<e->args.size(); i++)
e->args[i]->visit (this);
if (e->hist)
e->hist->visit(this);
}
void
traversing_visitor::visit_stat_op (stat_op* e)
{
e->stat->visit (this);
}
void
traversing_visitor::visit_hist_op (hist_op* e)
{
e->stat->visit (this);
}
void
expression_visitor::visit_literal_string (literal_string* e)
{
traversing_visitor::visit_literal_string (e);
visit_expression (e);
}
void
expression_visitor::visit_literal_number (literal_number* e)
{
traversing_visitor::visit_literal_number (e);
visit_expression (e);
}
void
expression_visitor::visit_embedded_expr (embedded_expr* e)
{
traversing_visitor::visit_embedded_expr (e);
visit_expression (e);
}
void
expression_visitor::visit_binary_expression (binary_expression* e)
{
traversing_visitor::visit_binary_expression (e);
visit_expression (e);
}
void
expression_visitor::visit_unary_expression (unary_expression* e)
{
traversing_visitor::visit_unary_expression (e);
visit_expression (e);
}
void
expression_visitor::visit_pre_crement (pre_crement* e)
{
traversing_visitor::visit_pre_crement (e);
visit_expression (e);
}
void
expression_visitor::visit_post_crement (post_crement* e)
{
traversing_visitor::visit_post_crement (e);
visit_expression (e);
}
void
expression_visitor::visit_logical_or_expr (logical_or_expr* e)
{
traversing_visitor::visit_logical_or_expr (e);
visit_expression (e);
}
void
expression_visitor::visit_logical_and_expr (logical_and_expr* e)
{
traversing_visitor::visit_logical_and_expr (e);
visit_expression (e);
}
void
expression_visitor::visit_array_in (array_in* e)
{
traversing_visitor::visit_array_in (e);
visit_expression (e);
}
void
expression_visitor::visit_regex_query (regex_query* e)
{
traversing_visitor::visit_regex_query (e);
visit_expression (e);
}
void
expression_visitor::visit_comparison (comparison* e)
{
traversing_visitor::visit_comparison (e);
visit_expression (e);
}
void
expression_visitor::visit_concatenation (concatenation* e)
{
traversing_visitor::visit_concatenation (e);
visit_expression (e);
}
void
expression_visitor::visit_ternary_expression (ternary_expression* e)
{
traversing_visitor::visit_ternary_expression (e);
visit_expression (e);
}
void
expression_visitor::visit_assignment (assignment* e)
{
traversing_visitor::visit_assignment (e);
visit_expression (e);
}
void
expression_visitor::visit_symbol (symbol* e)
{
traversing_visitor::visit_symbol (e);
visit_expression (e);
}
void
expression_visitor::visit_target_symbol (target_symbol* e)
{
traversing_visitor::visit_target_symbol (e);
visit_expression (e);
}
void
expression_visitor::visit_arrayindex (arrayindex* e)
{
traversing_visitor::visit_arrayindex (e);
visit_expression (e);
}
void
expression_visitor::visit_functioncall (functioncall* e)
{
traversing_visitor::visit_functioncall (e);
visit_expression (e);
}
void
expression_visitor::visit_print_format (print_format* e)
{
traversing_visitor::visit_print_format (e);
visit_expression (e);
}
void
expression_visitor::visit_stat_op (stat_op* e)
{
traversing_visitor::visit_stat_op (e);
visit_expression (e);
}
void
expression_visitor::visit_hist_op (hist_op* e)
{
traversing_visitor::visit_hist_op (e);
visit_expression (e);
}
void
expression_visitor::visit_cast_op (cast_op* e)
{
traversing_visitor::visit_cast_op (e);
visit_expression (e);
}
void
expression_visitor::visit_autocast_op (autocast_op* e)
{
traversing_visitor::visit_autocast_op (e);
visit_expression (e);
}
void
expression_visitor::visit_atvar_op (atvar_op* e)
{
traversing_visitor::visit_atvar_op (e);
visit_expression (e);
}
void
expression_visitor::visit_defined_op (defined_op* e)
{
traversing_visitor::visit_defined_op (e);
visit_expression (e);
}
void
expression_visitor::visit_entry_op (entry_op* e)
{
traversing_visitor::visit_entry_op (e);
visit_expression (e);
}
void
expression_visitor::visit_perf_op (perf_op* e)
{
traversing_visitor::visit_perf_op (e);
visit_expression (e);
}
void
functioncall_traversing_visitor::visit_functioncall (functioncall* e)
{
traversing_visitor::visit_functioncall (e);
this->enter_functioncall(e);
}
void
functioncall_traversing_visitor::enter_functioncall (functioncall* e)
{
for (unsigned i = 0; i < e->referents.size(); i++)
{
functiondecl* referent = e->referents[i];
// prevent infinite recursion
if (nested.find (referent) == nested.end ())
{
if (seen.find(referent) == seen.end())
seen.insert (referent);
nested.insert (referent);
// recurse
functiondecl* last_current_function = current_function;
current_function = referent;
referent->body->visit (this);
current_function = last_current_function;
nested.erase (referent);
}
else { this->note_recursive_functioncall(e); }
}
}
void
functioncall_traversing_visitor::note_recursive_functioncall (functioncall*)
{
}
void
varuse_collecting_visitor::visit_if_statement (if_statement *s)
{
assert(!current_lvalue_read);
current_lvalue_read = true;
s->condition->visit (this);
current_lvalue_read = false;
s->thenblock->visit (this);
if (s->elseblock)
s->elseblock->visit (this);
}
void
varuse_collecting_visitor::visit_for_loop (for_loop *s)
{
if (s->init) s->init->visit (this);
assert(!current_lvalue_read);
current_lvalue_read = true;
s->cond->visit (this);
current_lvalue_read = false;
if (s->incr) s->incr->visit (this);
s->block->visit (this);
}
void
varuse_collecting_visitor::visit_try_block (try_block *s)
{
if (s->try_block)
s->try_block->visit (this);
if (s->catch_error_var)
written.insert (s->catch_error_var->referent);
if (s->catch_block)
s->catch_block->visit (this);
// NB: don't functioncall_traversing_visitor::visit_try_block (s);
// since that would count s->catch_error_var as a read also.
}
void
varuse_collecting_visitor::visit_functioncall (functioncall* e)
{
// NB: don't call functioncall_traversing_visitor::visit_functioncall(). We
// replicate functionality here but split argument visiting from actual
// function visiting.
bool last_lvalue_read = current_lvalue_read;
// arguments are used
current_lvalue_read = true;
traversing_visitor::visit_functioncall(e);
// but function body shouldn't all be marked used
current_lvalue_read = false;
functioncall_traversing_visitor::enter_functioncall(e);
current_lvalue_read = last_lvalue_read;
}
void
varuse_collecting_visitor::visit_return_statement (return_statement *s)
{
assert(!current_lvalue_read);
current_lvalue_read = true;
functioncall_traversing_visitor::visit_return_statement(s);
current_lvalue_read = false;
}
void
varuse_collecting_visitor::visit_embeddedcode (embeddedcode *s)
{
assert (current_function); // only they get embedded code
/* We need to lock globals that are accessed through embedded C code */
for (unsigned i = 0; i < session.globals.size(); i++)
{
vardecl* v = session.globals[i];
string name = v->unmangled_name;
if (s->code.find("/* pragma:read:" + name + " */") != string::npos)
{
if (v->type == pe_stats)
throw SEMANTIC_ERROR(_("Aggregates not available in embedded-C"), s->tok);
read.insert(v);
}
if (s->code.find("/* pragma:write:" + name + " */") != string::npos)
{
if (v->type == pe_stats)
throw SEMANTIC_ERROR(_("Aggregates not available in embedded-C"), s->tok);
written.insert(v);
}
}
// Don't allow embedded C functions in unprivileged mode unless
// they are tagged with /* unprivileged */ or /* myproc-unprivileged */
// or we're in a usermode runtime.
if (! pr_contains (session.privilege, pr_stapdev) &&
! pr_contains (session.privilege, pr_stapsys) &&
! session.runtime_usermode_p () &&
s->code.find ("/* unprivileged */") == string::npos &&
s->code.find ("/* myproc-unprivileged */") == string::npos)
throw SEMANTIC_ERROR (_F("function may not be used when --privilege=%s is specified",
pr_name (session.privilege)),
current_function->tok);
// Don't allow /* guru */ functions unless -g is active.
if (!session.guru_mode && s->code.find ("/* guru */") != string::npos)
throw SEMANTIC_ERROR (_("function may not be used unless -g is specified"),
current_function->tok);
// PR14524: Support old-style THIS->local syntax on per-function basis.
if (s->code.find ("/* unmangled */") != string::npos)
current_function->mangle_oldstyle = true;
// We want to elide embedded-C functions when possible. For
// example, each $target variable access is expanded to an
// embedded-C function call. Yet, for safety reasons, we should
// presume that embedded-C functions have intentional side-effects.
//
// To tell these two types of functions apart, we apply a
// Kludge(tm): we look for a magic string within the function body.
// $target variables as rvalues will have this; lvalues won't.
// Also, explicit side-effect-free tapset functions will have this.
if (s->code.find ("/* pure */") != string::npos)
return;
embedded_seen = true;
}
// About the same case as above.
void
varuse_collecting_visitor::visit_embedded_expr (embedded_expr *e)
{
/* We need to lock globals that are accessed through embedded C code */
for (unsigned i = 0; i < session.globals.size(); i++)
{
vardecl* v = session.globals[i];
string name = v->unmangled_name;
if (e->code.find("/* pragma:read:" + name + " */") != string::npos)
{
if (v->type == pe_stats)
throw SEMANTIC_ERROR(_("Aggregates not available in embedded-C"), e->tok);
read.insert(v);
}
if (e->code.find("/* pragma:write:" + name + " */") != string::npos)
{
if (v->type == pe_stats)
throw SEMANTIC_ERROR(_("Aggregates not available in embedded-C"), e->tok);
written.insert(v);
}
}
// Don't allow embedded C expressions in unprivileged mode unless
// they are tagged with /* unprivileged */ or /* myproc-unprivileged */
// or we're in a usermode runtime.
if (! pr_contains (session.privilege, pr_stapdev) &&
! pr_contains (session.privilege, pr_stapsys) &&
! session.runtime_usermode_p () &&
e->code.find ("/* unprivileged */") == string::npos &&
e->code.find ("/* myproc-unprivileged */") == string::npos)
throw SEMANTIC_ERROR (_F("embedded expression may not be used when --privilege=%s is specified",
pr_name (session.privilege)),
e->tok);
// Don't allow /* guru */ functions unless -g is active.
if (!session.guru_mode && e->code.find ("/* guru */") != string::npos)
throw SEMANTIC_ERROR (_("embedded expression may not be used unless -g is specified"),
e->tok);
// We want to elide embedded-C functions when possible. For
// example, each $target variable access is expanded to an
// embedded-C function call. Yet, for safety reasons, we should
// presume that embedded-C functions have intentional side-effects.
//
// To tell these two types of functions apart, we apply a
// Kludge(tm): we look for a magic string within the function body.
// $target variables as rvalues will have this; lvalues won't.
// Also, explicit side-effect-free tapset functions will have this.
if (e->code.find ("/* pure */") != string::npos)
return;
embedded_seen = true;
}
void
varuse_collecting_visitor::visit_target_symbol (target_symbol *e)
{
// Still-unresolved target symbol assignments get treated as
// generating side-effects like embedded-C, to prevent premature
// elision and later error message suppression (PR5516). rvalue use
// of unresolved target symbols is OTOH not considered a side-effect.
if (is_active_lvalue (e))
embedded_seen = true;
functioncall_traversing_visitor::visit_target_symbol (e);
}
void
varuse_collecting_visitor::visit_atvar_op (atvar_op *e)
{
// Similar to visit_target_symbol
if (is_active_lvalue (e))
embedded_seen = true;
functioncall_traversing_visitor::visit_atvar_op (e);
}
void
varuse_collecting_visitor::visit_cast_op (cast_op *e)
{
// As with target_symbols, unresolved cast assignments need to preserved
// for later error handling.
if (is_active_lvalue (e))
embedded_seen = true;
functioncall_traversing_visitor::visit_cast_op (e);
}
void
varuse_collecting_visitor::visit_autocast_op (autocast_op *e)
{
// As with target_symbols, unresolved cast assignments need to preserved
// for later error handling.
if (is_active_lvalue (e))
embedded_seen = true;
functioncall_traversing_visitor::visit_autocast_op (e);
}
void
varuse_collecting_visitor::visit_defined_op (defined_op *e)
{
// XXX
functioncall_traversing_visitor::visit_defined_op (e);
}
void
varuse_collecting_visitor::visit_entry_op (entry_op *e)
{
// XXX
functioncall_traversing_visitor::visit_entry_op (e);
}
void
varuse_collecting_visitor::visit_perf_op (perf_op *e)
{
functioncall_traversing_visitor::visit_perf_op (e);
}
void
varuse_collecting_visitor::visit_print_format (print_format* e)
{
// NB: Instead of being top-level statements, "print" and "printf"
// are implemented as statement-expressions containing a
// print_format. They have side-effects, but not via the
// embedded-code detection method above.
//
// But sprint and sprintf don't have side-effects.
bool last_lvalue_read = current_lvalue_read;
current_lvalue_read = true;
if (e->print_to_stream)
embedded_seen = true; // a proxy for "has unknown side-effects"
functioncall_traversing_visitor::visit_print_format (e);
current_lvalue_read = last_lvalue_read;
}
void
varuse_collecting_visitor::visit_assignment (assignment *e)
{
if (e->op == "=" || e->op == "<<<") // pure writes
{
expression* last_lvalue = current_lvalue;
bool last_lvalue_read = current_lvalue_read;
current_lvalue = e->left; // leave a mark for ::visit_symbol
current_lvalue_read = true;
functioncall_traversing_visitor::visit_assignment (e);
current_lvalue = last_lvalue;
current_lvalue_read = last_lvalue_read;
}
else // read-modify-writes
{
expression* last_lrvalue = current_lrvalue;
current_lrvalue = e->left; // leave a mark for ::visit_symbol
functioncall_traversing_visitor::visit_assignment (e);
current_lrvalue = last_lrvalue;
}
}
void
varuse_collecting_visitor::visit_ternary_expression (ternary_expression* e)
{
// NB: don't call base class's implementation. We do the work here already.
bool last_lvalue_read = current_lvalue_read;
current_lvalue_read = true;
e->cond->visit (this);
current_lvalue_read = last_lvalue_read;
e->truevalue->visit (this);
e->falsevalue->visit (this);
}
void
varuse_collecting_visitor::visit_symbol (symbol *e)
{
if (e->referent == 0)
throw SEMANTIC_ERROR (_("symbol without referent"), e->tok);
// We could handle initialized globals by marking them as "written".
// However, this current visitor may be called for a function or
// probe body, from the point of view of which this global is
// already initialized, so not written.
/*
if (e->referent->init)
written.insert (e->referent);
*/
if (current_lvalue == e || current_lrvalue == e)
{
written.insert (e->referent);
}
if (current_lvalue != e || current_lrvalue == e)
{
read.insert (e->referent);
}
if (current_lrvalue == e)
{
if (current_lvalue_read)
used.insert (e->referent);
}
else if (current_lvalue != e)
used.insert (e->referent);
}
// NB: stat_op need not be overridden, since it will get to
// visit_symbol and only as a possible rvalue.
void
varuse_collecting_visitor::visit_arrayindex (arrayindex *e)
{
// NB: don't call parent implementation, we do the work here.
// First let's visit the indexes separately
bool old_lvalue_read = current_lvalue_read;
current_lvalue_read = true;
for (unsigned i=0; i<e->indexes.size(); i++)
if (e->indexes[i])
e->indexes[i]->visit (this);
current_lvalue_read = old_lvalue_read;
// Hooking this callback is necessary because of the hacky
// statistics representation. For the expression "i[4] = 5", the
// incoming lvalue will point to this arrayindex. However, the
// symbol corresponding to the "i[4]" is multiply inherited with
// arrayindex. If the symbol base part of this object is not at
// offset 0, then static_cast<symbol*>(e) may result in a different
// address, and not match lvalue by number when we recurse that way.
// So we explicitly override the incoming lvalue/lrvalue values to
// point at the embedded objects' actual base addresses.
expression* last_lrvalue = current_lrvalue;
expression* last_lvalue = current_lvalue;
symbol *array = NULL;
hist_op *hist = NULL;
classify_indexable(e->base, array, hist);
expression *value = array ?: hist->stat;
if (current_lrvalue == e) current_lrvalue = value;
if (current_lvalue == e) current_lvalue = value;
e->base->visit(this);
current_lrvalue = last_lrvalue;
current_lvalue = last_lvalue;
}
void
varuse_collecting_visitor::visit_pre_crement (pre_crement *e)
{
expression* last_lrvalue = current_lrvalue;
current_lrvalue = e->operand; // leave a mark for ::visit_symbol
functioncall_traversing_visitor::visit_pre_crement (e);
current_lrvalue = last_lrvalue;
}
void
varuse_collecting_visitor::visit_post_crement (post_crement *e)
{
expression* last_lrvalue = current_lrvalue;
current_lrvalue = e->operand; // leave a mark for ::visit_symbol
functioncall_traversing_visitor::visit_post_crement (e);
current_lrvalue = last_lrvalue;
}
void
varuse_collecting_visitor::visit_foreach_loop (foreach_loop* s)
{
assert(!current_lvalue_read);
// NB: we duplicate so don't bother call
// functioncall_traversing_visitor::visit_foreach_loop (s);
s->base->visit(this);
// If the collection is sorted, imply a "write" access to the
// array in addition to the "read" one already noted above.
if (s->sort_direction)
{
symbol *array = NULL;
hist_op *hist = NULL;
classify_indexable (s->base, array, hist);
if (array) this->written.insert (array->referent);
// XXX: Can hist_op iterations be sorted?
}
// NB: don't forget to visit the index expressions, which are lvalues.
for (unsigned i=0; i<s->indexes.size(); i++)
{
expression* last_lvalue = current_lvalue;
current_lvalue = s->indexes[i]; // leave a mark for ::visit_symbol
s->indexes[i]->visit (this);
current_lvalue = last_lvalue;
}
// visit the additional specified array slice
current_lvalue_read = true;
for (unsigned i=0; i<s->array_slice.size(); i++)
{
if (s->array_slice[i])
s->array_slice[i]->visit (this);
}
current_lvalue_read = false;
// The value is an lvalue too
if (s->value)
{
expression* last_lvalue = current_lvalue;
current_lvalue = s->value; // leave a mark for ::visit_symbol
s->value->visit (this);
current_lvalue = last_lvalue;
}
if (s->limit)
{
current_lvalue_read = true;
s->limit->visit (this);
current_lvalue_read = false;
}
s->block->visit (this);
}
void
varuse_collecting_visitor::visit_delete_statement (delete_statement* s)
{
// Ideally, this would be treated like an assignment: a plain write
// to the underlying value ("lvalue"). XXX: However, the
// optimization pass is not smart enough to remove an unneeded
// "delete" yet, so we pose more like a *crement ("lrvalue"). This
// should protect the underlying value from optimizional mischief.
assert(!current_lvalue_read);
expression* last_lrvalue = current_lrvalue;
current_lrvalue = s->value; // leave a mark for ::visit_symbol
current_lvalue_read = true;
functioncall_traversing_visitor::visit_delete_statement (s);
current_lrvalue = last_lrvalue;
current_lvalue_read = false;
}
bool
varuse_collecting_visitor::side_effect_free ()
{
return (written.empty() && !embedded_seen);
}
bool
varuse_collecting_visitor::side_effect_free_wrt (const set<vardecl*>& vars)
{
// A looser notion of side-effect-freeness with respect to a given
// list of variables.
// That's useful because the written list may consist of local
// variables of called functions. But visible side-effects only
// occur if the client's locals, or any globals are written-to.
set<vardecl*> intersection;
insert_iterator<set<vardecl*> > int_it (intersection, intersection.begin());
set_intersection (written.begin(), written.end(),
vars.begin(), vars.end(),
int_it);
return (intersection.empty() && !embedded_seen);
}
// ------------------------------------------------------------------------
throwing_visitor::throwing_visitor (const std::string& m): msg (m) {}
throwing_visitor::throwing_visitor (): msg (_("invalid element")) {}
void
throwing_visitor::throwone (const token* t)
{
throw SEMANTIC_ERROR (msg, t);
}
void
throwing_visitor::visit_block (block* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_try_block (try_block* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_embeddedcode (embeddedcode* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_null_statement (null_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_expr_statement (expr_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_if_statement (if_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_for_loop (for_loop* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_foreach_loop (foreach_loop* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_return_statement (return_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_delete_statement (delete_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_next_statement (next_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_break_statement (break_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_continue_statement (continue_statement* s)
{
throwone (s->tok);
}
void
throwing_visitor::visit_literal_string (literal_string* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_literal_number (literal_number* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_embedded_expr (embedded_expr* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_binary_expression (binary_expression* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_unary_expression (unary_expression* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_pre_crement (pre_crement* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_post_crement (post_crement* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_logical_or_expr (logical_or_expr* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_logical_and_expr (logical_and_expr* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_array_in (array_in* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_regex_query (regex_query* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_comparison (comparison* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_concatenation (concatenation* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_ternary_expression (ternary_expression* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_assignment (assignment* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_symbol (symbol* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_target_symbol (target_symbol* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_atvar_op (atvar_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_cast_op (cast_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_autocast_op (autocast_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_defined_op (defined_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_entry_op (entry_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_perf_op (perf_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_arrayindex (arrayindex* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_functioncall (functioncall* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_print_format (print_format* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_stat_op (stat_op* e)
{
throwone (e->tok);
}
void
throwing_visitor::visit_hist_op (hist_op* e)
{
throwone (e->tok);
}
// ------------------------------------------------------------------------
void
update_visitor::visit_block (block* s)
{
for (unsigned i = 0; i < s->statements.size(); ++i)
replace (s->statements[i]);
provide (s);
}
void
update_visitor::visit_try_block (try_block* s)
{
replace (s->try_block);
replace (s->catch_error_var);
replace (s->catch_block);
provide (s);
}
void
update_visitor::visit_embeddedcode (embeddedcode* s)
{
provide (s);
}
void
update_visitor::visit_null_statement (null_statement* s)
{
provide (s);
}
void
update_visitor::visit_expr_statement (expr_statement* s)
{
replace (s->value);
provide (s);
}
void
update_visitor::visit_if_statement (if_statement* s)
{
replace (s->condition);
replace (s->thenblock);
replace (s->elseblock);
provide (s);
}
void
update_visitor::visit_for_loop (for_loop* s)
{
replace (s->init);
replace (s->cond);
replace (s->incr);
replace (s->block);
provide (s);
}
void
update_visitor::visit_foreach_loop (foreach_loop* s)
{
for (unsigned i = 0; i < s->indexes.size(); ++i)
replace (s->indexes[i]);
replace (s->base);
replace (s->value);
replace (s->limit);
replace (s->block);
provide (s);
}
void
update_visitor::visit_return_statement (return_statement* s)
{
replace (s->value);
provide (s);
}
void
update_visitor::visit_delete_statement (delete_statement* s)
{
replace (s->value);
provide (s);
}
void
update_visitor::visit_next_statement (next_statement* s)
{
provide (s);
}
void
update_visitor::visit_break_statement (break_statement* s)
{
provide (s);
}
void
update_visitor::visit_continue_statement (continue_statement* s)
{
provide (s);
}
void
update_visitor::visit_literal_string (literal_string* e)
{
provide (e);
}
void
update_visitor::visit_literal_number (literal_number* e)
{
provide (e);
}
void
update_visitor::visit_embedded_expr (embedded_expr* e)
{
provide (e);
}
void
update_visitor::visit_binary_expression (binary_expression* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_unary_expression (unary_expression* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_pre_crement (pre_crement* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_post_crement (post_crement* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_logical_or_expr (logical_or_expr* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_logical_and_expr (logical_and_expr* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_array_in (array_in* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_regex_query (regex_query* e)
{
replace (e->left);
replace (e->right); // XXX: do we *need* to replace literal in RHS?
provide (e);
}
void
update_visitor::visit_comparison (comparison* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_concatenation (concatenation* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_ternary_expression (ternary_expression* e)
{
replace (e->cond);
replace (e->truevalue);
replace (e->falsevalue);
provide (e);
}
void
update_visitor::visit_assignment (assignment* e)
{
replace (e->left);
replace (e->right);
provide (e);
}
void
update_visitor::visit_symbol (symbol* e)
{
provide (e);
}
void
update_visitor::visit_target_symbol (target_symbol* e)
{
e->visit_components (this);
provide (e);
}
void
update_visitor::visit_cast_op (cast_op* e)
{
replace (e->operand);
e->visit_components (this);
provide (e);
}
void
update_visitor::visit_autocast_op (autocast_op* e)
{
replace (e->operand);
e->visit_components (this);
provide (e);
}
void
update_visitor::visit_atvar_op (atvar_op* e)
{
e->visit_components (this);
provide (e);
}
void
update_visitor::visit_defined_op (defined_op* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_entry_op (entry_op* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_perf_op (perf_op* e)
{
replace (e->operand);
provide (e);
}
void
update_visitor::visit_arrayindex (arrayindex* e)
{
replace (e->base);
for (unsigned i = 0; i < e->indexes.size(); ++i)
replace (e->indexes[i]);
provide (e);
}
void
update_visitor::visit_functioncall (functioncall* e)
{
for (unsigned i = 0; i < e->args.size(); ++i)
replace (e->args[i]);
provide (e);
}
void
update_visitor::visit_print_format (print_format* e)
{
for (unsigned i = 0; i < e->args.size(); ++i)
replace (e->args[i]);
replace (e->hist);
provide (e);
}
void
update_visitor::visit_stat_op (stat_op* e)
{
replace (e->stat);
provide (e);
}
void
update_visitor::visit_hist_op (hist_op* e)
{
replace (e->stat);
provide (e);
}
// ------------------------------------------------------------------------
void
deep_copy_visitor::visit_block (block* s)
{
update_visitor::visit_block(new block(*s));
}
void
deep_copy_visitor::visit_try_block (try_block* s)
{
update_visitor::visit_try_block(new try_block(*s));
}
void
deep_copy_visitor::visit_embeddedcode (embeddedcode* s)
{
update_visitor::visit_embeddedcode(new embeddedcode(*s));
}
void
deep_copy_visitor::visit_null_statement (null_statement* s)
{
update_visitor::visit_null_statement(new null_statement(*s));
}
void
deep_copy_visitor::visit_expr_statement (expr_statement* s)
{
update_visitor::visit_expr_statement(new expr_statement(*s));
}
void
deep_copy_visitor::visit_if_statement (if_statement* s)
{
update_visitor::visit_if_statement(new if_statement(*s));
}
void
deep_copy_visitor::visit_for_loop (for_loop* s)
{
update_visitor::visit_for_loop(new for_loop(*s));
}
void
deep_copy_visitor::visit_foreach_loop (foreach_loop* s)
{
update_visitor::visit_foreach_loop(new foreach_loop(*s));
}
void
deep_copy_visitor::visit_return_statement (return_statement* s)
{
update_visitor::visit_return_statement(new return_statement(*s));
}
void
deep_copy_visitor::visit_delete_statement (delete_statement* s)
{
update_visitor::visit_delete_statement(new delete_statement(*s));
}
void
deep_copy_visitor::visit_next_statement (next_statement* s)
{
update_visitor::visit_next_statement(new next_statement(*s));
}
void
deep_copy_visitor::visit_break_statement (break_statement* s)
{
update_visitor::visit_break_statement(new break_statement(*s));
}
void
deep_copy_visitor::visit_continue_statement (continue_statement* s)
{
update_visitor::visit_continue_statement(new continue_statement(*s));
}
void
deep_copy_visitor::visit_literal_string (literal_string* e)
{
update_visitor::visit_literal_string(new literal_string(*e));
}
void
deep_copy_visitor::visit_literal_number (literal_number* e)
{
update_visitor::visit_literal_number(new literal_number(*e));
}
void
deep_copy_visitor::visit_embedded_expr (embedded_expr* e)
{
update_visitor::visit_embedded_expr(new embedded_expr(*e));
}
void
deep_copy_visitor::visit_binary_expression (binary_expression* e)
{
update_visitor::visit_binary_expression(new binary_expression(*e));
}
void
deep_copy_visitor::visit_unary_expression (unary_expression* e)
{
update_visitor::visit_unary_expression(new unary_expression(*e));
}
void
deep_copy_visitor::visit_pre_crement (pre_crement* e)
{
update_visitor::visit_pre_crement(new pre_crement(*e));
}
void
deep_copy_visitor::visit_post_crement (post_crement* e)
{
update_visitor::visit_post_crement(new post_crement(*e));
}
void
deep_copy_visitor::visit_logical_or_expr (logical_or_expr* e)
{
update_visitor::visit_logical_or_expr(new logical_or_expr(*e));
}
void
deep_copy_visitor::visit_logical_and_expr (logical_and_expr* e)
{
update_visitor::visit_logical_and_expr(new logical_and_expr(*e));
}
void
deep_copy_visitor::visit_array_in (array_in* e)
{
update_visitor::visit_array_in(new array_in(*e));
}
void
deep_copy_visitor::visit_regex_query (regex_query* e)
{
update_visitor::visit_regex_query(new regex_query(*e));
}
void
deep_copy_visitor::visit_comparison (comparison* e)
{
update_visitor::visit_comparison(new comparison(*e));
}
void
deep_copy_visitor::visit_concatenation (concatenation* e)
{
update_visitor::visit_concatenation(new concatenation(*e));
}
void
deep_copy_visitor::visit_ternary_expression (ternary_expression* e)
{
update_visitor::visit_ternary_expression(new ternary_expression(*e));
}
void
deep_copy_visitor::visit_assignment (assignment* e)
{
update_visitor::visit_assignment(new assignment(*e));
}
void
deep_copy_visitor::visit_symbol (symbol* e)
{
symbol* n = new symbol(*e);
n->referent = NULL; // don't copy!
update_visitor::visit_symbol(n);
}
void
deep_copy_visitor::visit_target_symbol (target_symbol* e)
{
target_symbol* n = new target_symbol(*e);
update_visitor::visit_target_symbol(n);
}
void
deep_copy_visitor::visit_cast_op (cast_op* e)
{
update_visitor::visit_cast_op(new cast_op(*e));
}
void
deep_copy_visitor::visit_autocast_op (autocast_op* e)
{
update_visitor::visit_autocast_op(new autocast_op(*e));
}
void
deep_copy_visitor::visit_atvar_op (atvar_op* e)
{
update_visitor::visit_atvar_op(new atvar_op(*e));
}
void
deep_copy_visitor::visit_defined_op (defined_op* e)
{
update_visitor::visit_defined_op(new defined_op(*e));
}
void
deep_copy_visitor::visit_entry_op (entry_op* e)
{
update_visitor::visit_entry_op(new entry_op(*e));
}
void
deep_copy_visitor::visit_perf_op (perf_op* e)
{
update_visitor::visit_perf_op(new perf_op(*e));
}
void
deep_copy_visitor::visit_arrayindex (arrayindex* e)
{
update_visitor::visit_arrayindex(new arrayindex(*e));
}
void
deep_copy_visitor::visit_functioncall (functioncall* e)
{
functioncall* n = new functioncall(*e);
n->referents.clear(); // don't copy!
update_visitor::visit_functioncall(n);
}
void
deep_copy_visitor::visit_print_format (print_format* e)
{
update_visitor::visit_print_format(new print_format(*e));
}
void
deep_copy_visitor::visit_stat_op (stat_op* e)
{
update_visitor::visit_stat_op(new stat_op(*e));
}
void
deep_copy_visitor::visit_hist_op (hist_op* e)
{
update_visitor::visit_hist_op(new hist_op(*e));
}
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
|