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
|
/***************************************************************************
* Copyright (C) 1999 by Jonas Nordin *
* jonas.nordin@syncom.se *
* Copyright (C) 2000-2001 by Bernd Gehrmann *
* bernd@kdevelop.org *
* Copyright (C) 2002-2003 by Roberto Raggi *
* roberto@kdevelop.org *
* Copyright (C) 2003-2004 by Alexander Dymo *
* adymo@mksat.net *
* *
* 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. *
* *
***************************************************************************/
#include "cppsupportpart.h"
#include "cppsupport_events.h"
#include "problemreporter.h"
#include "backgroundparser.h"
#include "store_walker.h"
#include "ast.h"
#include "ast_utils.h"
#include "cppcodecompletion.h"
#include "ccconfigwidget.h"
#include "KDevCppSupportIface.h"
#include "cppsupportfactory.h"
#include "catalog.h"
#include "cpp_tags.h"
#include "kdevdriver.h"
#include "cppcodecompletionconfig.h"
#include "cppsplitheadersourceconfig.h"
#include "tag_creator.h"
#include "cppsupport_utils.h"
#include "classgeneratorconfig.h"
#include "urlutil.h"
#include "creategettersetterconfiguration.h"
#include "kdevsourceformatter.h"
#include "kdevcreatefile.h"
#include "qtbuildconfig.h"
#include "kdeveditorutil.h"
#include <ktexteditor/viewcursorinterface.h>
#include <kpopupmenu.h>
// wizards
#include "cppnewclassdlg.h"
#include "subclassingdlg.h"
#include "addmethoddialog.h"
#include "addattributedialog.h"
#include "creategettersetterdialog.h"
// designer integration
#include "qtdesignercppintegration.h"
#include "cppimplementationwidget.h"
#include "configproblemreporter.h"
#include "codeinformationrepository.h"
#include <qeventloop.h>
#include <qheader.h>
#include <qdir.h>
#include <qdom.h>
#include <qfileinfo.h>
#include <qguardedptr.h>
#include <qpopupmenu.h>
#include <qprogressdialog.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <qstatusbar.h>
#include <qprogressbar.h>
#include <qregexp.h>
#include <qlabel.h>
#include <qvbox.h>
#include <kmessagebox.h>
#include <kaction.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kdialogbase.h>
#include <kgenericfactory.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmainwindow.h>
#include <kstatusbar.h>
#include <kconfig.h>
#include <kdeversion.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <ktexteditor/document.h>
#include <ktexteditor/editinterface.h>
#include <ktexteditor/view.h>
#include <ktexteditor/selectioninterface.h>
#include <ktexteditor/viewcursorinterface.h>
#include <ktexteditor/clipboardinterface.h>
#include <ktexteditor/texthintinterface.h>
#include <kdevcore.h>
#include <kdevproject.h>
#include <kdevmainwindow.h>
#include <kdevpartcontroller.h>
#include <kdevmakefrontend.h>
#include <kdevcoderepository.h>
#include <codemodel_utils.h>
#include <kdevplugininfo.h>
#include <domutil.h>
#include <config.h>
const bool alwaysParseInBackground = true;
enum { KDEV_DB_VERSION = 21 };
enum { KDEV_PCS_VERSION = 18 };
QStringList CppSupportPart::m_sourceMimeTypes = QStringList() << "text/x-csrc" << "text/x-c++src";
QStringList CppSupportPart::m_headerMimeTypes = QStringList() << "text/x-chdr" << "text/x-c++hdr";
QStringList CppSupportPart::m_sourceExtensions = QStringList::split( ",", "c,C,cc,cpp,c++,cxx,m,mm,M" );
QStringList CppSupportPart::m_headerExtensions = QStringList::split( ",", "h,H,hh,h++,hxx,hpp,inl,tlh,diff,ui.h" );
class CppDriver: public KDevDriver
{
public:
CppDriver( CppSupportPart* cppSupport ) : KDevDriver( cppSupport, true )
{}
void fileParsed( ParsedFile& fileName )
{
//kdDebug(9007) << "-----> file " << fileName << " parsed!" << endl;
ParsedFilePointer ast = takeTranslationUnit( fileName.fileName() );
if ( cppSupport() ->problemReporter() )
{
cppSupport() ->problemReporter() ->removeAllProblems( fileName.fileName() );
QValueList<Problem> pl = problems( fileName.fileName() );
QValueList<Problem>::ConstIterator it = pl.begin();
while ( it != pl.end() )
{
const Problem & p = *it++;
cppSupport() ->problemReporter() ->reportProblem( fileName.fileName(), p );
}
}
StoreWalker walker( fileName.fileName(), cppSupport() ->codeModel() );
if ( cppSupport() ->codeModel() ->hasFile( fileName.fileName() ) )
{
FileDom file = cppSupport() ->codeModel() ->fileByName( fileName.fileName() );
cppSupport() ->removeWithReferences( fileName.fileName() );
}
walker.parseTranslationUnit( *ast );
cppSupport() ->codeModel() ->addFile( walker.file() );
remove
( fileName.fileName() );
if( cppSupport()->_jd ) {
cppSupport()->_jd->backgroundState ++;
cppSupport()->_jd->lastParse = QTime::currentTime();
}
QFileInfo fileInfo( fileName.fileName() );
QString path = URLUtil::canonicalPath( fileName.fileName() );
cppSupport()->m_timestamp[ path ] = fileInfo.lastModified();
cppSupport()->emitSynchronousParseReady( fileName.fileName(), ast );
}
};
// ProblemReporter doesn't really depend on background parsing, so it's a bit of a mixup to
// handle them together, but it's the same config widget so...
class BackgroundParserConfig
{
bool m_useProblemReporter;
bool m_useBackgroundParser;
int m_backgroundParseDelay;
public:
void readConfig()
{
KConfig* config = kapp->config();
config->setGroup( "General Options" );
m_useProblemReporter = config->readBoolEntry( "EnableProblemReporter", true );
m_useBackgroundParser = config->readBoolEntry( "EnableCppBgParser", true );
m_backgroundParseDelay = config->readNumEntry( "BgParserDelay", 500 );
}
bool useProblemReporter() { return m_useProblemReporter; }
bool useBackgroundParser() { return m_useBackgroundParser; }
int backgroudParseDelay() { return m_backgroundParseDelay; }
};
CppSupportPart::CppSupportPart( QObject *parent, const char *name, const QStringList &args )
: KDevLanguageSupport( CppSupportFactory::info(), parent, name ? name : "KDevCppSupport" ), m_backgroundParser(0),
m_activeDocument( 0 ), m_activeView( 0 ), m_activeSelection( 0 ), m_activeEditor( 0 ), m_activeViewCursor( 0 ),
m_projectClosed( true ), m_projectClosing( false ), m_valid( false ), m_isTyping( false ), m_hadErrors( false ),
_jd(0)
{
setInstance( CppSupportFactory::instance() );
m_pCompletionConfig = new CppCodeCompletionConfig( this, projectDom() );
m_pSplitHeaderSourceConfig = new CppSplitHeaderSourceConfig( this, projectDom() );
m_pCreateGetterSetterConfiguration = new CreateGetterSetterConfiguration( this ); connect( m_pSplitHeaderSourceConfig, SIGNAL( stored() ),
this, SLOT( splitHeaderSourceConfigStored() ) );
connect( m_pCompletionConfig, SIGNAL( stored() ),
this, SLOT( codeCompletionConfigStored() ) );
m_qtBuildConfig = new QtBuildConfig( this, projectDom() );
m_qtBuildConfig->store();
m_backgroundParserConfig = new BackgroundParserConfig;
m_backgroundParserConfig->readConfig();
m_driver = new CppDriver( this );
m_problemReporter = 0;
m_textChangedTimer = new QTimer( this );
connect( m_textChangedTimer, SIGNAL(timeout()), this, SLOT(slotParseCurrentFile()) );
m_cursorMovedTimer = new QTimer( this );
connect( m_cursorMovedTimer, SIGNAL(timeout()), this, SLOT(slotCursorPositionChanged()) );
// m_deleteParserStoreTimer = new QTimer( this );
m_saveMemoryTimer = new QTimer( this );
m_buildSafeFileSetTimer = new QTimer( this );
// m_functionHintTimer = new QTimer( this );
connect( m_buildSafeFileSetTimer, SIGNAL(timeout()), this, SLOT(buildSafeFileSet()) );
connect( m_saveMemoryTimer, SIGNAL(timeout()), this, SLOT(slotSaveMemory()) );
// connect( m_deleteParserStoreTimer, SIGNAL(timeout()), this, SLOT(slotDeleteParserStore()) );
resetParserStoreTimer();
m_saveMemoryTimer->start( 240000, false ); //Free some memory every 4 minutes
// connect( m_functionHintTimer, SIGNAL(timeout()), this, SLOT(slotFunctionHint()) );
setXMLFile( "kdevcppsupport.rc" );
m_catalogList.setAutoDelete( true );
connect( core(), SIGNAL( projectOpened() ), this, SLOT( projectOpened() ) );
connect( core(), SIGNAL( projectClosed() ), this, SLOT( projectClosed() ) );
connect( core(), SIGNAL( languageChanged() ), this, SLOT( projectOpened() ) );
connect( partController(), SIGNAL( savedFile( const KURL& ) ),
this, SLOT( savedFile( const KURL& ) ) );
connect( core(), SIGNAL( contextMenu( QPopupMenu *, const Context * ) ),
this, SLOT( contextMenu( QPopupMenu *, const Context * ) ) );
connect( partController(), SIGNAL( activePartChanged( KParts::Part* ) ),
this, SLOT( activePartChanged( KParts::Part* ) ) );
connect( partController(), SIGNAL( partRemoved( KParts::Part* ) ),
this, SLOT( partRemoved( KParts::Part* ) ) );
connect( core(), SIGNAL( configWidget( KDialogBase* ) ),
this, SLOT( configWidget( KDialogBase* ) ) );
m_switchHeaderSourceAction = new KAction( i18n( "Switch Header/Implementation" ), SHIFT + Key_F12,
this, SLOT( slotSwitchHeader() ),
actionCollection(), "edit_switchheader" );
m_switchHeaderSourceAction->setToolTip( i18n( "Switch between header and implementation files" ) );
m_switchHeaderSourceAction->setWhatsThis( i18n( "<b>Switch Header/Implementation</b><p>"
"If you are currently looking at a header file, this "
"brings you to the corresponding implementation file. "
"If you are looking at an implementation file (.cpp etc.), "
"this brings you to the corresponding header file." ) );
m_switchHeaderSourceAction->setEnabled( false );
KAction *action;
action = new KAction( i18n( "Complete Text" ), CTRL + Key_Space,
this, SLOT( slotCompleteText() ),
actionCollection(), "edit_complete_text" );
action->setToolTip( i18n( "Complete current expression" ) );
action->setWhatsThis( i18n( "<b>Complete Text</p><p>Completes current expression using "
"memory class store for the current project and persistent class stores "
"for external libraries." ) );
action->setEnabled( false );
m_createGetterSetterAction = new KAction( i18n( "Create Accessor Methods" ), 0,
this, SLOT( slotCreateAccessMethods() ), actionCollection(),
"edit_create_getter_setter" );
action = new KAction( i18n( "Make Member" ), 0, Key_F2,
this, SLOT( slotMakeMember() ),
actionCollection(), "edit_make_member" );
action->setToolTip( i18n( "Make member" ) );
action->setWhatsThis( i18n( "<b>Make member</b><p>Creates a class member function in implementation file "
"based on the member declaration at the current line." ) );
action->plug( &m_DummyActionWidget );
action = new KAction( i18n( "Navigation Menu" ), 0, CTRL + ALT + Key_Space,
this, SLOT( slotNavigate() ),
actionCollection(), "edit_navigate" );
action->setToolTip( i18n( "Show the navigation-menu" ) );
action->setWhatsThis( i18n( "<b>Navigate</b><p>Shows a navigation-menu based on the type-evaluation of the item under the cursor." ) );
action->plug( &m_DummyActionWidget );
action = new KAction( i18n( "New Class..." ), "classnew", 0,
this, SLOT( slotNewClass() ),
actionCollection(), "project_newclass" );
action->setToolTip( i18n( "Generate a new class" ) );
action->setWhatsThis( i18n( "<b>New Class</b><p>Calls the <b>New Class</b> wizard." ) );
m_pCompletion = 0;
withcpp = false;
if ( args.count() == 1 && args[ 0 ] == "Cpp" )
withcpp = true;
// daniel
connect( core( ), SIGNAL( projectConfigWidget( KDialogBase* ) ), this,
SLOT( projectConfigWidget( KDialogBase* ) ) );
new KDevCppSupportIface( this );
//(void) dcopClient();
m_lockupTester = new UIBlockTester( 100 );
}
CppSupportPart::~CppSupportPart()
{
delete m_lockupTester;
if ( !m_projectClosed )
projectClosed();
delete( m_driver );
m_driver = 0;
if ( m_backgroundParser )
{
m_backgroundParser->close();
// m_backgroundParser->wait();
delete m_backgroundParser;
m_backgroundParser = 0;
}
codeRepository() ->setMainCatalog( 0 );
QPtrListIterator<Catalog> it( m_catalogList );
while ( Catalog * catalog = it.current() )
{
++it;
codeRepository() ->unregisterCatalog( catalog );
}
delete m_backgroundParserConfig;
m_backgroundParserConfig = 0;
delete m_pCompletion;
m_pCompletion = 0;
/* mainWindow()->removeView( m_problemReporter );
delete m_problemReporter;
m_problemReporter = 0;
*/
delete _jd;
_jd = 0;
kdDebug( 9007 ) << k_funcinfo << endl;
}
void CppSupportPart::customEvent( QCustomEvent* ev )
{
kdDebug( 9007 ) << "CppSupportPart::customEvent(" << ev->type() << ")" << endl;
QTime t;
t.start();
bool fromDisk = false;
if ( ev->type() == int( Event_FileParsed ) )
{
resetParserStoreTimer();
FileParsedEvent * event = ( FileParsedEvent* ) ev;
fromDisk = event->fromDisk();
QString fileName = event->fileName();
bool hasErrors = false;
if ( m_problemReporter )
{
m_problemReporter->removeAllProblems( fileName );
QValueList<Problem> problems = event->problems();
QValueList<Problem>::ConstIterator it = problems.begin();
while ( it != problems.end() )
{
const Problem & p = *it++;
if ( p.level() == Problem::Level_Error )
hasErrors = true;
m_problemReporter->reportProblem( fileName, p );
}
}
ParsedFilePointer p = m_backgroundParser->translationUnit( fileName );
if( p && !p->includedFrom().isEmpty() ) {
kdDebug( 9007 ) << "customEvent() parsed included file \"" << fileName << "\" included from \"" << p->includedFrom() << "\"" << endl;
} else {
kdDebug( 9007 ) << "customEvent() parsed file \"" << fileName << "\"" << endl;
}
if( p && !p->includedFrom().isEmpty() ) {
if( !project()->isProjectFile( fileName ) ) {
//The file was parsed to resolve a dependency, and is not a project file
addToRepository( p );
} else {
//It is a project-file that was parsed for whatever reason to resolve a dependency(currently it isn't handled this way)
}
} else if( !project()->isProjectFile( fileName ) || !m_parseEmitWaiting.reject( fileName ) ) {
ParseEmitWaiting::Processed p = m_parseEmitWaiting.processFile( fileName, ( !m_hadErrors && hasErrors && !fromDisk && m_isTyping && fileName == m_activeFileName ) ? ParseEmitWaiting::HadErrors : ParseEmitWaiting::None );
parseEmit( p );
//Increase status-bar
if( p.hasFlag( ParseEmitWaiting::Silent ) && _jd ) {
_jd->backgroundState ++;
_jd->lastParse = QTime::currentTime();
}
} else {
ParseEmitWaiting::Processed p = m_fileParsedEmitWaiting.processFile( fileName );
if( !p.hasFlag( ParseEmitWaiting::Silent ) )
emitFileParsed( p );
//Increase status-bar
if( p.hasFlag( ParseEmitWaiting::Silent ) && _jd ) {
_jd->backgroundState ++;
_jd->lastParse = QTime::currentTime();
}
}
}
}
void CppSupportPart::projectConfigWidget( KDialogBase* dlg )
{
QVBox * vbox = 0;
vbox = dlg->addVBoxPage( i18n( "C++ Support" ), i18n( "C++ Support" ),
BarIcon( info() ->icon(), KIcon::SizeMedium ) );
CCConfigWidget* w = new CCConfigWidget( this, vbox );
connect( dlg, SIGNAL( okClicked( ) ), w, SLOT( accept( ) ) );
}
void CppSupportPart::configWidget( KDialogBase *dlg )
{
QVBox * vbox = dlg->addVBoxPage( i18n( "C++ Class Generator" ), i18n( "C++ Class Generator" ),
BarIcon( info() ->icon(), KIcon::SizeMedium ) );
ClassGeneratorConfig *w = new ClassGeneratorConfig( vbox, "classgenerator config widget" );
connect( dlg, SIGNAL( okClicked() ), w, SLOT( storeConfig() ) );
vbox = dlg->addVBoxPage(i18n("C++ Parsing"), i18n("C++ Parsing"),
BarIcon( "source_cpp", KIcon::SizeMedium) );
ConfigureProblemReporter* ww = new ConfigureProblemReporter( vbox );
ww->setPart( this );
connect(dlg, SIGNAL(okClicked()), ww, SLOT(accept()));
}
void CppSupportPart::activePartChanged( KParts::Part *part )
{
kdDebug( 9032 ) << "CppSupportPart::activePartChanged()" << endl;
bool enabled = false;
// m_functionHintTimer->stop();
if ( m_activeView )
{
disconnect( m_activeView, SIGNAL( cursorPositionChanged() ), this, 0 );
}
if ( m_activeDocument )
{
disconnect( m_activeDocument, SIGNAL(textChanged()), this, 0 );
}
m_isTyping = false;
m_hadErrors = true;
m_activeDocument = dynamic_cast<KTextEditor::Document*>( part );
m_activeView = part ? dynamic_cast<KTextEditor::View*>( part->widget() ) : 0;
m_activeEditor = dynamic_cast<KTextEditor::EditInterface*>( part );
m_activeSelection = dynamic_cast<KTextEditor::SelectionInterface*>( part );
m_activeViewCursor = dynamic_cast<KTextEditor::ViewCursorInterface*>( m_activeView );
m_activeFileName = QString::null;
if ( m_activeDocument )
{
m_activeFileName = URLUtil::canonicalPath( m_activeDocument->url().path() );
QFileInfo fi( m_activeFileName );
QString ext = fi.extension();
if ( isSource( m_activeFileName ) || isHeader( m_activeFileName ) )
enabled = true;
}
actionCollection() ->action( "edit_switchheader" ) ->setEnabled( enabled );
actionCollection() ->action( "edit_complete_text" ) ->setEnabled( enabled );
actionCollection() ->action( "edit_make_member" ) ->setEnabled( enabled );
if ( !part || !part->widget() )
return ;
if ( m_activeDocument )
{
connect( m_activeDocument, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) );
m_textChangedTimer->start( 250, true ); // kick the parse timer, we might want to parse the current file
}
if ( m_activeViewCursor )
{
connect( m_activeView, SIGNAL( cursorPositionChanged() ), this, SLOT(slotCursorMoved()) );
// this, SLOT( slotCursorPositionChanged() ) );
}
#if 0
KTextEditor::TextHintInterface* textHintIface = dynamic_cast<KTextEditor::TextHintInterface*>( m_activeView );
if ( !textHintIface )
return ;
connect( view, SIGNAL( needTextHint( int, int, QString& ) ),
this, SLOT( slotNeedTextHint( int, int, QString& ) ) );
textHintIface->enableTextHints( 1000 );
#endif
}
void CppSupportPart::setTyping( bool typing ) {
m_isTyping = typing;
if( m_problemReporter) {
m_hadErrors &= m_problemReporter->hasErrors(m_activeFileName);///m_hadErrors generally stores whether there was an error-free state of the file.
}
}
void CppSupportPart::projectOpened( )
{
kdDebug( 9007 ) << "projectOpened( )" << endl;
m_backgroundParser = new BackgroundParser( this, &m_eventConsumed );
m_backgroundParser->start( QThread::IdlePriority );
// setup the driver
QString conf_file_name = specialHeaderName();
if ( QFile::exists( conf_file_name ) )
m_driver->parseFile( conf_file_name, true, true, true );
m_projectDirectory = URLUtil::canonicalPath( project() ->projectDirectory() );
m_projectFileList = project() ->allFiles();
setupCatalog();
embedProblemReporter();
connect( core(), SIGNAL( configWidget( KDialogBase* ) ),
m_problemReporter, SLOT( configWidget( KDialogBase* ) ) );
connect( project( ), SIGNAL( addedFilesToProject( const QStringList & ) ),
this, SLOT( addedFilesToProject( const QStringList & ) ) );
connect( project( ), SIGNAL( removedFilesFromProject( const QStringList & ) ),
this, SLOT( removedFilesFromProject( const QStringList & ) ) );
connect( project( ), SIGNAL( changedFilesInProject( const QStringList & ) ),
this, SLOT( changedFilesInProject( const QStringList & ) ) );
connect( project(), SIGNAL( projectCompiled() ),
this, SLOT( slotProjectCompiled() ) );
m_timestamp.clear();
m_parseEmitWaiting.clear();
m_fileParsedEmitWaiting.clear();
m_pCompletion = new CppCodeCompletion( this );
m_projectClosed = false;
m_buildSafeFileSetTimer->start( 500, true );
updateParserConfiguration(); //Necessary to respect custom include-paths and such
QTimer::singleShot( 500, this, SLOT( initialParse( ) ) );
}
void CppSupportPart::embedProblemReporter( bool force )
{
if ( force || m_backgroundParserConfig->useProblemReporter() )
{
m_problemReporter = new ProblemReporter( this, 0, "problemReporterWidget" );
m_problemReporter->setIcon( SmallIcon( "info" ) );
m_problemReporter->setCaption( i18n( "Problem Reporter" ) );
mainWindow( ) ->embedOutputView( m_problemReporter, i18n( "Problems" ), i18n( "Problem reporter" ) );
}
}
void CppSupportPart::removeProblemReporter()
{
mainWindow()->removeView( m_problemReporter );
delete m_problemReporter;
m_problemReporter = 0;
}
void CppSupportPart::projectClosed( )
{
kdDebug( 9007 ) << "projectClosed( )" << endl;
m_projectClosing = true;
QStringList enabledPCSs;
QValueList<Catalog*> catalogs = codeRepository() ->registeredCatalogs();
for ( QValueList<Catalog*>::Iterator it = catalogs.begin(); it != catalogs.end(); ++it )
{
Catalog* c = *it;
if ( c->enabled() )
enabledPCSs.push_back( QFileInfo( c->dbName() ).baseName(true) );
}
DomUtil::writeListEntry( *project() ->projectDom(), "kdevcppsupport/references", "pcs", enabledPCSs );
for ( QMap<KInterfaceDesigner::DesignerType, KDevDesignerIntegration*>::const_iterator it = m_designers.begin();
it != m_designers.end(); ++it )
{
kdDebug( 9007 ) << "calling save settings fro designer integration" << endl;
it.data() ->saveSettings( *project() ->projectDom(), "kdevcppsupport/designerintegration" );
}
saveProjectSourceInfo();
m_pCompletionConfig->store();
delete _jd;
_jd = 0;
removeProblemReporter();
delete m_pCompletion;
m_parseEmitWaiting.clear();
m_fileParsedEmitWaiting.clear();
m_pCompletion = 0;
m_projectClosed = true;
m_projectClosing = false;
}
void CppSupportPart::slotNavigate() {
if( codeCompletion() && m_activeView && m_activeViewCursor ) {
unsigned int curLine = 0, curCol = 0;
m_activeViewCursor->cursorPositionReal( &curLine, &curCol );
if( m_navigationMenu ) delete (KPopupMenu*)m_navigationMenu;
m_navigationMenu = new KPopupMenu( m_activeView );
codeCompletion()->contextEvaluationMenus( m_navigationMenu, 0, curLine, curCol );
m_navigationMenu->move( m_activeView->mapToGlobal( m_activeViewCursor->cursorCoordinates() ) );
if ( m_navigationMenu->count() > 0 )
{
m_navigationMenu->show();
}
}
}
void CppSupportPart::contextMenu( QPopupMenu *popup, const Context *context )
{
m_activeClass = 0;
m_activeFunction = 0;
m_activeVariable = 0;
m_curAttribute = 0;
m_curClass = 0;
if ( context->hasType( Context::EditorContext ) )
{
int id;
m_switchHeaderSourceAction->plug( popup );
// CodeModelItemContext
if ( context->type() == Context::EditorContext )
{
m_curClass = currentClass();
if ( m_curClass != 0 )
{
m_curAttribute = currentAttribute( m_curClass );
if ( m_curAttribute != 0 )
m_createGetterSetterAction->plug( popup );
}
}
QString text;
int atline, atcol;
MakeMemberHelper( text, atline, atcol );
if ( !text.isEmpty() )
{
id = popup->insertItem( i18n( "Make Member" ), this, SLOT( slotMakeMember() ) );
popup->setWhatsThis( id, i18n( "<b>Make member</b><p>Creates a class member function in implementation file "
"based on the member declaration at the current line." ) );
}
kdDebug( 9007 ) << "======> code model has the file: " << m_activeFileName << " = " << codeModel() ->hasFile( m_activeFileName ) << endl;
bool showContextMenuExplosion = false;
bool showContextTypeEvaluation = false;
KConfig *config = CppSupportFactory::instance() ->config();
if ( config )
{
config->setGroup( "General" );
showContextMenuExplosion = config->readBoolEntry( "ShowContextMenuExplosion", false );
config->setGroup( "General" );
showContextTypeEvaluation = config->readBoolEntry( "ShowContextTypeEvaluation", true );
}
if( codeModel() ->hasFile( m_activeFileName ) ) {
if( showContextTypeEvaluation && m_activeViewCursor != 0 ) {
if( codeCompletion() ) {
unsigned int curLine = 0, curCol = 0;
m_activeViewCursor->cursorPositionReal( &curLine, &curCol );
codeCompletion()->contextEvaluationMenus( popup, context, curLine, curCol );
}
}
if ( showContextMenuExplosion )
{
//kdDebug( 9007 ) << "CppSupportPart::contextMenu 1" << endl;
QString candidate;
if ( isSource( m_activeFileName ) )
candidate = sourceOrHeaderCandidate();
else
candidate = m_activeFileName;
unsigned int curLine = 0, curCol = 0;
if ( m_activeViewCursor != 0 )
m_activeViewCursor->cursorPositionReal( &curLine, &curCol );
//kdDebug( 9007 ) << "CppSupportPart::contextMenu 2: candidate: " << candidate << endl;
if ( !candidate.isEmpty() && codeModel() ->hasFile( candidate ) )
{
QPopupMenu * m2 = new QPopupMenu( popup );
id = popup->insertItem( i18n( "Go to Declaration" ), m2 );
popup->setWhatsThis( id, i18n( "<b>Go to declaration</b><p>Provides a menu to select available function declarations "
"in the current file and in the corresponding header (if the current file is an implementation) or source (if the current file is a header) file." ) );
FileDom file2 = codeModel() ->fileByName( candidate );
//kdDebug( 9007 ) << "CppSupportPart::contextMenu 3: " << file2->name() << endl;
FunctionList functionList2 = CodeModelUtils::allFunctions( file2 );
for ( FunctionList::ConstIterator it = functionList2.begin(); it != functionList2.end(); ++it )
{
QString text = ( *it ) ->scope().join( "::" );
//kdDebug( 9007 ) << "CppSupportPart::contextMenu 3 text: " << text << endl;
if ( !text.isEmpty() )
{
text += "::";
}
text += formatModelItem( *it, true );
text = text.replace( QString::fromLatin1( "&" ), QString::fromLatin1( "&&" ) );
int id = m2->insertItem( text, this, SLOT( gotoDeclarationLine( int ) ) );
int line, column;
( *it ) ->getStartPosition( &line, &column );
m2->setItemParameter( id, line );
}
if ( m2->count() == 0 )
{
popup->removeItem( id );
}
//kdDebug( 9007 ) << "CppSupportPart::contextMenu 4" << endl;
}
QString candidate1;
if ( isHeader( m_activeFileName ) )
{
candidate1 = sourceOrHeaderCandidate();
}
else
{
candidate1 = m_activeFileName;
}
//kdDebug( 9007 ) << "CppSupportPart::go to definition in " << candidate1 << endl;
if ( codeModel() ->hasFile( candidate1 ) )
{
QPopupMenu * m = new QPopupMenu( popup );
id = popup->insertItem( i18n( "Go to Definition" ), m );
popup->setWhatsThis( id, i18n( "<b>Go to definition</b><p>Provides a menu to select available function definitions "
"in the current file and in the corresponding header (if the current file is an implementation) or source (if the current file is a header) file." ) );
const FileDom file = codeModel() ->fileByName( candidate1 );
const FunctionDefinitionList functionDefinitionList = CodeModelUtils::allFunctionDefinitionsDetailed( file ).functionList;
for ( FunctionDefinitionList::ConstIterator it = functionDefinitionList.begin(); it != functionDefinitionList.end(); ++it )
{
QString text = ( *it ) ->scope().join( "::" );
if ( !text.isEmpty() )
{
text += "::";
}
text += formatModelItem( *it, true );
text = text.replace( QString::fromLatin1( "&" ), QString::fromLatin1( "&&" ) );
int id = m->insertItem( text, this, SLOT( gotoLine( int ) ) );
int line, column;
( *it ) ->getStartPosition( &line, &column );
m->setItemParameter( id, line );
}
if ( m->count() == 0 )
{
popup->removeItem( id );
}
}
}
}
const EditorContext *econtext = static_cast<const EditorContext*>( context );
QString str = econtext->currentLine();
if ( str.isEmpty() )
return ;
}
else if ( context->hasType( Context::CodeModelItemContext ) )
{
const CodeModelItemContext * mcontext = static_cast<const CodeModelItemContext*>( context );
if ( mcontext->item() ->isClass() )
{
m_activeClass = ( ClassModel* ) mcontext->item();
int id = popup->insertItem( i18n( "Extract Interface..." ), this, SLOT( slotExtractInterface() ) );
popup->setWhatsThis( id, i18n( "<b>Extract interface</b><p>Extracts interface from the selected class and creates a new class with this interface. "
"No implementation code is extracted and no implementation code is created." ) );
}
else if ( mcontext->item() ->isFunction() )
{
m_activeFunction = ( FunctionModel* ) mcontext->item();
}
}
else if ( context->hasType( Context::FileContext ) )
{
const FileContext * fc = static_cast<const FileContext*>( context );
//this is a .ui file and only selection contains only one such file
KURL url = fc->urls().first();
kdDebug( 9007 ) << "file context with " << url.path() << endl;
if ( url.fileName().endsWith( ".ui" ) )
{
m_contextFileName = url.path();
int id = popup->insertItem( i18n( "Create or Select Implementation..." ), this, SLOT( slotCreateSubclass() ) );
popup->setWhatsThis( id, i18n( "<b>Create or select implementation</b><p>Creates or selects a subclass of selected form for use with integrated KDevDesigner." ) );
}
}
}
QStringList makeListUnique( const QStringList& rhs ) {
QMap<QString, bool> map;
QStringList ret;
for( QStringList::const_iterator it = rhs.begin(); it != rhs.end(); ++it ) {
if( map.find( *it ) == map.end() ) {
ret << *it;
map.insert( *it, true );
}
}
return ret;
}
// Makes sure that header files come first
QStringList CppSupportPart::reorder( const QStringList &list )
{
QStringList headers, others;
QStringList headerExtensions = QStringList::split( ",", "h,H,hh,hxx,hpp,tlh" );
QString projectPath = project()->projectDirectory();
QStringList::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it )
{
QString filePath = *it;
// brilliant stuff.. this method is apparently called both with
// relative and absolute paths..
if ( !filePath.startsWith("/") )
{
filePath = projectPath + "/" + filePath;
}
if( !isValidSource( filePath ) ) continue;
if ( headerExtensions.contains( QFileInfo( filePath ).extension() ) )
headers << ( filePath );
else
others << ( filePath );
}
return makeListUnique( headers + others );
}
void CppSupportPart::addedFilesToProject( const QStringList &fileList )
{
m_projectFileList = project() ->allFiles();
QStringList files = reorder( fileList );
for ( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
{
QString path = *it;
if (!path.startsWith("/"))
path = URLUtil::canonicalPath( m_projectDirectory + "/" + ( *it ) );
maybeParse( path );
//emit addedSourceInfo( path );
}
m_buildSafeFileSetTimer->start( 500, true );
}
void CppSupportPart::removedFilesFromProject( const QStringList &fileList )
{
m_projectFileList = project() ->allFiles();
for ( QStringList::ConstIterator it = fileList.begin(); it != fileList.end(); ++it )
{
QString path = URLUtil::canonicalPath( m_projectDirectory + "/" + *it );
kdDebug( 9007 ) << "=====================> remove file: " << path << endl;
removeWithReferences( path );
m_backgroundParser->removeFile( path );
}
m_buildSafeFileSetTimer->start( 500, true );
}
void CppSupportPart::changedFilesInProject( const QStringList & fileList )
{
QStringList files = reorder( fileList );
for ( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
{
QString path = URLUtil::canonicalPath( m_projectDirectory + "/" + *it );
maybeParse( path );
//emit addedSourceInfo( path );
}
}
void CppSupportPart::savedFile( const KURL &file )
{
if( file.path() == m_activeFileName ) {
m_isTyping = false;
m_hadErrors = false;
maybeParse( file.path() );
}
Q_UNUSED( file.path() );
#if 0 // not needed anymore
kdDebug( 9007 ) << "savedFile(): " << fileName.mid ( m_projectDirectory.length() + 1 ) << endl;
if ( m_projectFileList.contains( fileName.mid ( m_projectDirectory.length() + 1 ) ) )
{
maybeParse( fileName );
emit addedSourceInfo( fileName );
}
#endif
}
QString CppSupportPart::findSourceFile()
{
// get the path of the currently active document
QFileInfo fi( m_activeFileName );
QString path = fi.filePath();
QString ext = fi.extension();
// extract the base path (full path without '.' and extension)
QString base = path.left( path.length() - ext.length() - 1 );
QStringList candidates;
if ( QStringList::split( ',', "h,H,hh,hxx,hpp,tlh" ).contains( ext ) )
{
candidates << ( base + ".c" );
candidates << ( base + ".cc" );
candidates << ( base + ".cpp" );
candidates << ( base + ".c++" );
candidates << ( base + ".cxx" );
candidates << ( base + ".C" );
candidates << ( base + ".m" );
candidates << ( base + ".mm" );
candidates << ( base + ".M" );
candidates << ( base + ".inl" );
candidates << ( base + "_impl.h" );
}
QStringList::ConstIterator it;
for ( it = candidates.begin(); it != candidates.end(); ++it )
{
kdDebug( 9007 ) << "Trying " << ( *it ) << endl;
if ( QFileInfo( *it ).exists() )
{
return * it;
}
}
return m_activeFileName;
}
QString CppSupportPart::sourceOrHeaderCandidate( const KURL &url )
{
QString urlPath;
if ( url.isEmpty() )
{
KTextEditor::Document * doc =
dynamic_cast<KTextEditor::Document*>( partController() ->activePart() );
if ( !doc )
return QString::null;
urlPath = doc->url().path();
}
else
{
urlPath = url.path();
}
// get the path of the currently active document
QFileInfo fi( urlPath );
QString path = fi.filePath();
// extract the exension
QString ext = fi.extension();
if ( ext.isEmpty() )
return QString::null;
// extract the base path (full path without '.' and extension)
QString base = path.left( path.length() - ext.length() - 1 );
//kdDebug( 9007 ) << "base: " << base << ", ext: " << ext << endl;
// just the filename without the extension
QString fileNameWoExt = fi.fileName();
if ( !ext.isEmpty() )
fileNameWoExt.replace( "." + ext, "" );
QString possibleExts;
// depending on the current extension assemble a list of
// candidate files to look for
QStringList candidates;
// special case for template classes created by the new class dialog
if ( path.endsWith( "_impl.h" ) )
{
QString headerpath = path;
headerpath.replace( "_impl.h", ".h" );
candidates << headerpath;
fileNameWoExt.replace( "_impl", "" );
possibleExts = "h";
}
// if file is a header file search for implementation file
else if ( QStringList::split( ',', "h,H,hh,hxx,hpp,tlh" ).contains( ext ) )
{
candidates << ( base + ".c" );
candidates << ( base + ".cc" );
candidates << ( base + ".cpp" );
candidates << ( base + ".c++" );
candidates << ( base + ".cxx" );
candidates << ( base + ".C" );
candidates << ( base + ".m" );
candidates << ( base + ".mm" );
candidates << ( base + ".M" );
candidates << ( base + ".inl" );
candidates << ( base + "_impl.h" );
possibleExts = "c,cc,cpp,c++,cxx,C,m,mm,M,inl,_impl.h";
}
// if file is an implementation file, search for header file
else if ( QStringList::split( ',', "c,cc,cpp,c++,cxx,C,m,mm,M,inl" ).contains( ext ) )
{
candidates << ( base + ".h" );
candidates << ( base + ".H" );
candidates << ( base + ".hh" );
candidates << ( base + ".hxx" );
candidates << ( base + ".hpp" );
candidates << ( base + ".tlh" );
possibleExts = "h,H,hh,hxx,hpp,tlh";
}
// search for files from the assembled candidate lists, return the first
// candidate file that actually exists or QString::null if nothing is found.
QStringList::ConstIterator it;
for ( it = candidates.begin(); it != candidates.end(); ++it )
{
//kdDebug( 9007 ) << "Trying " << ( *it ) << endl;
if ( QFileInfo( *it ).exists() )
{
kdDebug( 9007 ) << "using: " << *it << endl;
return * it;
}
}
//kdDebug( 9007 ) << "Now searching in project files." << endl;
// Our last resort: search the project file list for matching files
QStringList::iterator fileIt;
QFileInfo candidateFileWoExt;
QString candidateFileWoExtString;
QStringList possibleExtsList = QStringList::split( ',', possibleExts );
for ( fileIt = m_projectFileList.begin(); fileIt != m_projectFileList.end(); ++fileIt )
{
candidateFileWoExt.setFile(*fileIt);
//kdDebug( 9007 ) << "candidate file: " << *fileIt << endl;
if( !candidateFileWoExt.extension().isEmpty() )
candidateFileWoExtString = candidateFileWoExt.fileName().replace( "." + candidateFileWoExt.extension(), "" );
if ( candidateFileWoExtString == fileNameWoExt )
{
if ( possibleExtsList.contains( candidateFileWoExt.extension() ) || candidateFileWoExt.extension().isEmpty() )
{
//kdDebug( 9007 ) << "checking if " << *fileIt << " exists" << endl;
if ( QFileInfo( *fileIt ).exists() )
kdDebug( 9007 ) << "using: " << *fileIt << endl;
return *fileIt;
}
}
}
return QString::null;
}
void CppSupportPart::slotSaveMemory() {
if( m_backgroundParser ) {
///This is done so the caches are completely empty after kdevelop was idle for some time(else it would be waste of memory). The background-parsers internal lexer-cache-manager just cares about keeping the count of cached files under a specific count, but doesn't decrease that count when kdevelop is idle.
m_backgroundParser->lock();
m_backgroundParser->saveMemory();
m_backgroundParser->unlock();
}
}
void CppSupportPart::slotSwitchHeader( bool scrollOnly )
{
bool attemptMatch = true;
KConfig *config = CppSupportFactory::instance() ->config();
if ( config )
{
config->setGroup( "General" );
attemptMatch = config->readBoolEntry( "SwitchShouldMatch", true );
}
// ok, both files exist. Do the codemodel have them?
if ( codeModel() ->hasFile( m_activeFileName ) && m_activeViewCursor && attemptMatch )
{
unsigned int currentline, column;
m_activeViewCursor->cursorPositionReal( ¤tline, &column );
if ( switchHeaderImpl( m_activeFileName, currentline, column, scrollOnly ) )
return;
}
// last chance
KURL url;
url.setPath( sourceOrHeaderCandidate() );
if ( scrollOnly )
return;
else if ( !splitHeaderSourceConfig()->splitEnabled() )
partController() ->editDocument( url );
else
partController() ->splitCurrentDocument( url );
}
bool CppSupportPart::switchHeaderImpl( const QString& file, int line, int col, bool scrollOnly )
{
bool handled = false;
FunctionDom d;
FileDom fd = codeModel() ->fileByName( file );
if ( fd ) {
CodeModelUtils::CodeModelHelper h( codeModel(), fd );
d = h.functionAt( line, col );
}
if ( d ) {
if( d->isFunctionDefinition() ) {
FunctionDom decl = findFunction( d );
if ( decl ) {
if ( (void*)&decl != (void*)d.data() && ( !scrollOnly || decl->fileName() != file ) ) {
jumpToCodeModelItem( model_cast<ItemDom>(decl), scrollOnly );
handled = true;
}
}
} else {
FunctionDom def = findFunctionDefinition( d );
if ( def ) {
if ( def != d && ( !scrollOnly || def->fileName() != file ) ) {
jumpToCodeModelItem( model_cast<ItemDom>(def), scrollOnly );
handled = true;
}
}
}
}
return handled;
}
FunctionDom CppSupportPart::findFunction( const FunctionDom& def )
{
// We have a definition so we're looking for a declaration. The declaration will either be the child of a namespace node (non class members)
// or the child of a class node (class member). Search recursively until we find a declaration that matches.
FunctionDom bestMatch;
FunctionDom decl = findFunctionInNamespace( codeModel()->globalNamespace(), def, codeModel()->globalNamespace()->namespaceImports(),
sourceOrHeaderCandidate( def->fileName() ), 0, bestMatch );
return decl ? decl : bestMatch;
}
FunctionDom CppSupportPart::findFunctionInNamespace( const NamespaceDom& ns, const FunctionDom& def, const std::set<NamespaceImportModel>& nsImports,
const QString& candidateFile, int scopeIndex, FunctionDom& bestMatch )
{
FunctionDom d;
QStringList scope = def->scope();
if ( !(scopeIndex >= (signed) scope.size()) ) {
NamespaceDom ns_next = ns->namespaceByName( scope[ scopeIndex ] );
if ( ns_next ) {
d = findFunctionInNamespace( ns_next, def, ns_next->namespaceImports(), candidateFile, scopeIndex+1, bestMatch );
}
if ( !d ) {
for ( std::set<NamespaceImportModel>::const_iterator it_ns = nsImports.begin(); it_ns != nsImports.end(); ++it_ns ) {
if ( (*it_ns).fileName().str() == def->fileName() ) {
ns_next = ns->namespaceByName( (*it_ns).name() );
if ( ns_next ) {
if ( d = findFunctionInNamespace( ns_next, def, nsImports, candidateFile, scopeIndex, bestMatch ) ) break;
}
}
}
}
if ( !d ) {
ClassList classList = ns->classByName( scope[ scopeIndex ] );
for ( ClassList::ConstIterator it_cs = classList.begin(); it_cs != classList.end(); ) {
if ( d = findFunctionInClass( *(it_cs++), def, nsImports, candidateFile, scopeIndex+1, bestMatch ) ) break;
}
}
}
if ( !d ) {
FunctionList functionList = ns->functionByName( def->name() );
for ( FunctionList::ConstIterator it_decl = functionList.begin(); it_decl != functionList.end(); ++it_decl ) {
if ( CodeModelUtils::compareDeclarationToDefinition( *it_decl, (FunctionDefinitionModel*) def.data(), nsImports ) ) {
ParsedFile* p = dynamic_cast<ParsedFile*>( def->file()->parseResult().data() );
if ( p ) {
if ( p->includeFiles()[ (*it_decl)->fileName() ] ) {
d = *it_decl;
break;
} else if ( (*it_decl)->fileName() == candidateFile ) {
d = *it_decl;
break;
}
}
if ( !bestMatch ) {
bestMatch = *it_decl;
}
}
}
}
return d;
}
FunctionDom CppSupportPart::findFunctionInClass( const ClassDom& cs, const FunctionDom& def, const std::set<NamespaceImportModel>& nsImports,
const QString& candidateFile, int scopeIndex, FunctionDom& bestMatch )
{
FunctionDom d;
QStringList scope = def->scope();
if ( !(scopeIndex >= (signed) scope.size()) ) {
ClassList classList = cs->classByName( scope[ scopeIndex ] );
for ( ClassList::ConstIterator it_cs = classList.begin(); it_cs != classList.end(); ) {
if ( d = findFunctionInClass( *(it_cs++), def, nsImports, candidateFile, scopeIndex+1, bestMatch ) ) break;
}
}
if ( !d ) {
FunctionList functionList = cs->functionByName( def->name() );
for ( FunctionList::ConstIterator it_decl = functionList.begin(); it_decl != functionList.end(); ++it_decl ) {
if ( CodeModelUtils::compareDeclarationToDefinition( *it_decl, (FunctionDefinitionModel*) def.data(), nsImports ) ) {
ParsedFile* p = dynamic_cast<ParsedFile*>( def->file()->parseResult().data() );
if ( p ) {
if ( p->includeFiles()[ (*it_decl)->fileName() ] ) {
d = *it_decl;
break;
} else if ( (*it_decl)->fileName() == candidateFile ) {
d = *it_decl;
break;
}
}
if ( !bestMatch ) {
bestMatch = *it_decl;
}
}
}
}
return d;
}
FunctionDom CppSupportPart::findFunctionDefinition( const FunctionDom& decl )
{
// We have a declaration so we're looking for a definition. The definition will be the child of some namespace node (never a class node).
// Since the definition can be the child of any namespace in its scope depending on syntax, we have to check every one.
FunctionDom def, bestMatch;
NamespaceDom ns = codeModel()->globalNamespace();
QString candidateFile = sourceOrHeaderCandidate( decl->fileName() );
FunctionDefinitionList functionList = ns->functionDefinitionByName( decl->name() );
for ( FunctionDefinitionList::ConstIterator it_def = functionList.begin(); it_def != functionList.end() && !def; ++it_def ) {
if ( CodeModelUtils::compareDeclarationToDefinition( decl, *it_def, ns->namespaceImports() ) ) {
ParsedFile* p = dynamic_cast<ParsedFile*>( (*it_def)->file()->parseResult().data() );
if ( p ) {
if ( p->includeFiles()[ decl->fileName() ] ) {
def = *it_def;
} else if ( (*it_def)->fileName() == candidateFile ) {
def = *it_def;
break;
}
}
if ( !bestMatch ) {
bestMatch = *it_def;
}
}
}
QStringList scope = decl->scope();
for ( QStringList::ConstIterator it_scope = scope.begin(); it_scope != scope.end() && !def; ++it_scope ) {
NamespaceDom ns_next = ns->namespaceByName( *it_scope );
if ( ns_next ) {
ns = ns_next;
FunctionDefinitionList functionList = ns->functionDefinitionByName( decl->name() );
for ( FunctionDefinitionList::ConstIterator it_def = functionList.begin(); it_def != functionList.end() && !def; ++it_def ) {
if ( CodeModelUtils::compareDeclarationToDefinition( decl, *it_def, ns->namespaceImports() ) ) {
ParsedFile* p = dynamic_cast<ParsedFile*>( (*it_def)->file()->parseResult().data() );
if ( p ) {
if ( p->includeFiles()[ decl->fileName() ] ) {
def = *it_def;
} else if ( (*it_def)->fileName() == candidateFile ) {
def = *it_def;
break;
}
}
if ( !bestMatch ) {
bestMatch = *it_def;
}
}
}
}
}
return def ? def : bestMatch;
}
void CppSupportPart::jumpToCodeModelItem( const ItemDom& item, bool scrollOnly )
{
static KURL lastSyncedUrl;
static int lastSyncedLine = -1;
int line, col;
item->getStartPosition( &line, &col );
KURL url( item->fileName() );
if ( scrollOnly ) {
KParts::ReadOnlyPart* part = partController()->partForURL( url );
int currentLine = lastSyncedLine;
if ( part ) {
KTextEditor::ViewCursorInterface *iface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget());
if( iface )
iface->cursorPosition( (uint*) ¤tLine, (uint*) &col );
}
partController() ->scrollToLineColumn( url, line, -1, lastSyncedLine != currentLine || lastSyncedUrl != url );
} else if ( !splitHeaderSourceConfig()->splitEnabled() )
partController() ->editDocument( url, line );
else
partController() ->splitCurrentDocument( url, line );
lastSyncedLine = line;
lastSyncedUrl = url;
}
KDevLanguageSupport::Features CppSupportPart::features()
{
if ( withcpp )
return Features( Classes | Structs | Functions | Variables | Namespaces | Declarations
| Signals | Slots | AddMethod | AddAttribute | NewClass | CreateAccessMethods );
else
return Features ( Structs | Functions | Variables | Declarations );
}
QString CppSupportPart::formatClassName( const QString &name )
{
QString n = name;
return n.replace( ".", "::" );
}
QString CppSupportPart::unformatClassName( const QString &name )
{
QString n = name;
return n.replace( "::", "." );
}
bool CppSupportPart::shouldSplitDocument(const KURL &url)
{
if ( !splitHeaderSourceConfig()->splitEnabled() )
return false;
KURL::List list = partController()->openURLs();
KURL::List::ConstIterator it = list.begin();
while ( it != list.end() )
{
QString candidate = sourceOrHeaderCandidate( ( *it ) );
if ( candidate.isEmpty() )
{
++it;
continue;
}
KURL urlCandidate;
urlCandidate.setPath( candidate );
if ( url == urlCandidate )
{
// It is already open, so switch to it so
// our split view will open with it
partController() ->editDocument( ( *it ) );
return true;
}
++it;
}
return false;
}
Qt::Orientation CppSupportPart::splitOrientation() const
{
QString o = splitHeaderSourceConfig()->orientation();
if ( o == "Vertical" )
return Qt::Vertical;
else
return Qt::Horizontal;
}
void CppSupportPart::slotNewClass()
{
CppNewClassDialog dlg( this );
dlg.exec();
}
void CppSupportPart::addMethod( ClassDom klass )
{
if ( !klass )
{
KMessageBox::error( 0, i18n( "Please select a class." ), i18n( "Error" ) );
return ;
}
AddMethodDialog dlg( this, klass, mainWindow() ->main() );
dlg.exec();
}
void CppSupportPart::addAttribute( ClassDom klass )
{
if ( !klass )
{
KMessageBox::error( 0, i18n( "Please select a class." ), i18n( "Error" ) );
return ;
}
AddAttributeDialog dlg( this, klass, mainWindow() ->main() );
dlg.exec();
}
void CppSupportPart::slotCompleteText()
{
if ( !m_pCompletion )
return ;
m_pCompletion->completeText( true );
}
/**
* parsing stuff for project persistent classstore and code completion
*/
void CppSupportPart::initialParse( )
{
// For debugging
if ( !project( ) )
{
// messagebox ?
kdDebug( 9007 ) << "No project" << endl;
return ;
}
parseProject( );
m_valid = true;
return ;
}
bool CppSupportPart::parseProject( bool force )
{
if( _jd )
delete _jd->progressBar; ///Make sure the progress-bar is open
mainWindow() ->statusBar() ->message( i18n( "Updating..." ) );
kapp->setOverrideCursor( waitCursor );
_jd = new JobData;
if( QFileInfo( project() ->projectDirectory() + "/" + project()->projectName().lower()
+ ".kdevelop.pcs" ).exists())
{
QDir d( project() ->projectDirectory());
d.rename(project() ->projectName().lower() + ".kdevelop.pcs",
project() ->projectName() +".kdevelop.pcs");
}
_jd->file.setName( project() ->projectDirectory() + "/" + project()->projectName()
+ ".kdevelop.pcs" );
QString skip_file_name = project() ->projectDirectory() + "/" +
project() ->projectName() + ".kdevelop.ignore_pcs";
QString skip_lower_file_name = project() ->projectDirectory() + "/" +
project() ->projectName().lower() + ".kdevelop.ignore_pcs";
if ( !force && !QFile::exists( skip_file_name ) &&
!QFile::exists( skip_lower_file_name ) && _jd->file.open( IO_ReadOnly ) )
{
_jd->stream.setDevice( &( _jd->file ) );
createIgnorePCSFile();
QString sig;
int pcs_version = 0;
_jd->stream >> sig >> pcs_version;
if ( sig == "PCS" && pcs_version == KDEV_PCS_VERSION )
{
int numFiles = 0;
_jd->stream >> numFiles;
kdDebug( 9007 ) << "Read " << numFiles << " files from pcs" << endl;
for ( int i = 0; i < numFiles; ++i )
{
QString fn;
uint ts;
uint offset;
_jd->stream >> fn >> ts >> offset;
_jd->pcs[ fn ] = qMakePair( ts, offset );
}
}
}
_jd->files = reorder( modifiedFileList() );
QProgressBar* bar = new QProgressBar( _jd->files.count( ), mainWindow( ) ->statusBar( ) );
bar->setMinimumWidth( 120 );
bar->setCenterIndicator( true );
mainWindow( ) ->statusBar( ) ->addWidget( bar );
bar->show( );
_jd->progressBar = bar;
_jd->dir.setPath( m_projectDirectory );
_jd->it = _jd->files.begin();
_jd->reparseList = QStringList();
_jd->backgroundCount = 0;
_jd->cycle = 0;
QTimer::singleShot( 0, this, SLOT( slotParseFiles() ) );
m_saveMemoryTimer->stop(); //Do not regularly remove cached files that may still be needed while parsing(the cache anyway be full for the whole parsing-process)
return true;
}
void CppSupportPart::slotParseFiles()
{
// NOTE: The checking for m_projectClosed is actually (currently) not needed.
// When the project is closed, the language support plugin is destroyed
// and as a consequence, the timer job signal never arrives at this method
if ( !_jd ) return; // how can this possibly happen?!
if ( _jd->cycle == 0 && !m_projectClosed && _jd->it != _jd->files.end() )
{
_jd->progressBar->setProgress( _jd->progressBar->progress() + 1 );
QFileInfo fileInfo( _jd->dir, *( _jd->it ) );
if ( fileInfo.exists() && fileInfo.isFile() && fileInfo.isReadable() )
{
QString absFilePath = URLUtil::canonicalPath( fileInfo.absFilePath() );
if ( isValidSource( absFilePath ) )
{
QDateTime t = fileInfo.lastModified();
if ( ! ( m_timestamp.contains( absFilePath ) && m_timestamp[ absFilePath ] == t ) )
{
if ( _jd->pcs.contains( absFilePath ) )
{
_jd->stream.device() ->at( _jd->pcs[ absFilePath ].second );
FileDom file = codeModel() ->create<FileModel>();
file->read( _jd->stream );
codeModel() ->addFile( file );
if( t.toTime_t() != _jd->pcs[ absFilePath ].first ) {
///The FileDom had to be created first, so the dependencies are known
_jd->reparseList << file->name();
/* kdDebug( 9007 ) << "File timestamp: " << ": " << t.toTime_t() << endl;
kdDebug( 9007 ) << "Stored timestamp: " << ": " << _jd->pcs[ absFilePath ].first << endl;*/
} else {
m_timestamp[ absFilePath ] = t;
/* kdDebug( 9007 ) << "timestamp ok" << endl;*/
}
} else {
_jd->reparseList << absFilePath;
/* kdDebug( 9007 ) << absFilePath << " put into reparse-list" << endl;
*/ }
} else {
/* kdDebug( 9007 ) << absFilePath << " is already in code-model" << endl;*/
}
}
}
++( _jd->it );
QTimer::singleShot( 0, this, SLOT( slotParseFiles() ) );
if( _jd->it == _jd->files.end()) {
if( _jd->reparseList.isEmpty() ) {
_jd->backgroundCount = 0;
} else {
if( alwaysParseInBackground ) {
_jd->backgroundCount = parseFilesAndDependencies( _jd->reparseList, true, false, true );
} else {
_jd->reparseList = reorder( _jd->reparseList );
_jd->it = _jd->reparseList.begin();
_jd->backgroundCount = _jd->reparseList.count();
}
_jd->progressBar->setProgress( 0 ); ///restart progress-bar for reparsing
_jd->progressBar->setTotalSteps( _jd->backgroundCount );
}
_jd->lastBackgroundState = -1;
_jd->backgroundState = 0;
_jd->cycle = 1;
_jd->lastParse = QTime::currentTime();
kapp->restoreOverrideCursor( );
}
}
else // finished or interrupted
{
if( _jd->backgroundCount <= _jd->backgroundState || m_projectClosed ) {
mainWindow( ) ->statusBar( ) ->removeWidget( _jd->progressBar );
if ( !m_projectClosed )
{
kdDebug( 9007 ) << "updating sourceinfo" << endl;
kapp->restoreOverrideCursor( );
emit updatedSourceInfo();
mainWindow( ) ->statusBar( ) ->message( i18n( "Done" ), 2000 );
QFile::remove( project() ->projectDirectory()
+ "/" + project() ->projectName()
+ ".kdevelop.ignore_pcs" );
QFile::remove( project() ->projectDirectory()
+ "/" + project() ->projectName().lower()
+ ".kdevelop.ignore_pcs" );
}
else
{
kdDebug( 9007 ) << "ABORT" << endl;
}
delete _jd;
_jd = 0;
m_saveMemoryTimer->start( 240000, false );
} else {
_jd->progressBar->setProgress( _jd->backgroundState ); ///restart
_jd->progressBar->setTotalSteps( _jd->backgroundCount );
if( _jd->lastParse.msecsTo( QTime::currentTime()) > 60000 && !m_backgroundParser->filesInQueue()) {
_jd->backgroundCount = _jd->backgroundState; ///Stop waiting if there is no progress and no file in the background-parser
QTimer::singleShot( 0, this, SLOT( slotParseFiles() ) );
} else {
int timeStep = 0;
if( alwaysParseInBackground ) {
QTimer::singleShot( 10, this, SLOT( slotParseFiles() ) );
} else {
if( _jd->it == _jd->reparseList.end() ) {
/*_jd->it = _jd->files.end();
_jd->backgroundCount = _jd->backgroundState; ///finish processing*/
timeStep = 1;
} else {
/*///Parse the files one by one
if( _jd->lastParse.msecsTo( QTime::currentTime()) > 100 || _jd->backgroundState != _jd->lastBackgroundState ) {*/
maybeParse( *_jd->it, false );
++(_jd->it);
_jd->lastBackgroundState = _jd->backgroundState;
/*}else{
timeStep = 1;
}*/
}
QTimer::singleShot( timeStep, this, SLOT( slotParseFiles() ) );
}
}
}
}
}
void CppSupportPart::maybeParse( const QString& fn, bool background )
{
if ( !isValidSource( fn ) )
return ;
QFileInfo fileInfo( fn );
QString path = URLUtil::canonicalPath( fn );
QDateTime t = fileInfo.lastModified();
if ( !fileInfo.exists() )
return;
QMap<QString, QDateTime>::Iterator it = m_timestamp.find( path );
if ( codeModel()->hasFile( fn ) && it != m_timestamp.end() && *it == t )
return;
QStringList l;
l << fn;
parseFilesAndDependencies( l, background );
}
bool CppSupportPart::isQueued( const QString& file ) const {
//int c = m_backgroundParser->countInQueue( file );
//if( c == 0 ) return false;
return m_parseEmitWaiting.waiting( file, ParseEmitWaiting::Silent, 2 ); //Since it may be possible that the background-parser is currently parsing the file(in an obselete state), it is allowed to have the file in the queue twice.
}
void CppSupportPart::slotNeedTextHint( int line, int column, QString& textHint )
{
if ( 1 || !m_activeEditor )
return ;
m_backgroundParser->lock();
TranslationUnitAST* ast = *m_backgroundParser->translationUnit( m_activeFileName );
AST* node = 0;
if ( ast && ( node = findNodeAt( ast, line, column ) ) )
{
while ( node && node->nodeType() != NodeType_FunctionDefinition )
node = node->parent();
if ( node )
{
int startLine, startColumn;
int endLine, endColumn;
node->getStartPosition( &startLine, &startColumn );
node->getEndPosition( &endLine, &endColumn );
if ( !node->text().isNull() )
textHint = node->text();
else
textHint = m_activeEditor->textLine( startLine ).simplifyWhiteSpace();
}
}
m_backgroundParser->unlock();
}
void CppSupportPart::MakeMemberHelper( QString& text, int& atLine, int& atColumn )
{
if ( !m_activeViewCursor || !m_valid )
return ;
atLine = -2;
atColumn = 0;
QString implFile = findSourceFile();
m_backgroundParser->lock();
TranslationUnitAST* translationUnit = *m_backgroundParser->translationUnit( m_activeFileName );
if ( translationUnit )
{
bool fail = false;
unsigned int line, column;
m_activeViewCursor->cursorPositionReal( &line, &column );
AST* currentNode = findNodeAt( translationUnit, line, column );
DeclaratorAST* declarator = 0;
while ( currentNode && currentNode->nodeType() != NodeType_SimpleDeclaration )
{
if ( currentNode->nodeType() == NodeType_Declarator )
declarator = ( DeclaratorAST* ) currentNode;
currentNode = currentNode->parent();
}
SimpleDeclarationAST* decl = currentNode ? ( SimpleDeclarationAST* ) currentNode : 0;
if ( decl && decl->storageSpecifier() && decl->storageSpecifier()->text().contains("friend") )
{
kdDebug(9007) << "this is a friend declaration, don't create any definition" << endl;
fail = true;
}
if ( !fail && decl && decl->initDeclaratorList() && !declarator )
{
InitDeclaratorAST * i = decl->initDeclaratorList() ->initDeclaratorList().at( 0 );
if ( i )
declarator = i->declarator();
}
if ( !fail && decl && declarator && declarator->parameterDeclarationClause() )
{
QStringList scope;
scopeOfNode( decl, scope );
QString scopeStr = scope.join( "::" );
if ( !scopeStr.isEmpty() )
scopeStr += "::";
QString declStr = declaratorToString( declarator, scopeStr ).simplifyWhiteSpace();
if ( declarator->exceptionSpecification() )
{
declStr += QString::fromLatin1( " throw( " );
QPtrList<AST> l = declarator->exceptionSpecification() ->nodeList();
QPtrListIterator<AST> type_it( l );
while ( type_it.current() )
{
declStr += type_it.current() ->text();
++type_it;
if ( type_it.current() )
declStr += QString::fromLatin1( ", " );
}
declStr += QString::fromLatin1( " )" );
}
text += "\n\n";
QString type = typeSpecToString( decl->typeSpec() );
text += type;
if ( !type.isNull() )
text += + " ";
text += declStr + "\n{\n}";
}
if ( !fail )
{
translationUnit = *m_backgroundParser->translationUnit( implFile );
if ( translationUnit )
translationUnit->getEndPosition( &atLine, &atColumn );
}
kdDebug( 9007 ) << "at line in mm: " << atLine << endl;
}
m_backgroundParser->unlock();
}
void CppSupportPart::slotMakeMember()
{
QString text;
int atColumn, atLine;
MakeMemberHelper( text, atLine, atColumn );
if ( !text.isEmpty() )
{
QString implFile = findSourceFile();
if ( !implFile.isEmpty() )
{
partController() ->editDocument( KURL( implFile ) );
kapp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput | QEventLoop::ExcludeSocketNotifiers, 500 );
}
if ( atLine == -2 )
atLine = m_activeEditor->numLines() - 1;
m_backgroundParser->lock ()
;
kdDebug( 9007 ) << "at line in mm: " << atLine << " atCol: " << atColumn << endl;
kdDebug( 9007 ) << "text: " << text << endl;
if ( m_activeEditor )
m_activeEditor->insertText( atLine, atColumn, text );
if ( m_activeViewCursor )
m_activeViewCursor->setCursorPositionReal( atLine + 3, 1 );
m_backgroundParser->unlock();
}
}
QStringList CppSupportPart::subclassWidget( const QString& formName )
{
QStringList newFileNames;
SubclassingDlg *dlg = new SubclassingDlg( this, formName, newFileNames );
dlg->exec();
return newFileNames;
}
QStringList CppSupportPart::updateWidget( const QString& formName, const QString& fileName )
{
QStringList dummy;
SubclassingDlg *dlg = new SubclassingDlg( this, formName, fileName, dummy );
dlg->exec();
return dummy;
}
void CppSupportPart::partRemoved( KParts::Part* part )
{
kdDebug( 9032 ) << "CppSupportPart::partRemoved()" << endl;
if ( KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( part ) )
{
QString fileName = doc->url().path();
if ( !isValidSource( fileName ) )
return ;
QString canonicalFileName = URLUtil::canonicalPath( fileName );
m_backgroundParser->removeFile( canonicalFileName );
m_backgroundParser->addFile( canonicalFileName, true );
}
}
void CppSupportPart::slotProjectCompiled()
{
kdDebug( 9007 ) << "CppSupportPart::slotProjectCompiled()" << endl;
parseProject();
}
QStringList CppSupportPart::modifiedFileList()
{
QStringList lst;
QStringList fileList = m_projectFileList;
QStringList::Iterator it = fileList.begin();
while ( it != fileList.end() )
{
QString fileName = *it;
++it;
QFileInfo fileInfo( m_projectDirectory, fileName );
QString path = URLUtil::canonicalPath( fileInfo.absFilePath() );
if ( !( isSource( path ) || isHeader( path ) ) )
continue;
QDateTime t = fileInfo.lastModified();
QMap<QString, QDateTime>::Iterator dictIt = m_timestamp.find( path );
if ( fileInfo.exists() && dictIt != m_timestamp.end() && *dictIt == t )
continue;
lst << fileName;
}
return lst;
}
KTextEditor::Document * CppSupportPart::findDocument( const KURL & url )
{
if ( !partController() ->parts() )
return 0;
QPtrList<KParts::Part> parts( *partController() ->parts() );
QPtrListIterator<KParts::Part> it( parts );
while ( KParts::Part * part = it.current() )
{
KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( part );
if ( doc && doc->url() == url )
return doc;
++it;
}
return 0;
}
void CppSupportPart::setupCatalog( )
{
kdDebug( 9007 ) << "CppSupportPart::setupCatalog()" << endl;
KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
QStringList pcsList = dirs->findAllResources( "pcs", "*.db", false, true );
QStringList pcsIdxList = dirs->findAllResources( "pcs", "*.idx", false, true );
QStringList enabledPCSs;
if ( DomUtil::elementByPath( *project() ->projectDom(), "kdevcppsupport/references" ).isNull() )
{
for ( QStringList::Iterator it = pcsList.begin(); it != pcsList.end(); ++it )
{
kdDebug( 9007 ) << "CppSupportPart::setupCatalog()1 " << *it << endl;
enabledPCSs.push_back( QFileInfo( *it ).baseName(true) );
}
}
else
{
enabledPCSs = DomUtil::readListEntry( *project() ->projectDom(), "kdevcppsupport/references", "pcs" );
}
QStringList indexList = QStringList() << "kind" << "name" << "scope" << "fileName" << "prefix";
if ( pcsList.size() && pcsVersion() < KDEV_DB_VERSION )
{
QStringList l = pcsList + pcsIdxList;
int rtn = KMessageBox::questionYesNoList( 0, i18n( "Persistent class store will be disabled: you have a wrong version of pcs installed.\nRemove old pcs files?" ), l, i18n( "C++ Support" ), KStdGuiItem::del(), KStdGuiItem::cancel() );
if ( rtn == KMessageBox::Yes )
{
QStringList::Iterator it = l.begin();
while ( it != l.end() )
{
QFile::remove
( *it );
++it;
}
// @todo regenerate the pcs list
pcsList.clear();
}
else
{
return ;
}
}
QStringList::Iterator it = pcsList.begin();
while ( it != pcsList.end() )
{
kdDebug( 9007 ) << "CppSupportPart::setupCatalog()2 " << *it << endl;
Catalog * catalog = new Catalog();
catalog->open( *it );
catalog->setEnabled( enabledPCSs.contains( QFileInfo( *it ).baseName(true) ) );
++it;
for ( QStringList::Iterator idxIt = indexList.begin(); idxIt != indexList.end(); ++idxIt )
catalog->addIndex( ( *idxIt ).utf8() );
m_catalogList.append( catalog );
codeRepository() ->registerCatalog( catalog );
}
setPcsVersion( KDEV_DB_VERSION );
}
KMimeType::List CppSupportPart::mimeTypes( )
{
QStringList mimeList;
mimeList += m_headerMimeTypes;
mimeList += m_sourceMimeTypes;
KMimeType::List list;
for ( QStringList::Iterator it = mimeList.begin(); it != mimeList.end(); ++it )
{
if ( KMimeType::Ptr mime = KMimeType::mimeType( *it ) )
list << mime;
}
return list;
}
int CppSupportPart::pcsVersion()
{
KConfig * config = CppSupportFactory::instance() ->config();
KConfigGroupSaver cgs( config, "PCS" );
return config->readNumEntry( "Version", 0 );
}
void CppSupportPart::setPcsVersion( int version )
{
KConfig * config = CppSupportFactory::instance() ->config();
KConfigGroupSaver cgs( config, "PCS" );
config->writeEntry( "Version", version );
config->sync();
}
QString CppSupportPart::formatTag( const Tag & inputTag )
{
Tag tag = inputTag;
switch ( tag.kind() )
{
case Tag::Kind_Namespace:
return QString::fromLatin1( "namespace " ) + tag.name();
case Tag::Kind_Class:
return QString::fromLatin1( "class " ) + tag.name();
case Tag::Kind_Function:
case Tag::Kind_FunctionDeclaration:
{
CppFunction<Tag> tagInfo( tag );
return tagInfo.name() + "( " + tagInfo.arguments().join( ", " ) + " ) : " + tagInfo.type();
}
break;
case Tag::Kind_Variable:
case Tag::Kind_VariableDeclaration:
{
CppVariable<Tag> tagInfo( tag );
return tagInfo.name() + " : " + tagInfo.type();
}
break;
}
return tag.name();
}
void CppSupportPart::codeCompletionConfigStored( )
{
if ( m_projectClosing ) return;
updateParserConfiguration();
/*
m_backgroundParser->updateParserConfiguration();
KDevDriver* d = dynamic_cast<KDevDriver*>( m_driver ); //The foreground-parse isn't used anymore, and could be removed
if( d ) {
d->setup();
d->makeMacrosPersistent();
}*/
partController() ->setActivePart( partController()->activePart() );
}
void CppSupportPart::splitHeaderSourceConfigStored( )
{
QString o = splitHeaderSourceConfig()->orientation();
if ( o == "Vertical" )
emit splitOrientationChanged( Qt::Vertical );
else if ( o == "Horizontal" )
emit splitOrientationChanged( Qt::Horizontal );
}
void CppSupportPart::removeWithReferences( const QString & fileName )
{
kdDebug( 9007 ) << "remove with references: " << fileName << endl;
m_timestamp.remove( fileName );
if ( !codeModel() ->hasFile( fileName ) )
return ;
emit aboutToRemoveSourceInfo( fileName );
codeModel() ->removeFile( codeModel() ->fileByName( fileName ) );
}
bool CppSupportPart::isValidSource( const QString& fileName ) const
{
QFileInfo fileInfo( fileName );
QString path = URLUtil::canonicalPath( fileInfo.absFilePath() );
return /*project() && project() ->isProjectFile( path )
&&*/ ( isSource( path ) || isHeader( path ) )
&& !QFile::exists( fileInfo.dirPath( true ) + "/.kdev_ignore" );
}
QString CppSupportPart::formatModelItem( const CodeModelItem *item, bool shortDescription )
{
if ( item->isFunction() || item->isFunctionDefinition() )
{
const FunctionModel * model = static_cast<const FunctionModel*>( item );
QString function;
QString args;
ArgumentList argumentList = model->argumentList();
for ( ArgumentList::const_iterator it = argumentList.begin(); it != argumentList.end(); ++it )
{
args.isEmpty() ? args += "" : args += ", " ;
args += formatModelItem( ( *it ).data() );
}
if ( !shortDescription )
function += ( model->isVirtual() ? QString( "virtual " ) : QString( "" ) ) + model->resultType() + " ";
function += model->name() + "(" + args + ")" + ( model->isConstant() ? QString( " const" ) : QString( "" ) ) +
( model->isAbstract() ? QString( " = 0" ) : QString( "" ) );
return function;
}
else if ( item->isVariable() )
{
const VariableModel * model = static_cast<const VariableModel*>( item );
if ( shortDescription )
return model->name();
return model->type() + " " + model->name();
}
else if ( item->isArgument() )
{
const ArgumentModel * model = static_cast<const ArgumentModel*>( item );
QString arg;
if ( !shortDescription )
arg += model->type() + " ";
arg += model->name();
if ( !shortDescription )
arg += model->defaultValue().isEmpty() ? QString( "" ) : QString( " = " ) + model->defaultValue();
return arg.stripWhiteSpace();
}
else
return KDevLanguageSupport::formatModelItem( item, shortDescription );
}
void CppSupportPart::addClass()
{
slotNewClass();
}
void CppSupportPart::saveProjectSourceInfo()
{
const FileList fileList = codeModel() ->fileList();
if ( !project() || fileList.isEmpty() )
return ;
QFile f( project() ->projectDirectory() + "/"
+ project() ->projectName() + ".kdevelop.pcs" );
if ( !f.open( IO_WriteOnly ) )
return ;
m_backgroundParser->lock();
createIgnorePCSFile();
QDataStream stream( &f );
QMap<QString, uint> offsets;
QString pcs( "PCS" );
stream << pcs << KDEV_PCS_VERSION;
stream << int( fileList.size() );
for ( FileList::ConstIterator it = fileList.begin(); it != fileList.end(); ++it )
{
const FileDom dom = ( *it );
stream << dom->name() << m_timestamp[ dom->name() ].toTime_t();
if( m_timestamp.find( dom->name() ) == m_timestamp.end() ) {
kdDebug( 9007 ) << dom->name() << ": timestamp is missing " << endl;
}
offsets.insert( dom->name(), stream.device() ->at() );
stream << ( uint ) 0; // dummy offset
}
for ( FileList::ConstIterator it = fileList.begin(); it != fileList.end(); ++it )
{
const FileDom dom = ( *it );
int offset = stream.device() ->at();
dom->write( stream );
int end = stream.device() ->at();
stream.device() ->at( offsets[ dom->name() ] );
stream << offset;
stream.device() ->at( end );
}
QFile::remove( project() ->projectDirectory() + "/"
+ project() ->projectName() + ".kdevelop.ignore_pcs" );
QFile::remove( project() ->projectDirectory() + "/"
+ project() ->projectName().lower() + ".kdevelop.ignore_pcs" );
m_backgroundParser->unlock();
}
QString CppSupportPart::extractInterface( const ClassDom& klass )
{
QString txt;
QTextStream stream( &txt, IO_WriteOnly );
QString name = klass->name() + "Interface";
QString ind;
ind.fill( QChar( ' ' ), 4 );
stream
<< "class " << name << "\n"
<< "{" << "\n"
<< "public:" << "\n"
<< ind << name << "() {}" << "\n"
<< ind << "virtual ~" << name << "() {}" << "\n"
<< "\n";
const FunctionList functionList = klass->functionList();
for ( FunctionList::ConstIterator it = functionList.begin(); it != functionList.end(); ++it )
{
const FunctionDom& fun = *it;
if ( !fun->isVirtual() || fun->name().startsWith( "~" ) )
continue;
stream << ind << formatModelItem( fun );
if ( !fun->isAbstract() )
stream << " = 0";
stream << ";\n";
}
stream
<< "\n"
<< "private:" << "\n"
<< ind << name << "( const " << name << "& source );" << "\n"
<< ind << "void operator = ( const " << name << "& source );" << "\n"
<< "};" << "\n\n";
return txt;
}
void CppSupportPart::slotExtractInterface( )
{
if ( !m_activeClass )
return ;
QFileInfo fileInfo( m_activeClass->fileName() );
QString ifaceFileName = fileInfo.dirPath( true ) + "/" + m_activeClass->name().lower() + "_interface.h";
if ( QFile::exists( ifaceFileName ) )
{
KMessageBox::error( mainWindow() ->main(), i18n( "File %1 already exists" ).arg( ifaceFileName ),
i18n( "C++ Support" ) );
}
else
{
QString text = extractInterface( m_activeClass );
QFile f( ifaceFileName );
if ( f.open( IO_WriteOnly ) )
{
QTextStream stream( &f );
stream
<< "#ifndef __" << m_activeClass->name().upper() << "_INTERFACE_H" << "\n"
<< "#define __" << m_activeClass->name().upper() << "_INTERFACE_H" << "\n"
<< "\n"
<< extractInterface( m_activeClass )
<< "\n"
<< "#endif // __" << m_activeClass->name().upper() << "_INTERFACE_H" << "\n";
f.close();
project() ->addFile( ifaceFileName );
}
}
m_activeClass = 0;
}
void CppSupportPart::gotoLine( int line )
{
if ( isHeader( m_activeFileName ) )
{
KURL url;
url.setPath( sourceOrHeaderCandidate() );
partController() ->editDocument( url, line );
}
else
m_activeViewCursor->setCursorPositionReal( line, 0 );
}
FileDom CppSupportPart::fileByName( const QString& name) {
return codeModel()->fileByName( name );
}
int CppSupportPart::parseFilesAndDependencies( QStringList files, bool background, bool parseFirst, bool silent ) {
QMap<QString, int> fileGroups;
int nextGroup = 0;
for( QStringList::iterator it = files.begin(); it != files.end(); ++it ) {
FileDom d = fileByName( *it );
QStringList lst;
if( !d ) {
lst << *it;
}else{
lst = codeModel()->getGroupStrings( d->groupId() );
/* kdDebug( 9007 ) << "adding group of: " << *it << ":\n" << " which is " << lst.join("\n") << "\n\n";*/
if( lst.count() > 10 ) {
lst = codeModel()->getGroupStrings( d->groupId() );
}
}
int cgroup = nextGroup;
nextGroup++;
if( fileGroups.find( *it ) != fileGroups.end() )
cgroup = fileGroups[*it];
for( QStringList::iterator lit = lst.begin(); lit != lst.end(); ++lit )
fileGroups[*lit] = cgroup;
}
QValueVector<QStringList> groups;
groups.resize( nextGroup );
///put the groups together
for( QMap<QString, int>::iterator it = fileGroups.begin(); it != fileGroups.end(); ++it ) {
groups[*it] << it.key();
}
for( int a = 0; a < nextGroup; a++ ) {
QStringList group = reorder( groups[a] );
/* kdDebug( 9007 ) << "reparsing the following group: " << ":\n" << group.join("\n") << "\n\n";*/
if( background ) {
m_backgroundParser->lock();
if( !group.isEmpty() ) {
if( !parseFirst )
m_parseEmitWaiting.addGroup( group, silent ? ParseEmitWaiting::Silent : ParseEmitWaiting::None );
else
m_parseEmitWaiting.addGroupFront( group, silent ? ParseEmitWaiting::Silent : ParseEmitWaiting::None );
if( !silent ) {
if( !parseFirst )
m_fileParsedEmitWaiting.addGroup( group, silent ? ParseEmitWaiting::Silent : ParseEmitWaiting::None );
else
m_fileParsedEmitWaiting.addGroupFront( group, silent ? ParseEmitWaiting::Silent : ParseEmitWaiting::None );
}
}
if( parseFirst && !group.empty() ) {
for(QStringList::iterator it = --group.end(); it != group.end(); ) {
backgroundParser()->addFileFront(*it);
if( it == group.begin() ) {
it = group.end();
} else {
--it;
}
}
} else {
for(QStringList::iterator it = group.begin(); it != group.end(); ++it) {
backgroundParser()->addFile(*it);
}
}
m_backgroundParser->unlock();
} else {
for(QStringList::iterator it = group.begin(); it != group.end(); ++it) {
m_driver->parseFile( *it );
}
}
}
return fileGroups.count();
}
int CppSupportPart::parseFileAndDependencies( const QString & fileName, bool background, bool parseFirst, bool silent ) {
if(! isValidSource( fileName ) ) return 0;
// kdDebug( 9007 ) << "reparsing dependencies of " << fileName << "\n";
return parseFilesAndDependencies( fileName, background, parseFirst, silent );
}
void CppSupportPart::parseEmit( ParseEmitWaiting::Processed files ) {
if( files.res.isEmpty() ) return;
bool modelHasFiles = true;
for( QStringList::iterator it = files.res.begin(); it != files.res.end(); ++it ) {
if( !codeModel()->hasFile( *it ) ) modelHasFiles = false;
}
int oldFileCount = codeModel()->fileList().count();
if( (files.flag & ParseEmitWaiting::HadErrors) && modelHasFiles && !files.hasFlag( ParseEmitWaiting::Silent ) ) {
mainWindow() ->statusBar() ->message( "File parsed, but not updating code-model because of errors", 2000 );
kdDebug( 9007 ) << "not updating code-model because at least one file has errors" << endl;
// for( QStringList::iterator it = files.res.begin(); it != files.res.end(); ++it )
// m_backgroundParser->removeFile( *it );
} else {
///update timestamps
for( QStringList::iterator it = files.res.begin(); it != files.res.end(); ++it ) {
if( !codeModel()->hasFile( *it ) ) modelHasFiles = false;
QString& fileName = *it;
QFileInfo fileInfo( fileName );
QString path = URLUtil::canonicalPath( fileName );
if ( !fileInfo.exists() ) {
removeWithReferences( path );
continue ;
}
m_timestamp[ path ] = fileInfo.lastModified();
}
if( files.hasFlag( ParseEmitWaiting::Silent ) && !alwaysParseInBackground )
return;
m_backgroundParser->lock();
QStringList l = files.res;
QMap<QString, bool> wholeResult;
QStringList missing;
QMap<QString, FileDom> newFiles;
while(!l.isEmpty() ) {
QString fileName = l.front();
if( !m_backgroundParser->hasTranslationUnit( fileName ) ) {
kdDebug( 9007 ) << "error: translation-unit is missing: " << fileName << endl;
missing << fileName;
} else {
if ( ParsedFilePointer ast = m_backgroundParser->translationUnit( fileName ) )
{
if ( true /*!hasErrors*/ )
{
FileDom oldFile = codeModel()->fileByName( fileName );
StoreWalker walker( fileName, codeModel() );
walker.setOverrides( newFiles );
walker.parseTranslationUnit( *ast );
if( oldFile ) {
newFiles[fileName] = walker.file();
///update timestamps
QFileInfo fileInfo( fileName );
QString path = URLUtil::canonicalPath( fileName );
m_timestamp[ path ] = fileInfo.lastModified();
} else {
codeModel() ->addFile( walker.file() );
}
if( walker.file() ) {
QStringList grp = walker.file()->wholeGroupStrings();
for( QStringList::const_iterator it = grp.begin(); it != grp.end(); ++it )
wholeResult[*it] = true;
}
}
} else {
kdDebug( 9007 ) << "failed to parse " << fileName << endl;
}
}
l.pop_front();
}
bool canUpdate = true;
for( QMap<QString, FileDom>::const_iterator it = newFiles.begin(); it != newFiles.end(); ++it ) {
FileDom oldFile = codeModel()->fileByName( it.key() );
if( !oldFile || !oldFile->canUpdate( *it ) ) {
canUpdate = false;
break;
}
}
if( canUpdate ) {
///Update the code-model
for( QMap<QString, FileDom>::const_iterator it = newFiles.begin(); it != newFiles.end(); ++it ) {
FileDom oldFile = codeModel()->fileByName( it.key() );
oldFile->update( *it );
codeModel()->mergeGroups( oldFile->groupId(), (*it)->groupId() ); ///Merge parsing-groups together
}
} else {
///Remove the current files and replace them with the new ones
for( QMap<QString, FileDom>::const_iterator it = newFiles.begin(); it != newFiles.end(); ++it ) {
removeWithReferences( it.key() );
codeModel()->addFile( *it );
}
}
/*
///make the list unique
l.clear();
for( QMap<QString, bool>::const_iterator it = wholeResult.begin(); it != wholeResult.end(); ++it )
l << it.key();*/
m_backgroundParser->unlock();
if( !missing.isEmpty() ) {
kdDebug( 9007 ) << "error: translation-units were missing: " << missing << endl;
//don't reparse missing units, because it may cause the whole project to be reparsed
// parseFilesAndDependencies( missing, true, false, files.hasFlag( ParseEmitWaiting::Silent ) );
}
if( files.hasFlag( ParseEmitWaiting::Silent ) ) {
if( alwaysParseInBackground )
for( QStringList::iterator it = files.res.begin(); it != files.res.end(); ++it )
m_backgroundParser->removeFile( *it );
} else {
if( !canUpdate ) { ///If the current model could be updated, do not emit addedSourceInfo(..) and remove the units from the parser, because nobody will be using them
QStringList l = files.res;
while(!l.isEmpty() ) {
emit aboutToRemoveSourceInfo( l.front() );
emit removedSourceInfo( l.front() );
emit addedSourceInfo( l.front() );
l.pop_front();
}
if( !files.hasFlag( ParseEmitWaiting::Silent ) )
emitFileParsed( files );
} else {
QStringList l = files.res;
while( !l.isEmpty() ) {
emit codeModelUpdated( l.front() );
emit aboutToRemoveSourceInfo( l.front() );
emit removedSourceInfo( l.front() );
emit addedSourceInfo( l.front() );
l.pop_front();
}
}
}
kdDebug( 9007 ) << "files in code-model after parseEmit: " << codeModel()->fileList().count() << " before: " << oldFileCount << endl;
}
}
/*void CppSupportPart::recomputeCodeModel( const QString& fileName )
{*/
//}
void CppSupportPart::emitSynchronousParseReady( const QString& file, ParsedFilePointer unit ) {
emit synchronousParseReady( file, unit );
}
void CppSupportPart::emitFileParsed( QStringList l )
{
while( !l.isEmpty() ) {
emit fileParsed( l.front() );
l.pop_front();
}
}
bool CppSupportPart::isHeader( const QString& fileName ) const
{
/*KMimeType::Ptr ptr = KMimeType::findByPath( fileName );
if ( ptr && m_headerMimeTypes.contains( ptr->name() ) )
return true;*/
return ( m_headerExtensions.findIndex( QFileInfo( fileName ).extension() ) != -1 );
}
bool CppSupportPart::isSource( const QString& fileName ) const
{
/*KMimeType::Ptr ptr = KMimeType::findByPath( fileName );
if ( ptr && m_sourceMimeTypes.contains( ptr->name() ) )
return true;*/
return ( m_sourceExtensions.findIndex( QFileInfo( fileName ).extension() ) != -1 );
}
void CppSupportPart::gotoDeclarationLine( int line )
{
if ( isHeader( m_activeFileName ) )
m_activeViewCursor->setCursorPositionReal( line, 0 );
else
{
KURL url;
url.setPath( sourceOrHeaderCandidate() );
partController() ->editDocument( url, line );
}
}
void CppSupportPart::removeCatalog( const QString & dbName )
{
if ( !QFile::exists( dbName ) )
return ;
QValueList<Catalog*> catalogs = codeRepository() ->registeredCatalogs();
Catalog* c = 0;
for ( QValueList<Catalog*>::Iterator it = catalogs.begin(); it != catalogs.end(); ++it )
{
if ( ( *it ) ->dbName() == dbName )
{
c = *it;
break;
}
}
if ( c )
{
codeRepository() ->unregisterCatalog( c );
m_catalogList.remove( c );
}
QFileInfo fileInfo( dbName );
QDir dir( fileInfo.dir( true ) );
QStringList indexList = QStringList() << "kind" << "name" << "scope" << "fileName" << "prefix";
for(QStringList::Iterator iter = indexList.begin(); iter != indexList.end(); iter++)
{
QStringList fileList = dir.entryList( fileInfo.baseName(true) +"." +(*iter) + ".idx" );
for ( QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it )
{
QString idxName = fileInfo.dirPath( true ) + "/" + *it;
kdDebug( 9007 ) << "=========> remove db index: " << idxName << endl;
dir.remove( *it );
}
}
dir.remove( fileInfo.fileName() );
}
void CppSupportPart::addCatalog( Catalog * catalog )
{
m_catalogList.append( catalog );
codeRepository() ->registerCatalog( catalog );
}
FunctionDefinitionDom CppSupportPart::functionDefinitionAt( int line, int column )
{
if ( !codeModel() ->hasFile( m_activeFileName ) )
return FunctionDefinitionDom();
CodeModelUtils::CodeModelHelper h( codeModel(), codeModel()->fileByName( m_activeFileName ) );
FunctionDom d = h.functionAt( line, column, CodeModelUtils::CodeModelHelper::Definition );
if( d ) {
FunctionDefinitionModel* m = dynamic_cast<FunctionDefinitionModel*>( d.data() );
if( m ) return FunctionDefinitionDom( m );
}
return FunctionDefinitionDom();
}
FunctionDefinitionDom CppSupportPart::currentFunctionDefinition( )
{
if ( !this->m_activeViewCursor )
return FunctionDefinitionDom();
unsigned int line, column;
this->m_activeViewCursor->cursorPositionReal( &line, &column );
return functionDefinitionAt( line, column );
}
void CppSupportPart::slotCursorPositionChanged()
{
if ( codeCompletion() )
{
unsigned int line = 0;
unsigned int column = 0;
if ( KDevEditorUtil::currentPositionReal( &line, &column, dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ) )
{
QString typeInfoString = codeCompletion()->createTypeInfoString( line, column );
mainWindow()->statusBar()->message( typeInfoString );
}
}
// m_functionHintTimer->changeInterval( 1000 );
if ( splitHeaderSourceConfig()->splitEnabled()
&& splitHeaderSourceConfig()->autoSync() )
slotSwitchHeader( true );
}
/*
void CppSupportPart::slotFunctionHint( )
{
kdDebug( 9007 ) << "=======> compute current function definition" << endl;
// m_functionHintTimer->stop();
if ( FunctionDefinitionDom fun = currentFunctionDefinition() )
{
QStringList scope = fun->scope();
QString funName = scope.join( "::" );
if ( !funName.isEmpty() )
funName += "::";
funName += formatModelItem( fun, true );
mainWindow() ->statusBar() ->message( funName, 2000 );
}
}
*/
void CppSupportPart::createIgnorePCSFile( )
{
static QCString skip_me( "ignore me\n" );
QString skip_file_name = project() ->projectDirectory() + "/"
+ project() ->projectName() + ".kdevelop.ignore_pcs";
QFile skip_pcs_file( skip_file_name );
if ( skip_pcs_file.open( IO_WriteOnly ) )
{
skip_pcs_file.writeBlock( skip_me );
skip_pcs_file.close();
}
}
QString CppSupportPart::specialHeaderName( bool local ) const
{
if ( local )
return ::locateLocal( "data", "kdevcppsupport/configuration", CppSupportFactory::instance() );
return ::locate( "data", "kdevcppsupport/configuration", CppSupportFactory::instance() );
}
void CppSupportPart::updateParserConfiguration()
{
m_backgroundParser->updateParserConfiguration();
QString conf_file_name = specialHeaderName();
m_driver->removeAllMacrosInFile( conf_file_name );
dynamic_cast<KDevDriver*>(m_driver)->setup();
m_driver->parseFile( conf_file_name, true, true, true );
m_buildSafeFileSetTimer->start( 500, true );
parseProject( true );
}
const Driver* CppSupportPart::driver() const {
return m_driver;
}
Driver* CppSupportPart::driver() {
return m_driver;
}
KDevDesignerIntegration * CppSupportPart::designer( KInterfaceDesigner::DesignerType type )
{
KDevDesignerIntegration * des = 0;
switch ( type )
{
case KInterfaceDesigner::Glade:
case KInterfaceDesigner::QtDesigner:
des = m_designers[ type ];
if ( des == 0 )
{
CppImplementationWidget * impl = new CppImplementationWidget( this );
des = new QtDesignerCppIntegration( this, impl );
des->loadSettings( *project() ->projectDom(), "kdevcppsupport/designerintegration" );
m_designers[ type ] = des;
}
break;
}
return des;
}
void CppSupportPart::resetParserStoreTimer() {
// m_deleteParserStoreTimer->start(10000); ///try to empty the store regularly
}
void CppSupportPart::slotDeleteParserStore() {
/* if( !m_backgroundParser->filesInQueue() )
m_backgroundParser->removeAllFiles();
else
resetParserStoreTimer();*/
}
void CppSupportPart::slotCreateSubclass()
{
QFileInfo fi( m_contextFileName );
if ( fi.extension( false ) != "ui" )
return ;
QtDesignerCppIntegration *des = dynamic_cast<QtDesignerCppIntegration*>( designer( KInterfaceDesigner::QtDesigner ) );
if ( des )
des->selectImplementation( m_contextFileName );
}
void CppSupportPart::addMethod( ClassDom aClass, const QString& name, const QString type,
const QString& parameters, CodeModelItem::Access accessType,
bool isConst, bool isInline, bool isVirtual, bool isPureVirtual,
const QString& implementation )
{
partController() ->editDocument( KURL( aClass->fileName() ) );
KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( partController() ->activePart() );
if ( !editIface )
{
/// @fixme show messagebox
return ;
}
QString declarationString = type + " " + name + "(" + parameters + ")" + ( isConst ? " const" : "" );
KDevSourceFormatter* sourceFormatter = extension<KDevSourceFormatter>( "KDevelop/SourceFormatter" );
QString finalDeclaration = ( ( isVirtual || isPureVirtual ) ? "\nvirtual " : "\n" + declarationString +
( isPureVirtual ? " = 0 " : "" ) +
( isInline ? "\n{\n" + implementation + "\n}\n" : ";" ) );
if ( sourceFormatter != 0 )
finalDeclaration = sourceFormatter->formatSource( finalDeclaration );
QString indentString = "\t";
if ( sourceFormatter != 0 )
indentString = sourceFormatter->indentString();
editIface->insertText( findInsertionLineMethod( aClass, accessType ), 0,
finalDeclaration.replace( "\n", "\n\t" ) + "\n" );
backgroundParser() ->addFile( aClass->fileName() );
if ( isInline || isPureVirtual )
return ;
// construct fully qualified name for method definition
QString fullyQualifiedName = aClass->scope().join("::");
if (! fullyQualifiedName.isEmpty())
{
fullyQualifiedName += "::";
}
fullyQualifiedName += aClass->name() + "::" + name;
QString definitionString = "\n" + type + " " + fullyQualifiedName + "(" + parameters + ")" + ( isConst ? " const" : "" ) + "\n{\n" + implementation + "\n}\n";
if ( sourceFormatter != 0 )
definitionString = sourceFormatter->formatSource( definitionString );
QFileInfo info( aClass->fileName() );
QString implementationFile = info.dirPath( true ) + "/" + info.baseName() + ".cpp" ;
QFileInfo fileInfo( implementationFile );
KDevCreateFile* createFileSupport = extension<KDevCreateFile>( "KDevelop/CreateFile" );
if ( !QFile::exists( fileInfo.absFilePath() ) && createFileSupport != 0 )
createFileSupport->createNewFile( fileInfo.extension(), fileInfo.dirPath( true ), fileInfo.baseName() );
partController() ->editDocument( KURL( implementationFile ) );
editIface = dynamic_cast<KTextEditor::EditInterface*>( partController() ->activePart() );
if ( !editIface )
return ; //@fixme errorverdoedelung
editIface->insertLine( editIface->numLines(), QString::fromLatin1( "" ) );
editIface->insertText( editIface->numLines() - 1, 0, definitionString );
backgroundParser() ->addFile( implementationFile );
}
ClassDom CppSupportPart::currentClass( ) const
{
FileDom file = codeModel() ->fileByName( m_activeFileName );
if ( file == 0 || m_activeViewCursor == 0 )
return 0;
unsigned int curLine, curCol;
m_activeViewCursor->cursorPositionReal( &curLine, &curCol );
CodeModelUtils::CodeModelHelper h( codeModel(), file );
return h.classAt( curLine, curCol );
}
VariableDom CppSupportPart::currentAttribute( ClassDom curClass ) const
{
if ( m_activeViewCursor == 0 || curClass == 0 )
return 0;
unsigned int line, col;
m_activeViewCursor->cursorPositionReal( &line, &col );
VariableList vars = curClass->variableList();
for ( VariableList::iterator i = vars.begin(); i != vars.end(); ++i )
{
int startLine, startCol;
( *i ) ->getStartPosition( &startLine, &startCol );
if ( startLine < (int)line || ( startLine == (int)line && startCol <= (int)col ) )
{
int endLine, endCol;
( *i ) ->getEndPosition( &endLine, &endCol );
if ( endLine > (int)line || ( endLine == (int)line && endCol >= (int)col ) )
return * i;
}
}
return 0;
}
void CppSupportPart::slotCreateAccessMethods( )
{
if ( m_curAttribute == 0 || m_curClass == 0 )
return ;
CreateGetterSetterDialog dlg ( this, m_curClass, m_curAttribute );
dlg.exec();
}
int CppSupportPart::findInsertionLineMethod( ClassDom aClass, CodeModelItem::Access access )
{
int line, column;
aClass->getEndPosition( &line, &column );
int point = CodeModelUtils::findLastMethodLine( aClass, access );
if ( point == -1 )
{
KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( partController() ->activePart() );
if ( !editIface )
return -1;
editIface->insertLine( line - 1, CodeModelUtils::accessSpecifierToString( access ) + ":\n" );
return line;
}
return point + 1;
}
int CppSupportPart::findInsertionLineVariable( ClassDom aClass, CodeModelItem::Access access )
{
int line, column;
aClass->getEndPosition( &line, &column );
int point = CodeModelUtils::findLastVariableLine( aClass, access );
if ( point == -1 )
{
KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( partController() ->activePart() );
if ( !editIface )
return -1;
editIface->insertLine( line - 1, CodeModelUtils::accessSpecifierToString( access ) + ":\n" );
return line;
}
return point;
}
void CppSupportPart::createAccessMethods( ClassDom theClass, VariableDom theVariable )
{
m_curClass = theClass;
m_curAttribute = theVariable;
slotCreateAccessMethods();
}
void CppSupportPart::slotCursorMoved()
{
m_cursorMovedTimer->start( 250, true );
}
void CppSupportPart::slotTextChanged()
{
setTyping( true ); ///@todo check if this is really needed
if ( m_backgroundParserConfig->useBackgroundParser() )
{
m_textChangedTimer->start( m_backgroundParserConfig->backgroudParseDelay(), true );
}
}
void CppSupportPart::slotParseCurrentFile()
{
if( isValid() && !isQueued( m_activeFileName ) )
{
parseFileAndDependencies( m_activeFileName, true, true );
}
}
void CppSupportPart::updateBackgroundParserConfig()
{
BackgroundParserConfig config;
config.readConfig();
if ( m_backgroundParserConfig->useProblemReporter() && !config.useProblemReporter() )
{
removeProblemReporter();
}
else if ( !m_backgroundParserConfig->useProblemReporter() && config.useProblemReporter() )
{
embedProblemReporter( true );
}
*m_backgroundParserConfig = config;
}
const SynchronizedFileSet& CppSupportPart::safeFileSet() const {
return m_safeProjectFiles;
}
SynchronizedFileSet& CppSupportPart::safeFileSet() {
return m_safeProjectFiles;
}
void CppSupportPart::buildSafeFileSet() {
if( codeCompletion() == 0 ) //probably the project has already been closed
return;
SynchronizedFileSet::SetType files; //everything that goes into this set must be deep-copied
kdDebug( 9007 ) << "CppSupportPart:: rebuilding safe-file-set" << endl;
for( QStringList::const_iterator it = m_projectFileList.begin(); it != m_projectFileList.end(); ++it ) {
QFileInfo fi( *it );
QString file = *it;
if( fi.isRelative() ) {
fi.setFile( QDir(m_projectDirectory), *it );
file = fi.absFilePath();
}
//deep-copy
files.insert( QString::fromUtf8(file.utf8()) );
}
///Now get all translation-units from the code-repository
QValueList<Catalog::QueryArgument> args;
args << Catalog::QueryArgument( "kind", Tag::Kind_TranslationUnit );
QValueList<Tag> tags( codeCompletion()->repository()->query( args ) );
for( QValueList<Tag>::const_iterator it = tags.begin(); it != tags.end(); ++it ) {
files.insert( (*it).fileName() + "||" + (*it).attribute("macroValueHash").toString() + "||" + (*it).attribute("macroIdHash").toString() );
}
m_safeProjectFiles.setFiles( files );
}
void CppSupportPart::addToRepository( ParsedFilePointer file ) {
QString catalogString( "automatic_" + KURL::encode_string_no_slash(m_projectDirectory) );
KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
QString dbName = dirs->saveLocation( "data", "kdevcppsupport/pcs" ) + catalogString + ".db";
Catalog* catalog = 0;
///First check if the catalog is already there
QValueList<Catalog*> catalogs = codeRepository()->registeredCatalogs();
for( QValueList<Catalog*>::const_iterator it = catalogs.begin(); it != catalogs.end(); ++it ) {
if( (*it)->dbName() == dbName ) {
catalog = *it;
break;
}
}
if( !catalog ) {
kdDebug( 9007 ) << "creating new catalog named " << catalogString << " for automatic filling" << endl;
//QStringList indexList = QStringList() << "kind" << "name" << "scope" << "fileName" << "prefix";
catalog = new Catalog;
catalog->open( dbName );
catalog->addIndex( "kind" );
catalog->addIndex( "name" );
catalog->addIndex( "scope" );
catalog->addIndex( "prefix" );
catalog->addIndex( "fileName" );
/*
for ( QStringList::Iterator idxIt = indexList.begin(); idxIt != indexList.end(); ++idxIt )
catalog->addIndex( ( *idxIt ).utf8() );*/
addCatalog( catalog );
}
catalog->setEnabled( true );
///Now check if the file was already parsed with the same parameters, if yes don't parse again(auto-update is currently not supported, when major changes have been done in the libraries, the repository should be deleted)
QValueList<Catalog::QueryArgument> args;
bool compatibleParsed = false;
Tag compatibleParsedTag;
args << Catalog::QueryArgument( "kind", Tag::Kind_TranslationUnit );
args << Catalog::QueryArgument( "fileName", file->fileName() );
QValueList<Tag> tags( catalog->query( args ) );
if( !tags.isEmpty() ) {
for( QValueList<Tag>::const_iterator it = tags.begin(); it != tags.end(); ++it ) {
if( (*it).hasAttribute( "cppparsedfile" ) ) {
QVariant v = (*it).attribute( "cppparsedfile" );
///@todo reenable this
/*QByteArray b = v.toByteArray();
if( !b.isEmpty() ) {
//Would be much more efficient not to do this deserialization
ParsedFile f(b);
if( f.usedMacros().valueHash() == file->usedMacros().valueHash() && f.usedMacros().idHash() == file->usedMacros().idHash() && f.includeFiles().hash() == file->includeFiles().hash() ) {
///Do not reparse the file, it seems to already be in the repository in a similar state
if( (*it).attribute( "includedFrom" ).toString() == file->includedFrom() ) return;
///It is probable that the same state has already been parsed, but there seems to be no such tag yet(the tag will be added)
compatibleParsed = true;
compatibleParsedTag = *it;
break;
}
}*/
}
}
}
if( compatibleParsed ) {
///Add a Tag that makes sure that the file will not be parsed again
compatibleParsedTag.setAttribute( "includedFrom", file->includedFrom() );
QByteArray data;
QDataStream s( data, IO_WriteOnly );
file->write( s );
compatibleParsedTag.setAttribute( "cppparsedfile", data );
catalog->addItem( compatibleParsedTag );
return;
}
kdDebug( 9007 ) << "parsing translation-unit " << file->fileName() << " into catalog " << catalogString << endl;
TagCreator w( file->fileName(), catalog );
w.parseTranslationUnit( *file );
codeRepository()->touchCatalog( catalog );
m_safeProjectFiles.insert( file->fileName() + "||" + QString("%1").arg(file->usedMacros().valueHash()) + "||" + QString("%1").arg(file->usedMacros().idHash()) );
}
QString CppSupportPart::findHeaderSimple( const QString &header )
{
QStringList::ConstIterator it;
for ( it = m_projectFileList.begin(); it != m_projectFileList.end(); ++it )
{
QString s = *it;
if (s == header)
return s;
if ( ( s.right( header.length() ) == header ) && ( s[s.length() - header.length() - 1] == '/' ) )
return s;
}
return QString::null;
}
UIBlockTester::UIBlockTesterThread::UIBlockTesterThread( UIBlockTester& parent ) : QThread(), m_parent( parent ), m_stop(false) {
}
void UIBlockTester::UIBlockTesterThread::run() {
while(!m_stop) {
msleep( m_parent.m_msecs / 10 );
m_parent.m_timeMutex.lock();
QDateTime t = QDateTime::currentDateTime();
uint msecs = m_parent.m_lastTime.time().msecsTo( t.time() );
if( msecs > m_parent.m_msecs ) {
m_parent.lockup();
m_parent.m_lastTime = t;
}
m_parent.m_timeMutex.unlock();
}
}
void UIBlockTester::UIBlockTesterThread::stop() {
m_stop = true;
}
UIBlockTester::UIBlockTester( uint milliseconds ) : m_thread( *this ), m_msecs( milliseconds ) {
m_timer = new QTimer( this );
m_timer->start( milliseconds/10 );
connect( m_timer, SIGNAL(timeout()), this, SLOT(timer()) );
timer();
m_thread.start();
}
UIBlockTester::~UIBlockTester() {
m_thread.stop();
m_thread.wait();
}
void UIBlockTester::timer() {
m_timeMutex.lock();
m_lastTime = QDateTime::currentDateTime();
m_timeMutex.unlock();
}
void UIBlockTester::lockup() {
//std::cout << "UIBlockTester: lockup of the UI for " << m_msecs << endl; ///kdDebug(..) is not thread-safe..
int a = 1; ///Place breakpoint here
}
#include "cppsupportpart.moc"
//kate: indent-mode csands; tab-width 4; space-indent off;
|