Blame view
circus/src/jcircus/translator/Translator2Java.java
113 KB
8d0dc533f
![]() |
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 |
package jcircus.translator; import java.io.File; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.Vector; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; //import paper.src.paper.typing.VALUE; import jcircus.complementaryenvs.CallProc2ChannelSetEnv; import jcircus.complementaryenvs.ChanComplexCommEnv; import jcircus.complementaryenvs.ChanDimEnv; import jcircus.complementaryenvs.ChanDotFieldEnv; import jcircus.complementaryenvs.ChanExtChoiceEnv; import jcircus.complementaryenvs.ChanForcedInterleavingEnv; import jcircus.complementaryenvs.ChanTransMSEnv; import jcircus.complementaryenvs.Coadj2SimpleSynchTransEnv; import jcircus.complementaryenvs.PId2PNameEnv; import jcircus.complementaryenvs.ProcCreateMainEnv; import jcircus.complementaryenvs.ProcName2ProcChanEnv; import jcircus.complementaryenvs.ProcProcessParaEnv; import jcircus.complementaryenvs.TypeSizeEnv; import jcircus.complexcomms.AbsCommValuesGenerator; import jcircus.complexcomms.CCMapsGenerator; import jcircus.complexcomms.CCUpdater; import jcircus.complexcomms.CCUtil; import jcircus.complexcomms.Channel2TypeEnvironment; //import jcircus.complexcomms.ComplexCommUpdater; import jcircus.environment.ChanInfoEnv; import jcircus.environment.ChanUseEnv; import jcircus.environment.Environment; import jcircus.environment.ProcChanEnv; import jcircus.environment.ProcChanUseEnv; import jcircus.exceptions.FailParsingException; import jcircus.exceptions.FailTranslationException; import jcircus.exceptions.FailTypeCheckingException; import jcircus.exceptions.TranslationCancelledException; import jcircus.exceptions.runtime.InvalidSubTypeException; import jcircus.exceptions.runtime.VisitorException; import jcircus.exceptions.JCircusException; import jcircus.exceptions.runtime.UnrecoveredErrorException; import jcircus.generators.GCArrayGenerator; import jcircus.generators.GPSEGenerator; import jcircus.gui.JCircusFrame; import jcircus.newfrontendmethod.FrontEndCounter; import jcircus.newfrontendmethod.FrontEndUpdater; import jcircus.newutil.CallUtil; import jcircus.newutil.ChannelUtil; import jcircus.newutil.ExceptionUtil; import jcircus.newutil.PrinterUtil; import jcircus.newutil.ProcessUtil; import jcircus.newutil.TypeUtil; import jcircus.parallelism.CopyProcessAnn; import jcircus.parallelism.CopyUpdater; import jcircus.parallelism.HiddenFromGUIInfo; import jcircus.parallelism.ParallelismUpdater; import jcircus.parallelism.ProcHiddenFromGUIEnv; import jcircus.util.CircusType; import jcircus.util.CodeFormatting; import jcircus.util.Constants; import jcircus.util.ChanUse; import jcircus.util.MathToolkitConstants; import jcircus.util.ProcInfo; import jcircus.util.Util; import jcircus.visitor.EnvLoadingVisitor; import jcircus.visitor.TranslatorVisitor; import net.sourceforge.czt.base.ast.ListTerm; import net.sourceforge.czt.base.ast.Term; import net.sourceforge.czt.circus.ast.CircusProcess; import net.sourceforge.czt.circus.ast.ParamProcess; import net.sourceforge.czt.circus.ast.ProcessPara; import net.sourceforge.czt.z.ast.AxPara; import net.sourceforge.czt.z.ast.Branch; import net.sourceforge.czt.z.ast.Decl; import net.sourceforge.czt.z.ast.DeclList; import net.sourceforge.czt.z.ast.NarrSect; import net.sourceforge.czt.z.ast.Sect; import net.sourceforge.czt.z.ast.ZBranchList; import net.sourceforge.czt.z.ast.ZDeclList; import net.sourceforge.czt.z.ast.ZName/*DeclName*/; import net.sourceforge.czt.z.ast.Expr; import net.sourceforge.czt.z.ast.Freetype; import net.sourceforge.czt.z.ast.Para; import net.sourceforge.czt.z.ast.RefExpr; import net.sourceforge.czt.z.ast.Spec; import net.sourceforge.czt.z.ast.VarDecl; import net.sourceforge.czt.z.ast.ZSect; import net.sourceforge.czt.z.impl.ZSectImpl; import net.sourceforge.czt.z.util.Factory; import newjcircusutil.multisync.GeneralChannel; import jcircus.JCircusController; /** * Translator2Java.java * * @authors Angela Freitas & Samuel Barrocas */ public class Translator2Java { private boolean hasExpandedCallActions = false; private JCircusFrame _jCircusFrame; private String _projectDir; private String _projectName; private String _compl = ""; //Acrescentado por Samuel private Spec/*Term*/ _spec; private TranslatorVisitor _translatorVisitor; private EnvLoadingVisitor _envLoadingVisitor; private Environment _environment; private List<ProcInfo> _procInfoList; private List<ProcInfo> _procInfoList2; private List<String> _axParaCodeList; private boolean useBarriers; //Sam's private ChanDimEnv updatedChanDimEnv; private ChanDotFieldEnv chanDotFieldEnv; private ProcCreateMainEnv pcme = new ProcCreateMainEnv (); private ProcProcessParaEnv procProcessParaEnv; public ProcProcessParaEnv getProcProcessParaEnv () { return this.procProcessParaEnv; } public void setProcProcessParaEnv (ProcProcessParaEnv env) { this.procProcessParaEnv = env; } private PId2PNameEnv id2name = new PId2PNameEnv (); public PId2PNameEnv getPId2PNameEnv () { return this.id2name; } private ProcName2ProcChanEnv pn2pce = new ProcName2ProcChanEnv (); public ProcName2ProcChanEnv getProcName2ProcChanEnv () { return this.pn2pce; } public void setProcName2ProcChanEnv (ProcName2ProcChanEnv pn2pce) { this.pn2pce = pn2pce; } private CallProc2ChannelSetEnv cp2cse = new CallProc2ChannelSetEnv (); private int minComm; //Sam's private int maxComm; //Sam's public CallProc2ChannelSetEnv getCallProc2ChannelSetEnv () { return this.cp2cse; } public Channel2TypeEnvironment cte = new Channel2TypeEnvironment (); private ChanForcedInterleavingEnv cfie; private ChanComplexCommEnv ccce; private CopyUpdater copyUpdater = new CopyUpdater (); //Sam's private ParallelismUpdater parallelismUpdater = new ParallelismUpdater (); //Sam's private /*ComplexCommUpdater*/CCUpdater complexCommUpdater = new CCUpdater ();/*new ComplexCommUpdater ();*/ //Sam's private FrontEndUpdater frontEndUpdater = new FrontEndUpdater (); //Sam's private ChanExtChoiceEnv cece = new ChanExtChoiceEnv (); //Sam's //private boolean createMain = false; public void setChanExtChoiceEnv (ChanExtChoiceEnv cece) { //Sam's this.cece = cece; } ProcHiddenFromGUIEnv prochid = new ProcHiddenFromGUIEnv (); boolean fullparallelism; /** * Constructor. * */ Spec spec; boolean bench; boolean cmain; public Translator2Java(String projectDir, String projectName, Spec spec, String compl, boolean useBarriers, boolean parallelism, boolean bench, JCircusFrame jcf, boolean createmain) { this.cmain = createmain; this.bench = bench; this._projectDir = projectDir; this._projectName = projectName; this._spec = spec; this._compl = compl; //Sam's this._environment = new Environment(); this._envLoadingVisitor = new EnvLoadingVisitor( this._environment, projectDir, projectName, _compl, useBarriers, this.bench); this._translatorVisitor = new TranslatorVisitor( this._environment, projectDir, projectName, useBarriers, this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanTypeEnv4CC(), this._envLoadingVisitor.getChanDimEnv(), _compl, this._envLoadingVisitor.getProcProcessParaEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getPId2PNameEnv(), this._envLoadingVisitor.getCallProc2ChannelSetEnv(), 0, //minComm, this._envLoadingVisitor.getMaxAbsValueComm(),//maxComm, this._envLoadingVisitor.getChanForcedInterleavingEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getTypeSizeEnv(), spec, createmain, this._envLoadingVisitor.getMuActs2Indexes() //,this.prochid ); this.chanDotFieldEnv = _envLoadingVisitor.getChanDotFieldEnv(); this._procInfoList = new ArrayList<ProcInfo>(); this._procInfoList2 = new ArrayList<ProcInfo>(); this._axParaCodeList = new ArrayList<String>(); this.id2name = this._envLoadingVisitor.getPId2PNameEnv(); this.useBarriers = useBarriers; //By Samuel Barrocas 16/12/2010, 17:31hs this.fullparallelism = parallelism; this.setProcProcessParaEnv(this._envLoadingVisitor.getProcProcessParaEnv()); //By Samuel Barrocas 16/12/2010, 17:31hs this.setProcName2ProcChanEnv(this._envLoadingVisitor.getProcName2ProcChanEnv()); this.cp2cse = this._envLoadingVisitor.getCallProc2ChannelSetEnv(); this.minComm = 0; this.maxComm = this._envLoadingVisitor.getMaxAbsValueComm(); this.cfie = this._envLoadingVisitor.getChanForcedInterleavingEnv(); this.ccce = this._envLoadingVisitor.getChanComplexCommEnv(); this.cte = this._envLoadingVisitor.getChanTypeEnv4CC(); this._jCircusFrame = jcf; this.pcme = jcf.getProcCreateMainEnv(); System.out.print(""); } public static String brackets (int dim) { String r = ""; for (int i = 0; i < dim; i++) { r = r + "[]"; } return r; } /** * Main method of this class. * * @param projectDir * @param projectName * @param spec * @param nameProjectRun * @throws Exception */ public void translate(boolean gui) throws FailTranslationException { //_projectDir = _projectDir + "\\" + _projectName + "\\" + Constants.DIR_SOURCE; _projectDir = _projectDir + "/" + _projectName + "/" + Constants.DIR_SOURCE; //In the linux version of JCircus, it is necessary to replace the \\ by / System.out.println (PrinterUtil.specAsString(_spec)); /**Estas duas tem que ir juntas! Se um dia expandCallsOnMainActions for comentada, this.hasExpandedCallActions também tem que ser!!*/ CallUtil.expandCallsOnMainActions(_spec, hasExpandedCallActions); this.hasExpandedCallActions = true; /**Estas duas tem que ir juntas! Se um dia expandCallsOnMainActions for comentada, this.hasExpandedCallActions também tem que ser!!*/ System.out.println (PrinterUtil.specAsString(_spec)); ProcessUtil.updateProcessesToBasicProcesses (_spec, hasExpandedCallActions); System.out.println (PrinterUtil.specAsString(_spec)); if (fullparallelism) { copyUpdater.updateSpec(_spec); System.out.println ("CopyUpdater.updateSpec"); parallelismUpdater.updateSpec(_spec); System.out.println ("ParallelismUpdater.updateSpec"); } if (fullparallelism) { complexCommUpdater.updateSpec (_spec); System.out.println ("ComplexCommUpdater.updateSpec"); frontEndUpdater.updateSpec (_spec); System.out.println (PrinterUtil.specAsString(_spec)); System.out.print(""); /*try { //JOptionPane.showMessageDialog(null, "At Translator2Java, before second typechecking"); JCircusController.typeCheck (_spec); //JOptionPane.showMessageDialog(null, "At Translator2Java, after second typechecking"); } catch (FailTypeCheckingException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, "Typechecking after ParallelismUpdater: "); e.printStackTrace(); System.exit(0); }*/ this.prochid = parallelismUpdater.prochid; this._translatorVisitor.setProcHid(this.prochid); } Spec _spec2 = (new Factory ()).createSpec(_spec.getSect(), "1.5"); ProcInfoUpdater.initProcInfoAndCreateMainEnv (_jCircusFrame.getProcCreateMainEnv(), _procInfoList2, _spec, fullparallelism, cmain); if (!cmain) { try { _jCircusFrame.promptForMainProcessesPCME (_procInfoList2); } catch (TranslationCancelledException e) { e.printStackTrace(); } } try { //ProcInfoUpdater.initProcCreateMainEnv (this.pcme, _spec, gui); _envLoadingVisitor.setProcCreateMainEnv(this.pcme); _envLoadingVisitor.visitSpec(_spec); //Angela's System.out.println ("EnvLoadingVisitor.visitSpec"); this._translatorVisitor.setChanDimEnv(_envLoadingVisitor); this._translatorVisitor.setChanExtChoiceEnv(this._envLoadingVisitor.getChanExtChoiceEnv()); this.updatedChanDimEnv = TranslatorVisitor.updateChanDim(this._envLoadingVisitor.getChanDimEnv(), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), cmain); this._translatorVisitor.setUpdatedChanDimEnv(this.updatedChanDimEnv); this._translatorVisitor.setProcCreateMainEnv (this._envLoadingVisitor.getProcCreateMainEnv ()); System.out.print (""); } catch (UnrecoveredErrorException e) { // There was a fatal error //System.out.println ("Exception 1"); throw new FailTranslationException(_envLoadingVisitor.getErrors(), e); } System.out.println ("Aqui estamos depois de throw new FailTranslationException"); if (!_envLoadingVisitor.getErrors().isEmpty()) { // There was not a fatal error, but errors need to be reported System.out.println (PrinterUtil.specAsString(_spec2)); System.out.println ("Dentro de !_envLoading, antes de FailTranslation"); ExceptionUtil.throwException (_envLoadingVisitor.getErrors().toString()); throw new FailTranslationException(_envLoadingVisitor.getErrors()); } System.out.println ("Aqui estamos depois de !_envLoadingVisitor.getErrors().isEmpty()"); // Iterates over the paragraphs to translate and loads information about // process paragraphs and axiomatic definitions //System.out.println ("....----....----...."); System.out.println ("Vai para Iterator iterator, em Translator2Java"); Iterator iterator; if (_spec.getSect().get(0) instanceof ZSectImpl) { iterator = ((List<Sect>) ((ZSect) (_spec).getSect().get(0)).getParaList()).iterator(); } else { iterator = ((List<Sect>) ((ZSect) (_spec).getSect().get(1)).getParaList()).iterator(); } while (iterator.hasNext()) { Para para = (Para) iterator.next(); if (para instanceof ProcessPara) { System.out.println ("Translator2Java vendo o processo " + ((ProcessPara)para).getZName().toString()); if (!CopyProcessAnn.isCopy((ProcessPara)para)) { ZName/*DeclName*/ procName = ((ProcessPara) para).getZName/*getDeclName*/(); CircusProcess circusProcess = ((ProcessPara) para).getCircusProcess(); System.out.print ("Vendo ainda..."); String procParaCode = null; try { procParaCode = (String) para.accept(_translatorVisitor); System.out.println ("para.accept(_translatorVisitor)"); } catch (UnrecoveredErrorException e) { System.out.println ("Catchou uma exception UnrecoveredError"); // There was a fatal error throw new FailTranslationException(_translatorVisitor.getErrors(), e); } if (!_translatorVisitor.getErrors().isEmpty()) { // There was not a fatal error List <jcircus.util.Error> errors = _translatorVisitor.getErrors(); throw new FailTranslationException(_translatorVisitor.getErrors()); } // If this is not being run with GUI, a class Main will be created // only for those processes which are not parameterized boolean createMain; if (!gui && !(circusProcess instanceof ParamProcess)) { createMain = true; } else { createMain = false; } // Stores information about the process definition ProcInfo procInfo = new ProcInfo(procName.toString(), (ProcessPara) para, procParaCode, getNormalizedParams(circusProcess), createMain); _procInfoList.add(procInfo); System.out.print (""); System.out.println ("Translator2Java terminou de ver o processo " + PrinterUtil.printProcess (((ProcessPara)para).getCircusProcess(), this._spec)); } } else if (para instanceof AxPara) { // Translates the axiomatic definition String axParaCode = (String) para.accept(_translatorVisitor); _axParaCodeList.add(axParaCode); } else { //System.out.println ("Nem ProcessPara, nem AxPara"); } } } /** * This method is the implementation of * * |[ CircusProgram ]|^{Program} proj * * in the strategy, where: * * - CircusProgram is the program defined by the attribute Spec * - proj is the name of the project, defined by the attribute "projectName" */ public void createSources() throws JCircusException { // Create the directories for the project createDirStructure(); //In the linux version of JCircus, the \\ must be replaced by a / (new GPSEGenerator (this._envLoadingVisitor.dim + 3, this._envLoadingVisitor.getMinComm(), this._envLoadingVisitor.getMaxAbsValueComm(), "paper", "src", this._envLoadingVisitor.getProjectDir(), this._envLoadingVisitor.getSpecNameOnTranslation())).generateClass(); GCArrayGenerator.generate (this._envLoadingVisitor.dim + 3, this._envLoadingVisitor.getProjectDir() + "/" + this._envLoadingVisitor.getProjectName() + "/src/" + this._envLoadingVisitor.getProjectName() + "/typing/GCArray.java", this._envLoadingVisitor.getSpecNameOnTranslation()); Vector <AbsCommValuesGenerator> absGens = new Vector <AbsCommValuesGenerator> (); Vector <CCMapsGenerator> ccMapsGens = new Vector <CCMapsGenerator> (); absGens = this._envLoadingVisitor.getAbsGens(); ccMapsGens = this._translatorVisitor.getccMapsGens(); for (int i = 0; i < absGens.size(); i++) { absGens.elementAt(i).generate(); } for (int j = 0; j < ccMapsGens.size(); j++) { ccMapsGens.elementAt(j).generate(); } // Corresponds to function "DeclareTypeClass" in the // translation strategy documentation createTypeClass(); // Creates class that represents the basic type \arithmos (number) createCircusIntegerClass(); // Corresponds to function |[ ]|^{FreeTypes} in the strategy doc. createClassesForFreeTypes(); // Corresponds to function "DeclareAxDefClass" in the strategy doc. createAxDefHorizDefClass(); // Implements "|[ ProcDecls ]|^{ProcDecls} proj" in the strategy doc. for (int i = 0; i < _procInfoList.size(); i++) { ProcInfo procInfo = _procInfoList.get(i); //procInfo.setCreateMain(true); //Em CRefine, JCircus criará Main para todos os processos. // Class for process createProcessClass(procInfo.getProcessName(), procInfo.getCode()); // Main for process if (procInfo.getCreateMain()) { createClassMain(procInfo); createGUI(procInfo); createBatFile(procInfo); } } System.out.println("Source files for project \'" + _projectName + "\' were created at " + _projectDir); } /** * Creates the project folders. */ private void createDirStructure() throws SecurityException { /*File dirProcesses = new File(_projectDir + "\\" + _projectName + "\\" + Constants.PKG_PROCESSES); File dirAxDefs = new File(_projectDir + "\\" + _projectName + "\\" + Constants.PKG_AXDEFS); File dirTyping = new File(_projectDir + "\\" + _projectName + "\\" + Constants.PKG_TYPING); File dirGui = new File(_projectDir + "\\" + _projectName + "\\" + Constants.PKG_GUI); File dirChannels = new File(_projectDir + "\\" + _projectName + "\\" + "channels"); File dirCCMaps = new File(_projectDir + "\\" + _projectName + "\\" + "ccmaps");*/ File dirProcesses = new File(_projectDir + "/" + _projectName + "/" + Constants.PKG_PROCESSES); File dirAxDefs = new File(_projectDir + "/" + _projectName + "/" + Constants.PKG_AXDEFS); File dirTyping = new File(_projectDir + "/" + _projectName + "/" + Constants.PKG_TYPING); File dirGui = new File(_projectDir + "/" + _projectName + "/" + Constants.PKG_GUI); File dirChannels = new File(_projectDir + "/" + _projectName + "/" + "channels"); File dirCCMaps = new File(_projectDir + "/" + _projectName + "/" + "ccmaps"); dirProcesses.mkdirs(); dirAxDefs.mkdirs(); dirTyping.mkdirs(); dirGui.mkdirs(); dirChannels.mkdirs(); dirCCMaps.mkdirs(); } /** * Pg. 165. * * @param projectDir * @param projectName */ private void createTypeClass() throws JCircusException { String typeConstants = declareTypeConstants(); String pkg = getPackage(_projectName, Constants.PKG_TYPING, _compl); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_TYPE_DECLCONST, typeConstants); map.put(Constants.C_TYPE_PKG, pkg); try { /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_TYPING + "\\" + Constants.CLS_TYPE + Constants.JAVA_EXT;*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_TYPING + "/" + Constants.CLS_TYPE + Constants.JAVA_EXT; Util.createFileFromTemplate(Constants.TMP_TYPE, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create Type class", t); } } /** * Returns Java code for the declaration of constants for all the types. * Pg. 166. * * @return */ private String declareTypeConstants() { String code = ""; int numberFt = _environment.freeTypesEnvironmentSize(); // Insert all the free types for (int i = 0; i < numberFt; i++) { Freetype ft = _environment.freeTypesEnvironmentGet(i); code += " public static final int " + ft.getZName()/*getDeclName*/ + " = " + i + ";"; } // Insert the CircusInteger type code += " public static final int " + Constants.CLS_CIRCNUM + " = " + numberFt + ";"; // min and max constants code += " public static final int MIN_TYPE_ID = 0;"; code += " public static final int MAX_TYPE_ID = " + numberFt + ";"; return code; } /** * Create CircusInteger.class * * @param projectDir * @param projectName */ private void createCircusIntegerClass() throws JCircusException { try { String pkg = getPackage(_projectName, Constants.PKG_TYPING, _compl); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_CIRCINT_PKG, pkg); /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_TYPING + "\\" + Constants.CLS_CIRCNUM + Constants.JAVA_EXT;*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_TYPING + "/" + Constants.CLS_CIRCNUM + Constants.JAVA_EXT; Util.createFileFromTemplate(Constants.TMP_CIRCINT, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create CircusInteger class.", t); } } /** * Creates classes for all the free types. * */ private void createClassesForFreeTypes() throws JCircusException { for (int i = 0; i < this._environment.freeTypesEnvironmentSize(); i++) { Freetype freetype = _environment.freeTypesEnvironmentGet(i); createClassForFreeType(freetype); } } /** * Creates class for a free type. * Pg. 167. * * @param freetype */ private void createClassForFreeType(Freetype freetype) throws JCircusException { String name = freetype./*getDeclName*/getZName().toString(); String constants = ""; String toStringCode = " String result = null; switch(super.getValue()) {"; String constructorCode = ""; int index = 0; //Abaixo foi mudado!!! ZBranchList/*ListTerm*/ branches = (ZBranchList) (freetype.getBranchList()); //ListTerm branches = freetype.getBranch(); // Constants for (int i = 0; i < branches.size(); i++) { Branch branch = (Branch) branches.get(i); String nameFreeTypeElement = branch.getZName()/*getDeclName()*/.toString(); constants = constants + " public static final int " + nameFreeTypeElement + " = " + index + ";"; toStringCode += " case " + nameFreeTypeElement + ": result = \"" + nameFreeTypeElement + "\"; break;"; constructorCode += " if (st.equals(\"" + nameFreeTypeElement + "\")) \tthis.setValue(" + index + ");"; index++; } toStringCode += " }"; toStringCode += " return result;"; constants = constants + " public static final int MIN_VALUE = 0;"; constants = constants + " public static final int MAX_VALUE = " + (branches.size() - 1) + ";"; // Formatting toStringCode = CodeFormatting.format(toStringCode); constructorCode = CodeFormatting.format(constructorCode); String pkg = getPackage(_projectName, Constants.PKG_TYPING, _compl); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_SUBTYPE_PROJ, _projectName); map.put(Constants.C_SUBTYPE_CLSNAME, name); map.put(Constants.C_SUBTYPE_CONST, constants); map.put(Constants.C_SUBTYPE_TOSTR, toStringCode); map.put(Constants.C_SUBTYPE_CONSTRUCTOR, constructorCode); map.put(Constants.C_SUBTYPE_PKG, pkg); try { /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_TYPING + "\\" + name + ".java";*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_TYPING + "/" + name + ".java"; Util.createFileFromTemplate(Constants.TMP_SUBTYPE, map, fileName); //System.out.println ("(((((((((((((((((((((((((((((((((((((((((((((((((("); } catch (Throwable t) { throw new JCircusException("Error while trying to create class for free type" + name, t); } } /** * Creates class for the axiomatic definitions and horizontal definitions. */ private void createAxDefHorizDefClass() throws JCircusException { String pkg = getPackage(_projectName, Constants.PKG_AXDEFS, _compl); String imp = getImports(_projectName); String body = ""; for (int i = 0; i < _axParaCodeList.size(); i++) { body = body + _axParaCodeList.get(i) + " "; } // Formatting body = CodeFormatting.format(body); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_AXDEFS_PKG, pkg); map.put(Constants.C_AXDEFS_IMP, imp); map.put(Constants.C_AXDEFS_BODY, body); try { /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_AXDEFS + "\\" + Constants.CLS_AXDEFS + Constants.JAVA_EXT;*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_AXDEFS + "/" + Constants.CLS_AXDEFS + Constants.JAVA_EXT; Util.createFileFromTemplate(Constants.TMP_AXDEFS, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create AxiomaticDefinitions class", t); } } /** * Creates class for a process definition. * Pg. 137. * * @param projectDir * @param projectName */ private void createProcessClass(String processName, String processBody) throws JCircusException { // Format String formattedProcessBody = CodeFormatting.format(processBody); String pkg = getPackage(_projectName, Constants.PKG_PROCESSES, _compl); String imp = getImports(_projectName); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_PROC_PROJ, _projectName); map.put(Constants.C_PROC_CLSBODY, formattedProcessBody); map.put(Constants.C_PROC_CLSNAME, processName); map.put(Constants.C_PROC_PKG, pkg); map.put(Constants.C_PROC_IMP, imp); try { /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_PROCESSES + "\\" + processName + ".java";*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_PROCESSES + "/" + processName + ".java"; Util.createFileFromTemplate(Constants.TMP_PROC, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create process class for " + processName, t); } } /** * Creates class Main for a process definition. * * @param projectDir * @param projectName * @param processDefinitionMain * @throws Exception */ private void createClassMain(ProcInfo procInfo) throws JCircusException { // Parameters for template String pkg = getPackage(_projectName, null, _compl); String imp = getImports(_projectName); String nameMain = "Main_" + procInfo.getProcessName(); String declarations = attributeDeclMainCode(procInfo.getProcessPara()); String processCall = processCallCode(procInfo); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_MAIN_PKG, pkg); map.put(Constants.C_MAIN_IMP, imp); map.put(Constants.C_MAIN_PROJ, _projectName); map.put(Constants.C_MAIN_NMMAIN, nameMain); map.put(Constants.C_MAIN_DECLS, declarations); map.put(Constants.C_MAIN_PROCCALL, processCall); try { //String fileName = _projectDir + "\\" + _projectName + "\\" + nameMain + ".java"; String fileName = _projectDir + "/" + _projectName + "/" + nameMain + ".java"; Util.createFileFromTemplate(Constants.TMP_MAIN, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create main class for " + procInfo.getProcessName()); } } /** * Code for declaration of channels in the main class. */ // DUPLICATED CODE? TV.attributeDeclCode() private String attributeDeclMainCode (ProcessPara processParaMain) { String code = ""; PId2PNameEnv p2pe = new PId2PNameEnv (); CircusProcess circusProcess = processParaMain.getCircusProcess(); String processName = processParaMain.getZName().toString(); ChanInfoEnv multiSyncEnv = Util.getChannelMSEnvAnn(processParaMain); //By Angela Freitas String key = this.procProcessParaEnv.getKey(processParaMain); ProcChanEnv procchanenv = this.getProcName2ProcChanEnv().get(key); ChanInfoEnv cie = procchanenv.getChanInfoEnv(); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); // Gets process id Integer procId = Util.getIdCircusProcessAnn(circusProcess).getId(); Iterator it = multiSyncEnv.iteratorKeys(); // For each channel while(it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv chanMSEnv = multiSyncEnv.get(channelName); //chanMSEnv.setChannelSet(multiSyncEnv.getChannelSet()); if (!chanUseEnvHid.containsKey(channelName) && ChannelUtil.getVisibleChannelsFromMainAction(circusProcess, processName, _spec).contains(channelName) ) { // Code for the declaration of the channel - only channels that // are not hidden can appear in the gui code = code + channelCode(channelName, procId, processName, chanMSEnv/*, p2pe*/); System.out.print (""); } } return code; } /** * Code for declaration of one channel in the main class. Example of code: * * final Any2OneChannel[] from_a = Any2OneChannel.create(3); // number of processes that take part in the MS - MS only * * final Any2OneChannel to_a = new Any2OneChannel(); * * Hashtable ht = new Hashtable(); * ht.put("GC_A", new Integer(1)); * ht.put("GC_B", new Integer(0)); * ht.put("GC_C", new Integer(2)); * final ChanInfo chanInfo = new ChanInfo(ht); * * final GeneralChannel a = new GeneralChannel( * to_a, * from_a, // MS only * chanInfo, * "GC_P"); * * OBS: Variables are no longer 'final', I do not remeber why they were like this * before. * */ private String channelCode(String channelName, Integer procId, String procName, ProcChanUseEnv chanMSEnv) { String code = ""; String toChannel = "to_" + channelName; String fromChannel = "from_" + channelName; String chanInfo = "chanInfo_" + channelName; /** * The variables in the * */ if (chanMSEnv.isMultiSync2(this.pcme.get(procName))) { if (!useBarriers) { code = code + "org.jcsp.lang.Any2OneChannel [] " + fromChannel + " = org.jcsp.lang.Channel.any2oneArray (" + chanMSEnv.getCardinality() + "); "; //Sam's, JCSP novo } } // to_channel declaration //code = code + "Any2OneChannel " + toChannel + " = new Any2OneChannel(); "; //Angela's, JCSP antigo if (!useBarriers) { code = code + "org.jcsp.lang.Any2OneChannel " + toChannel + " = org.jcsp.lang.Channel.any2one (); "; //Sam's, JCSP novo } List <Integer> ids = Util.resolveUndefinedChannels (chanMSEnv, true); //By Angela Freitas code = code + " " + Constants.CLS_CHINFO + " " + chanInfo + " = new " + Constants.CLS_CHINFO + " (); "; int startValue = 1; for (int i = 0; i < ids.size(); i++) { //This loop was implemented by Samuel Barrocas, in 16/12/2010, 18:07hs Integer subProcId = (Integer) ids.get(i);/*.get(j);*/ String strfrts = this.frontEndUpdater.strfrontends (chanMSEnv.getProcName(subProcId), channelName, startValue); code = code + chanInfo + ".putArray (new Integer (" + subProcId + "), " + strfrts + "); "; if (!chanMSEnv.getProcName(subProcId).equals("$$GUI$$")) { FrontEndCounter fec = this.frontEndUpdater.getProcFrontEndCounterEnv().get(chanMSEnv.getProcName(subProcId)); if (fec != null) { if (fec.get(channelName) == null) { startValue = 0; } else startValue = fec.get(channelName) + 1; } else startValue = 0; } } // general channel if (chanMSEnv.isMultiSync2(this.pcme.get(procName))) { // multisynchronization //code = code + "/*" + channelName + " é um canal multisincronizado!*/ "; int dimChannel; HiddenFromGUIInfo infoprocessname = this.prochid.get(procName); //if (infoprocessname.getCoadjChannels().contains(channelName)) { //dimChannel = this.updatedChanDimEnv.get(infoprocessname.get(channelName)); //} //else { dimChannel = this.updatedChanDimEnv.get(channelName); //} code = code + " GeneralChannel " + (brackets (dimChannel)) + " " + channelName + " = GCArray.create" + ((dimChannel < 0)? 0 : dimChannel) + "Array ("; if (!useBarriers) { code = code + toChannel + ","; code = code + fromChannel + ","; } code = code + chanInfo + ","; code = code + "new Integer(" + procId + "), " + "new int [] {" + TypeUtil.getTypeSizes (channelName, this.cte) + "}"/*(this._envLoadingVisitor.getMaxAbsValueComm() + 1)*/ + "); "; } else { // not multisynchronization //code = code + "/*" + channelName + " NÃO é um canal multisincronizado! */ "; int dimChannel; HiddenFromGUIInfo infoprocessname = this.prochid.get(procName); //if (infoprocessname.getCoadjChannels().contains(channelName)) { //dimChannel = this.updatedChanDimEnv.get(infoprocessname.get(channelName)); //} //else { dimChannel = this.updatedChanDimEnv.get(channelName); //} code = code + "GeneralChannel " + (brackets (dimChannel)) + " " + channelName + " = /*1*/" + "GCArray.create" + ((dimChannel < 0)? 0 : dimChannel) + "Array ("; if (!useBarriers) { code = code + toChannel + ","; } code = code + chanInfo + "," + "new Integer(" + procId + "), " + "new int [] {" + TypeUtil.getTypeSizes (channelName, this.cte) + "}" /*(this._envLoadingVisitor.getMaxAbsValueComm() + 1)*/ + "); "; } return code; } /** * Code for call to the main process. * */ private String processCallCode(ProcInfo procInfo) throws JCircusException { String code = ""; String processName = procInfo.getProcessName(); CircusProcess circusProcess = procInfo.getProcessPara().getCircusProcess(); ChanInfoEnv chanInfoEnv = Util.getChannelMSEnvAnn(procInfo.getProcessPara()); Integer procId = Util.getIdCircusProcessAnn(circusProcess).getId(); ProcessPara processPara = procInfo.getProcessPara(); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processPara); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); String params = paramsCode(procInfo); String processNameGui = getNameGui(processName); List<String> listProcessesCode = new ArrayList(); /** * Builds the parameters for the GUI, that is, the code for the * passage of channels as parameters. */ // c is the number of channels that take part in the gui int c = 0; String paramsGui = ""; String comma = ", "; //Iterator it = chanInfoEnv.iteratorKeys(); Iterator it = chanInfoEnv.iteratorKeysFromMainAction(processPara, _spec); //10/06/2013 String params4Par = ""; //Variável criada por Samuel Barrocas String p_name = "p_", p_gui_name = "p_gui_"; //Variáveis criadas por Samuel Barrocas String list_of_gpse_p_channels = ""; //By Samuel Barrocas String list_of_gpse_gui_channels = ""; //By Samuel Barrocas int counter_gpse_channels = 1; //By Samuel Barrocas while (it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv chanMSEnv = chanInfoEnv.get(channelName); if (!chanMSEnv.isSync() && !chanUseEnvHid.containsKey(channelName)) { /** * Independent channels - they will synchronize only with the gui. * They cannot be hidden otherwise the gui cannot see them. */ if (isTranslatedAsSimpleSynchronised (channelName, this.prochid.get(processName), cmain)) { paramsGui = paramsGui + comma + "/*V*/" + channelName + "/*new " + Constants.CLS_GENCHAN + "(" + channelName + //Angela's ", new Integer(-1))*/"; // global id of gui is -1 //Angela's } else { paramsGui = paramsGui + comma + "/*V*/ GPSE.getProcessSyncEnds (new Integer (-1), " + channelName + ")" + "/*new " + Constants.CLS_GENCHAN + "(" + channelName + //Angela's ", new Integer(-1))*/"; // global id of gui is -1 //Angela's } c++; } /*Abaixo código escrito por Samuel Barrocas (Sam's)*/ if (useBarriers) { p_name = p_name + channelName + "_"; p_gui_name = p_gui_name + channelName + "_"; //if (!chanMSEnv.isSync()) { if (!this._envLoadingVisitor.getEnvLoadingParProcessEnv().get(processName)) { if (!isTranslatedAsSimpleSynchronised (channelName, this.prochid.get(processName), cmain)) { list_of_gpse_p_channels = list_of_gpse_p_channels + "/*I*/GPSE.getProcessSyncEnds (new Integer (" + procId + "), " + channelName + ", " + "new int [] {" + TypeUtil.getTypeSizes (channelName, this.cte) + "}" + ")"; list_of_gpse_gui_channels = list_of_gpse_gui_channels + "/*I*/GPSE.getProcessSyncEnds (new Integer (-1), " + channelName + ", new int [] {" + TypeUtil.getTypeSizes (channelName, this.cte) + "}" + ")"; } else { list_of_gpse_p_channels = list_of_gpse_p_channels + "/*II*/" + channelName; list_of_gpse_gui_channels = list_of_gpse_gui_channels + "/*II*/" + channelName; //list_of_gpse_gui_channels = list_of_gpse_gui_channels + "GPSE.getProcessSyncEnds (new Integer (-1), " + channelName + ")"; } } else { list_of_gpse_p_channels = list_of_gpse_p_channels + "/*III*/" + channelName; //list_of_gpse_gui_channels = list_of_gpse_gui_channels + channelName; list_of_gpse_gui_channels = list_of_gpse_gui_channels + "/*III*/GPSE.getProcessSyncEnds (new Integer (-1), " + channelName + ", new int [] {" + TypeUtil.getTypeSizes (channelName, this.cte) + "}" + ")"; } //} /*else { list_of_gpse_p_channels = list_of_gpse_p_channels + channelName; list_of_gpse_gui_channels = list_of_gpse_gui_channels + channelName; }*/ //if (counter_gpse_channels < chanInfoEnv.size()) { if (counter_gpse_channels < chanInfoEnv.sizeFromMainAction(processPara, _spec)) { if (!list_of_gpse_p_channels.equals("")) list_of_gpse_p_channels = list_of_gpse_p_channels + ", "; if (!list_of_gpse_gui_channels.equals("")) list_of_gpse_gui_channels = list_of_gpse_gui_channels + ", "; } counter_gpse_channels++; } /*Acima código escrito por Samuel Barrocas (Sam's)*/ } if (this.bench == true) { List <VarDecl> decls = procInfo.getParameters(); if (decls.size() > 0) { if (!list_of_gpse_p_channels.equals("")) list_of_gpse_p_channels += ", "; for (int i = 0; i < procInfo.getParameters().size(); i++) { String name = decls.get(i).getName().get(0).toString(); Expr type = procInfo.getTypeOfParameter(i); if (type instanceof RefExpr) { String typename = ((RefExpr) type).getZName().toString(); if (((RefExpr) type).getZName().toString().equals("ℕ")) { list_of_gpse_p_channels += "new " + "CircusInteger" + " (0)"; } else { list_of_gpse_p_channels += "new " + typename + " (0)"; } } else { list_of_gpse_p_channels += "new CircusInteger (0)"; } if (i < procInfo.getParameters().size() - 1) list_of_gpse_p_channels += ", "; } } } listProcessesCode.add (p_name); listProcessesCode.add (p_gui_name); if (useBarriers) { String commaOrNothing = (list_of_gpse_gui_channels.equals("")? "" : ", "); params4Par = params4Par + processName + " " + p_name + " = new " + processName + "(" + list_of_gpse_p_channels + "); "; params4Par = params4Par + "\t\tGui_" + processName + " " + p_gui_name + " = new Gui_" + processName + "(\"" + processName + "\"" + commaOrNothing + list_of_gpse_gui_channels + "); "; } // c is the number of channels that take part in the gui paramsGui = "\"" + processName + "\"" + paramsGui; String parCodeLeft; String parCodeRight; //Abaixo, código do protocolo de multi-sincronização (nada a ver com a solução com barreiras alternantes) if (chanInfoEnv.noMultiSync2(this.pcme.get(processName)) == 0) { /** * If there is no multi-synchronization, the main call is the * parallelism of the main process and GUI. */ parCodeLeft = cspProcessCallCode(processName, params); parCodeRight = cspProcessCallCode(processNameGui, paramsGui); System.out.println (); } else { /** * If there is multi-synchronization, the main call is the * parallelism of ProcessManagerMultiSync and ControllersManager. */ parCodeLeft = processManagerCallCode(processName, params, processNameGui, paramsGui); parCodeRight = controllersManagerCallCode(chanInfoEnv, processName); } /** * Creates the parallelism */ if (!useBarriers) { listProcessesCode.add(parCodeLeft); listProcessesCode.add(parCodeRight); } else { //Samuel Barrocas (Sam's) //listProcessesCode.add (channelName + "_" + processName); } code = code + params4Par; //Samuel Barrocas (Sam's) code = code + parallelCallRunCode(listProcessesCode, true); return code; } /** * Code for the params to the main process in class Main. * */ private String paramsCode(ProcInfo procInfo) { String code = ""; String processName = procInfo.getProcessName(); CircusProcess circusProcess = procInfo.getProcessPara().getCircusProcess(); String procParamCode = ""; // parameters of the process if (circusProcess instanceof ParamProcess) { procParamCode = paramList(procInfo.getCodeForActuals()); } // visible channels passed as parameters String chanParamCode = paramPassageCode(procInfo.getProcessPara()); // Channels come first if (!chanParamCode.equals("") && !procParamCode.equals("")) { code = chanParamCode + "/*---*/, " + procParamCode; } else { code = chanParamCode + "/*---*/" + procParamCode; } return code; } /** * Return code for the expressions which are parameters of the process */ private String paramList(List<String> codeForActuals) { String code = ""; String comma = ""; for (int i = 0; i < codeForActuals.size(); i++) { code = code + comma + codeForActuals.get(i); comma = ", "; } return code; } /** * */ private String paramPassageCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName()/*getDeclName()*/.toString(); CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); Integer id = Util.getIdCircusProcessAnn(circusProcess).getId(); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); String comma = ""; Iterator it = channelMSEnv.iteratorKeys(); // For each channel while(it.hasNext()) { String channelName = (String) it.next(); if (!chanUseEnvHid.containsKey(channelName)) { // Hidden channels are not seen in main ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); code = code + comma + channelName; comma = ", /*--_-_-*/"; } } return code; } /** * */ private String cspProcessCallCode(String name, String paramsCode) { return "new " + name + "(" + paramsCode + ")"; } /** * Returns the code for the call to the constructor of class ProcessManagerMultiSync.java. * * Typically, this constructor will receive a process which is the parallelism of the main * class and the gui. * */ private String processManagerCallCode (String processName, String params, String processNameGui, String paramsGui) throws JCircusException { String code; List<String> listProcessesCode = new ArrayList<String>(); listProcessesCode.add(cspProcessCallCode(processName, params)); listProcessesCode.add(cspProcessCallCode(processNameGui, paramsGui)); String parallelismCode = parallelCallRunCode(listProcessesCode, false); HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put(Constants.C_PROCMNGR_PROC, parallelismCode); code = Util.getCodeFromTemplate(Constants.TMP_PROCMNGR, hashMap); return code; } /** * Returns the code for the call to the constructor of class ControllersManager.java. * */ private String controllersManagerCallCode(ChanInfoEnv chanInfoEnv, String procName) throws JCircusException { String code; String call; if (chanInfoEnv.noMultiSync2(this.pcme.get(procName)) == 1) { /** * If there is only one controller, this is the call to the * method run of the controller. */ Iterator<String> it = chanInfoEnv.iteratorKeys(); String channelName = ""; while(it.hasNext()) { channelName = it.next(); ProcChanUseEnv syncEnv = chanInfoEnv.get(channelName); if (syncEnv.isMultiSync2(this.pcme.get(procName))) break; } call = "new " + Constants.CLS_MSCTRL + "(Channel.getOutputArray (from_" + channelName + "), to_" + channelName + ".in())"; } else { /** * If there is more than one, this is the call to the method * run of the parallelism of the controllers. * */ List<String> listProcessCode = new ArrayList<String>(); /** * iterates over the environments and when it finds one * channel that is multisynchronized, * adds its name to the array */ Iterator<String> it = chanInfoEnv.iteratorKeys(); while(it.hasNext()) { String channelName = it.next(); ProcChanUseEnv syncEnv = chanInfoEnv.get(channelName); if (syncEnv.isMultiSync2(this.pcme.get(procName))) { String processCode = ""; /** * Multi synchronization. */ processCode = "new " + Constants.CLS_MSCTRL + " (from_" + channelName + ", to_" + channelName + ")"; listProcessCode.add(processCode); } } call = parallelCallRunCode(listProcessCode, false); } HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put(Constants.C_CTRLMNGR_CALL, call); code = Util.getCodeFromTemplate(Constants.TMP_CTRLMNGR, hashMap); return code; } /** * Returns the source code for the call for the constructor of a parallelism. * * Receives the code for each CSPProcess that takes part in the parallelism. * * @param boolean run If it is true, appends the call method run() at the end. */ private String parallelCallRunCode(List<String> processes, boolean run) throws JCircusException { String code; String listProcessesCode = ""; String comma = ""; for (int i=0; i < processes.size(); i++) { listProcessesCode += comma + processes.get(i); comma = ", "; } HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put(Constants.C_PARCALL_LISTPROC, listProcessesCode); code = Util.getCodeFromTemplate(Constants.TMP_PARCALL, hashMap); if (run) { code = code + ".run();"; } return code; } /** * Create class GUI for a process definition. */ private void createGUI(ProcInfo procInfo) throws JCircusException { String nameMain = procInfo.getProcessName(); String pkg = getPackage(_projectName, Constants.PKG_GUI, _compl); String imp = getImports(_projectName); String nameGui = getNameGui(nameMain); String chanDecl = chanDeclGuiCode(procInfo.getProcessPara()); String chanAssig = chanAssignGuiCode(procInfo.getProcessPara()); String chanParam = chanParamGuiCode(procInfo.getProcessPara()); String chanInit = chanInitGuiCode(procInfo.getProcessPara()); String chanActPerf = chanActPerfGuiCode(procInfo.getProcessPara()); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_GUI_PKG, pkg); map.put(Constants.C_GUI_IMP, imp); map.put(Constants.C_GUI_CLSNAME, nameGui); map.put(Constants.C_GUI_CHANDECL, chanDecl); map.put(Constants.C_GUI_CHANASSIG, chanAssig); map.put(Constants.C_GUI_CHANPARAM, chanParam); map.put(Constants.C_GUI_CHANINIT, chanInit); map.put(Constants.C_GUI_CHANACTPERF, chanActPerf); try { /*String fileName = _projectDir + "\\" + _projectName + "\\" + Constants.PKG_GUI + "\\" + nameGui + ".java";*/ String fileName = _projectDir + "/" + _projectName + "/" + Constants.PKG_GUI + "/" + nameGui + ".java"; Util.createFileFromTemplate(Constants.TMP_GUI, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create GUI for " + procInfo.getProcessName(), t); } } /** * Code for declaration of GUI components of a channel. */ public String cdgcode (String channelName, String procName/*, String code*/) { String code = ""; code = code + " private GeneralChannel /*GC1*/" + CCUtil.bracketizeds(this.updatedChanDimEnv.get(channelName), "") + " " + channelName + ";"; code = code + " private javax.swing.JButton btn_" + channelName + ";"; code = code + " private javax.swing.JLabel lbl_" + channelName + ";"; code = code + " private javax.swing.JPanel panel_" + channelName + " = new javax.swing.JPanel ();"; code = code + " private javax.swing.JComboBox " + "[]" + " combo_" + channelName + " = new javax.swing.JComboBox [" + (this._envLoadingVisitor.getChanDimEnv().get(channelName) < 0? 0 : this._envLoadingVisitor.getChanDimEnv().get(channelName)) + "]; //Changed by Samuel Barrocas"; code = code + " Vector <String []> boxcontent_" + channelName + " = new Vector <String []> (); " + " public JComboBox [] instComboBoxes_" + channelName + " (int x) { //Code Developed by Samuel Barrocas (Sam's) " + " javax.swing.JComboBox [] cb = new javax.swing.JComboBox [x]; "; Vector <Vector <BigInteger>> vec = cte.get(channelName); for (int i = 0; i < vec.size(); i++) { code = code + " boxcontent_" + channelName + ".addElement (" + Channel2TypeEnvironment.stringCode (channelName, i, cte) + "); "; } code = code + " " + " for (int i = 0; i < x; i++) { " + " cb [i] = new javax.swing.JComboBox (boxcontent_" + channelName + ".elementAt (i)); " + " } " + " return cb; " + " } "; code = code + " public int [] getValues_" + channelName + " (JComboBox [] jcb, Vector <String []> boxcontent_" + channelName +") { //Method developed by Samuel Barrocas (Sam's) " + " int [] values = new int [" + numberOfValuesComm (channelName, this.prochid.get(procName)) + "]; "; for (int i = 0; i < vec.size(); i++) { code = code + " values [" + i + "] = (new " + cte.getFreeType (channelName, i) + "(boxcontent_" + channelName + ".elementAt(" + i + ") [jcb [" + i + "].getSelectedIndex()])).getValue(); "; } code = code + " return values; " + " } "; return code; } private String chanDeclGuiCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName()/*getDeclName()*/.toString(); CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); //Set keys = channelMSEnv.keys(); Set keys = channelMSEnv.keysFromMainAction(processParaMain, _spec); Iterator it = keys.iterator(); while (it.hasNext()) { String channelName = (String) it.next(); if (this.prochid.get(processName).getCoadjChannels().contains(channelName)) { String mainChannelName = this.prochid.get(processName).get(channelName); if ((this.prochid.get(processName).getPutDecl(mainChannelName) == false || !fullparallelism)) { this.prochid.get(processName).putPutDecl(mainChannelName, true); code += cdgcode (mainChannelName, processName); } } ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); HiddenFromGUIInfo infoprocessname = this.prochid.get(processName); if ((this.prochid.get(processName).getPutDecl(channelName) == false || !fullparallelism)) { this.prochid.get(processName).putPutDecl(channelName, true); int chanDim; chanDim = this.updatedChanDimEnv.get(channelName); code = code + " private GeneralChannel /*GC2*/ " + CCUtil.bracketizeds(chanDim, "") + " " + channelName + ";"; code = code + " private javax.swing.JButton btn_" + channelName + ";"; code = code + " private javax.swing.JLabel lbl_" + channelName + ";"; code = code + " private javax.swing.JPanel panel_" + channelName + " = new javax.swing.JPanel ();"; code = code + " private javax.swing.JComboBox " + "[]" + " combo_" + channelName + " = new javax.swing.JComboBox [" + (this._envLoadingVisitor.getChanDimEnv().get(channelName) < 0? 0 : this._envLoadingVisitor.getChanDimEnv().get(channelName)) + "]; //Changed by Samuel Barrocas"; code = code + " Vector <String []> boxcontent_" + channelName + " = new Vector <String []> (); " + " public JComboBox [] instComboBoxes_" + channelName + " (int x) { //Code Developed by Samuel Barrocas (Sam's) " + " javax.swing.JComboBox [] cb = new javax.swing.JComboBox [x]; "; Vector <Vector <BigInteger>> vec = cte.get(channelName); for (int i = 0; i < vec.size(); i++) { code = code + " boxcontent_" + channelName + ".addElement (" + Channel2TypeEnvironment.stringCode (channelName, i, cte) + "); "; } code = code + " " + " for (int i = 0; i < x; i++) { " + " cb [i] = new javax.swing.JComboBox (boxcontent_" + channelName + ".elementAt (i)); " + " } " + " return cb; " + " } "; code = code + " public int [] getValues_" + channelName + " (JComboBox [] jcb, Vector <String []> boxcontent_" + channelName +") { //Method developed by Samuel Barrocas (Sam's) " + " int [] values = new int [" + numberOfValuesComm (channelName, infoprocessname) + "]; "; for (int i = 0; i < vec.size(); i++) { code = code + " values [" + i + "] = (new " + cte.getFreeType (channelName, i) + "(boxcontent_" + channelName + ".elementAt(" + i + ") [jcb [" + i + "].getSelectedIndex()])).getValue(); "; } code = code + " return values; " + " } "; } } return code; } public static boolean isTranslatedAsSimpleSynchronised ( String chanName, //HiddenFromGUIInfo hid, ChanTransMSEnv ctmse, ChanComplexCommEnv ccce, ChanDotFieldEnv cdfe, ChanExtChoiceEnv cece, ChanDimEnv cde, boolean cmain ) { if (ctmse.get(chanName) || ccce.get(chanName) || cdfe.get(chanName) || cece.get(chanName) || (cde.get(chanName) <= 0) || ctmse.get(chanName) || cmain ) { return false; } return true; } public boolean isTranslatedAsSimpleSynchronised (String chanName, HiddenFromGUIInfo hid, boolean cmain) { return isTranslatedAsSimpleSynchronised ( chanName, //hid, this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); } public int numberOfValuesComm (String chanName, HiddenFromGUIInfo hid) { if (chanName.equals ("returned")) { System.out.print(""); } if (hid.reverseGet(chanName).size() > 1) { Vector <String> reverse = hid.reverseGet(chanName); String coadjchan = reverse.get(1); int dim = this.updatedChanDimEnv.get(coadjchan); return dim; } return this.updatedChanDimEnv.get(chanName); //return this._envLoadingVisitor.getChanDimEnv().get(chanName); } /** * Code for the body of a constructor in the GUI component. */ private String chanAssignGuiCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName().toString(); CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); //Iterator it = channelMSEnv.iteratorKeys(); Iterator it = channelMSEnv.iteratorKeysFromMainAction(processParaMain, _spec); //10/06/2013 while (it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); if (!chanUseEnvHid.containsKey(channelName)) { if (this.prochid.get(processName).getCoadjChannels().contains(channelName)) { code = code + "this." + channelName + " = " + channelName + "; \t\t"; } else { Vector <String> coadjChannels = this.prochid.get(processName).reverseGet(channelName); if (coadjChannels == null) { System.out.print(""); } else { for (int i = 0; i < coadjChannels.size(); i++) { String coadj = coadjChannels.get(i); if (!this.prochid.get(processName).getMainChannels().contains(coadj)) { String main = this.prochid.get(processName).get(coadj); if (this.prochid.get(processName).reverseGet(main).size() <= 2 && main != null) { code = code + "this." + main + " = " + main + ";"; } else { code = code + "this." + coadj + " = " + coadj + ";"; } } else { code = code + "this." + coadj + " = " + coadj + ";"; } } } } } } return code; } /** * Code for parameters in the constructor in a GUI component. */ private String chanParamGuiCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName().toString(); CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); //Iterator it = channelMSEnv.iteratorKeys(); Iterator it = channelMSEnv.iteratorKeysFromMainAction(processParaMain, _spec); //10/06/2013 // for each channel while (it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); if (/*!syncEnv.isSync() &&*/ !chanUseEnvHid.containsKey(channelName)) { int chanDim; HiddenFromGUIInfo infoprocessname = this.prochid.get(processName); //if (infoprocessname.getCoadjChannels().contains(channelName)) { //String mainChannelName = infoprocessname.get(channelName); //chanDim = this.updatedChanDimEnv.get(mainChannelName); //} //else { chanDim = this.updatedChanDimEnv.get(channelName); //} int dim = chanDim;/*this.updatedChanDimEnv.get(channelName)*/ code = code + ", " + Constants.CLS_GENCHAN + " " + CCUtil.bracketizeds(dim, "") + "/*88*/ " + channelName; } } return code; } /** * */ private String chanInitGuiCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName()/*getDeclName()*/.toString(); CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); //Iterator it = channelMSEnv.iteratorKeys(); Iterator it = channelMSEnv.iteratorKeysFromMainAction(processParaMain, _spec); //10/06/2013 // for each channel while (it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); if (/*!syncEnv.isSync() &&*/ !chanUseEnvHid.containsKey(channelName)) { //TODO descomentar isSync()? ChanUse chanUse = syncEnv.getChanUseGuiNotSyncChannel(); CircusType circusType = procChanEnv.getNameTypeEnv().getCircusType(channelName); /** * Error when I try to use velocity: * org.apache.velocity.exception.ParseErrorException: Encountered "java" at line 5, column 37. * Was expecting one of: * "," ... * ")" ... * at org.apache.velocity.Template.process(Template.java:141) * */ if (circusType != null) { if (circusType.isSyncType()) { if (!this.prochid.get(processName).getCoadjChannels().contains(channelName)) //"if" by Samuel Barrocas code = code + "/*_A_*/" + initGuiChanSync(processName, channelName); else { code = code + "/*_B_*/" + initGuiChanSync(processName, this.prochid.get(processName).get(channelName)); } } else { String commTypeName = circusType.getJavaCircusTypeName(); if (chanUse == null) { chanUse = ChanUse.Undefined; } if (!this.prochid.get(processName).getCoadjChannels().contains(channelName)) {//"if" by Samuel Barrocas if (chanUse == null) { chanUse = ChanUse.Undefined; } code = code + "/*_C_*/" + initGuiChanComm(processName, channelName, chanUse.toStringGUI(), commTypeName); System.out.println (); } else { code = code + "/*_D_*/" + initGuiChanComm(processName, this.prochid.get(processName).get(channelName), chanUse.toStringGUI(), commTypeName); //code = code + initGuiChanSync(this.hid.get(channelName)); } } } } } return code; } /** * Code for initialisation of the GUI components for a synchronisation channel. */ private String initGuiChanSync(String processName, String chanName) { String code = ""; /*if (this.prochid.get(processName).getCoadjChannels().contains(chanName)) chanName = this.prochid.get(processName).get (chanName);*/ HiddenFromGUIInfo hie = this.prochid.get(processName); if ((this.prochid.get(processName).getPutAtt(chanName) == false || !fullparallelism)) { this.prochid.get(processName).putPutAtt (chanName, true); code += " \t\tbtn_" + chanName + " = new javax.swing.JButton(\"" + chanName + "\");"; code += " \t\tpanel_" + chanName + " = new javax.swing.JPanel();"; code += " \t\tbtn_" + chanName + ".addActionListener(new java.awt.event.ActionListener() {"; code += " \t\t\tpublic void actionPerformed(java.awt.event.ActionEvent evt) {"; code += " \t\t\t\tbtn_" + chanName + "_ActionPerformed(evt);"; code += " \t\t\t}"; code += " \t\t});"; //code += " \t\tthis.getContentPane().add(btn_" + chanName + ");"; code += " \t\tpanel_" + chanName + ".add(btn_" + chanName + ");"; /*totalcontainer.add(panel_c); totalcontainer.add(new javax.swing.JLabel(""));*/ /*code += " \t\tthis.getContentPane().add(panel_" + chanName + ");"; code += " \t\tthis.getContentPane().add(new javax.swing.JLabel(\"\"));";*/ code += " \t\ttotalcontainer.add(panel_" + chanName + ");"; code += " \t\ttotalcontainer.add(new javax.swing.JLabel(\"\"));"; code += " "; } return code; } /** * Code for initialisation of the GUI components for a communication channel. */ private String initGuiChanComm(String processName, String chanName, String chanType, String commType) { String code = ""; /*if (this.prochid.get(processName).getCoadjChannels().contains(chanName)) chanName = this.prochid.get(processName).get (chanName);*/ if (this.prochid.get(processName).getPutAtt(chanName) == false) { this.prochid.get(processName).putPutAtt(chanName, true); code += " \t\tbtn_" + chanName + " = new javax.swing.JButton(\"" + chanName + "\");"; code += " \t\tcombo_" + chanName + " = instComboBoxes_" + chanName + " (" + numberOfValuesComm(chanName, this.prochid.get(processName)) /*this._envLoadingVisitor.getChanDimEnv().get(chanName)*/ + "); //Modificado por Samuel Barrocas (Sam's)"; //Sam's code += " \t\tlbl_" + chanName + " = new javax.swing.JLabel(\"/*__*/" + chanType + ": " + commType + "\", SwingConstants.LEFT);"; code += " \t\tthis.btn_" + chanName + ".addActionListener(new java.awt.event.ActionListener() {"; code += " \t\t\tpublic void actionPerformed(java.awt.event.ActionEvent evt) {"; code += " \t\t\t\tbtn_" + chanName + "_ActionPerformed(evt);"; code += " \t\t\t}"; code += " \t\t});"; code += " "; code += " \t\tthis.panel_" + chanName + ".add(btn_" + chanName + ");"; code += " \t\tthis.panel_" + chanName + ".setLayout (new FlowLayout());"; code += " \t\tfor (int i = 0; i < " + numberOfValuesComm (chanName, this.prochid.get(processName))/*this._envLoadingVisitor.getChanDimEnv().get(chanName)*/ + "; i++) { //Criado por Samuel Barrocas (Sam's) " + "\t\t\tthis.panel_" + chanName + ".add(combo_" + chanName + " [i]); " + "\t\t} "; //code += "\t\tthis.getContentPane().add(panel_" + chanName + ");"; code += "\t\ttotalcontainer.add(panel_" + chanName + ");"; //code += " \t\tthis.getContentPane().add(lbl_" + chanName + ");"; code += " "; } return code; } /** * */ String currentProcess = ""; //Sam's private String chanActPerfGuiCode(ProcessPara processParaMain) { String code = ""; String processName = processParaMain.getZName()/*getDeclName()*/.toString(); currentProcess = processName; //Sam's CircusProcess circusProcess = processParaMain.getCircusProcess(); ChanInfoEnv channelMSEnv = Util.getChannelMSEnvAnn(processParaMain); ProcChanEnv procChanEnv = Util.getProcChanEnvAnn(processParaMain); ChanUseEnv chanUseEnvHid = procChanEnv.getChanUseEnvHid(); //Iterator it = channelMSEnv.iteratorKeys(); Iterator it = channelMSEnv.iteratorKeysFromMainAction(processParaMain, _spec); //10/06/2013 // for each channel while (it.hasNext()) { String channelName = (String) it.next(); ProcChanUseEnv syncEnv = channelMSEnv.get(channelName); if (!syncEnv.isSync() && !chanUseEnvHid.containsKey(channelName)) { //TODO descomentar isSync()? /*if (channelName.equals ("out")) { syncEnv._out_ = true; }*/ ChanUse chanUse = syncEnv.getChanUseGuiNotSyncChannel(); CircusType circusType = procChanEnv.getNameTypeEnv().getCircusType(channelName); // The channel does not take part in a parallelism, so it will // be in the graphical interface if (chanUse.equals(ChanUse.Input)) { if (!this.prochid.get(processName).getCoadjChannels().contains(channelName)) { //By Samuel Barrocas if (!this.prochid.get(processName).getPutActionPerformed (channelName)) { code = code + chanActPerfWrite (processName, channelName, circusType); this.prochid.get(processName).putPutActionPerformed (channelName, true); } } else if (!fullparallelism) { code = code + chanActPerfWrite (processName, channelName, circusType); } else { if (!this.prochid.get(processName).getPutActionPerformed(this.prochid.get(processName).get(channelName))) { code = code + chanActPerfWrite (processName, this.prochid.get(processName).get(channelName), circusType); this.prochid.get(processName).putPutActionPerformed (this.prochid.get(processName).get(channelName), true); } } } else { if (!this.prochid.get(processName).getCoadjChannels().contains (channelName)) { //By Samuel Barrocas if (!this.prochid.get(processName).getPutActionPerformed (channelName)) { code = code + chanActPerfRead (processName, channelName, circusType); this.prochid.get(processName).putPutActionPerformed (channelName, true); } } else if (!fullparallelism) { code = code + chanActPerfRead (processName, channelName, circusType); } else { if (!this.prochid.get(processName).getPutActionPerformed (this.prochid.get(processName).get(channelName))) { code = code + chanActPerfRead (processName, this.prochid.get(processName).get(channelName), circusType); this.prochid.get(processName).putPutActionPerformed (this.prochid.get(processName).get(channelName), true); } } } } else { if (!this.prochid.get(processName).getCoadjChannels().contains(channelName)) { //By Samuel Barrocas if (!this.prochid.get(processName).getPutActionPerformed (channelName)) { code = code + chanActPerfCompl (processName, channelName); this.prochid.get(processName).putPutActionPerformed (channelName, true); } } else if (!fullparallelism) { code = code + chanActPerfCompl (processName, channelName); } else { if (!this.prochid.get(processName).getPutActionPerformed(this.prochid.get(processName).get(channelName))) { code = code + chanActPerfCompl (processName, this.prochid.get(processName).get(channelName)); this.prochid.get(processName).putPutActionPerformed (this.prochid.get(processName).get(channelName), true); } } } /*else { //By Samuel Barrocas, 09/08(Agosto)/2011 code += " \tprivate void btn_" + channelName + "_ActionPerformed(java.awt.event.ActionEvent evt) {"; if (!useBarriers) code += " \t\t" + channelName + ".read();"; else { if (!this.prochid.get(processName).getMainChannels().contains(channelName)) //"if" by Samuel Barrocas code += " \t\t" + channelName + ".timerSync(area);"; else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(channelName); code += HiddenFromGUIInfo.hiddenSyncCode(hiddenChannelsFromGui, "","timerSync (area)"); } } code += "\t }"; }*/ } return code; } /** * */ private String showEventInGUICode (String processName, String chanName) { //Samuel Barrocas' Vector <Vector <BigInteger>> vec = cte.get(chanName); String code = ""; code = code + " String valuesstr = " + "\"" + chanName + "\"; "; //code = code + " for (int i = 0; i < values.length; i++) { "; //code = code + " valuesstr = valuesstr + \".\" + "; for (int i = 0; i < vec.size(); i++) { code = code + " valuesstr = valuesstr + \".\" + " + "(new " + cte.getFreeType (chanName, i) + "(boxcontent_" + chanName + ".elementAt(" + i + ") [this.combo_" + chanName + " [" + i + "].getSelectedIndex()])).toString(); "; } return code + " "; //valuesstr = valuesstr + "." + (new VALUE(boxcontent_result.elementAt(i) [this.combo_result [i].getSelectedIndex()])).toString(); //"(new " + cte.getFreeType (chanName, i) + "(boxcontent_" + chanName + ".elementAt(" + i + ") [jcb [" + i + "].getSelectedIndex()])).getValue(); "; /*for (int i = 0; i < vec.size(); i++) { code = code + " values [" + i + "] = "(new " + cte.getFreeType (channelName, i) + "(boxcontent_" + channelName + ".elementAt(" + i + ") [jcb [" + i + "].getSelectedIndex()])).getValue(); "; }*/ } private String chanActPerfCompl (String processName, String chanName) { String code = ""; code += " \tprivate void btn_" + chanName + "_ActionPerformed(java.awt.event.ActionEvent evt) {"; code += " \t\tfinal int [] values = getValues_" + chanName + " (" + "this.combo_" + chanName + ", boxcontent_" + chanName + "); "; code += showEventInGUICode (processName, chanName); if (isTranslatedAsSimpleSynchronised (chanName, this.prochid.get(processName), cmain)) { if (this.parallelismUpdater.parallelismBeingUsed.get(processName)) { if (!(this.prochid.get(processName).getMainChannels().contains(chanName))) code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName)) + "./*1*/guiTimerSimpleWrite (values " + guibracketized(this.updatedChanDimEnv.get(chanName)) + ", area, valuesstr);"; else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*2*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); //HiddenFromGUIInfo.hiddenSyncCode( // hiddenChannelsFromGui, // bracketizedsValues (this.updatedChanDimEnv.get(chanName)), // "/*2*/guiTimerSimpleWrite (values " + // guibracketized(this._envLoadingVisitor.getChanDimEnv().get(chanName)) + // ", area)", // this.prochid.get(processName)); } } else { code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName)) + "/*3*/.guiTimerSimpleWrite (values " + guibracketized (this.updatedChanDimEnv.get(chanName)) + ", area, valuesstr);"; } } else { if (this._envLoadingVisitor.getChanComplexCommEnv().get(chanName)) { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) {//"if" by Samuel Barrocas if (this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + ccBracketizedsValues ( this.updatedChanDimEnv.get(this.prochid.get(processName).get(chanName)), chanName ) + ".timerSync(area, new int [] {0}, valuesstr);/*1*/"; } else { code += " \t\t" + chanName + ccBracketizedsValues ( this.updatedChanDimEnv.get(chanName), chanName ) + ".timerSync(area, new int [] {0}, valuesstr);/*1.5*/"; } } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*2.01*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); } } else { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) {//"if" by Samuel Barrocas if (this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + bracketizedsValues ( this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName/*this.prochid.get(processName).get(chanName)*/) ) + ".timerSync(area, new int [] {0}, valuesstr);/*3.1*/"; } else { code += " \t\t" + chanName + bracketizedsValues ( this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName) ) + ".timerSync(area, new int [] {0}, valuesstr);/*3.2*/"; } } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*4*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); } } } code += " \t}"; return code; } private String chanActPerfWrite(String processName, String chanName, CircusType circusType) { //JOptionPane.showMessageDialog (null, "PerfWrite"); String code = ""; code += " \tprivate void btn_" + chanName + "_ActionPerformed(java.awt.event.ActionEvent evt) {"; if (circusType != null) { if (circusType.isSyncType()) { if (!useBarriers) code += " \t\t" + chanName + ".write(null);"; else { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) {//"if" by Samuel Barrocas if (!this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " "; code += showEventInGUICode (processName, chanName); code += " \t\t" + chanName + ".timerSync (area, new int [] {0}, valuesstr);/*.sync()*/; /*Sync 10.2*/"; } else { code += " "; code += showEventInGUICode (processName, chanName); code += " \t\t" + chanName/*this.prochid.get(processName).get(chanName)*/ + ".timerSync (area, new int [] {0}, valuesstr);/*.sync()*/; /*Sync 10.3*/"; } } else { code += " "; code += showEventInGUICode (processName, chanName); Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*9*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); } } } else { String chanCommType = circusType.getJavaCircusTypeName(); if (!useBarriers) { code += " \t\tString st = this.txt_" + chanName + ".getText(); "; code += " \t\t" + chanCommType + " o = new " + chanCommType + " (st);"; code += " \t\t" + chanName + ".write(o);"; } else { code += " \t\tfinal int [] values = getValues_" + chanName + " (" + "this.combo_" + chanName + ", boxcontent_" + chanName + "); "; code += showEventInGUICode (processName, chanName); if (isTranslatedAsSimpleSynchronised (chanName, this.prochid.get(processName), cmain) ) { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) { if (!this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName) ) + "/*4*/.guiTimerSimpleWrite (values " + guibracketized(this.updatedChanDimEnv.get(chanName)) + ", area, valuesstr);"; } else { code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName/*this.prochid.get(processName).get(chanName)*/)) + "/*5*/.guiTimerSimpleWrite (values " + guibracketized (this.updatedChanDimEnv.get(chanName/*this.prochid.get(processName).get(chanName)*/)) + ", area, valuesstr);"; } } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*6*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); //code += // HiddenFromGUIInfo.hiddenSyncCode ( // hiddenChannelsFromGui, // this._envLoadingVisitor.getChanComplexCommEnv(), // this.updatedChanDimEnv/*bracketizedsValues (this.updatedChanDimEnv.get(chanName))*/, // c2sste, // //"/*6*/guiTimerSimpleWrite (values " + guibracketized (this.updatedChanDimEnv.get(chanName)) + ", area)", // this.prochid.get(processName) // ); } } else { if (this._envLoadingVisitor.getChanComplexCommEnv().get(chanName)) { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) //"if" by Samuel Barrocas code += " \t\t" + chanName + ccBracketizedsValues ( this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName/*this.prochid.get(processName).get(chanName)*/), chanName ) + ".timerSync(area, new int [] {0}, valuesstr); /*1*/"; else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*2.02*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); //code += // HiddenFromGUIInfo.hiddenSyncCode( // hiddenChannelsFromGui, // ccBracketizedsValues (this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName), chanName), // "timerSync (area, new int [] {0})/*2*/", this.prochid.get(processName) // ); } } else { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) //"if" by Samuel Barrocas if (!this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName)) + ".timerSync(area, new int [] {0}, valuesstr);/*3.3*/"; } else { code += " \t\t" + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName)/*this.updatedChanDimEnv.get (this.prochid.get(processName).get(chanName))*/) + ".timerSync (area, new int [] {0}, valuesstr);/*3.4*/"; } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*4*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 1, this.prochid.get(processName) ); //code += // HiddenFromGUIInfo.hiddenSyncCode ( // hiddenChannelsFromGui, // bracketizedsValues (this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName)), // "timerSync (area, new int [] {0})/*4*/", this.prochid.get(processName)); } } } } } } code += " \t}"; return code; } public static String guibracketized (Object value/*, HiddenFromGUIInfo hid*/) { Integer i = (Integer) value; return "[" + ((Integer) value < 0? 0 : value) + "]"; } public static String bracketizedsValues (int x) { //Developed by Samuel Barrocas String str = ""; for (int i = 0; i < x; i++) { str = str + CCUtil.bracketized ("values [" + i + "]"); } return str; } public static String ccBracketizedsValues (int x, String chanName) { //Developed by Samuel Barrocas String str = ""; for (int i = 0; i < x; i++) { str = str + CCUtil.bracketized ("(new Abs_" + chanName/*currentProcess*/ + " ()).abs (\"" + chanName + "\", " + i + ", new BigInteger (\"\" + values [" + i + "] + \"\"))"); } return str; } /** * */ private String chanActPerfRead(String processName, String chanName, CircusType circusType) { String code = ""; //JOptionPane.showMessageDialog (null, "Passou por Translator2Java.chanActPerfRead"); code += " \tprivate void btn_" + chanName + "_ActionPerformed(java.awt.event.ActionEvent evt) {"; if (circusType.isSyncType()) { //AQUI � UM IF QUE EXECUTA O BLOCO ABAIXO SE O CANAL EM QUESTAO NAO COMUNICA VALORES if (!useBarriers) code += " \t\t" + chanName + ".read();"; else { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) //"if" by Samuel Barrocas code += " \t\t" + chanName + ".timerSync (area, new int [] {0}, valuesstr);/*.sync()*/; /*Sync.1*/"; else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*10*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 0, this.prochid.get(processName) ); //code += HiddenFromGUIInfo.hiddenSyncCode ( // hiddenChannelsFromGui, "", // "timerSync (area, new int [] {0})/*10*/", // this.prochid.get(processName) //); } } } else { if (!useBarriers) { String chanCommType = circusType.getJavaCircusTypeName(); code += " \t\t" + chanCommType + " o = (" + chanCommType + ") " + chanName + ".read();"; code += " \t\tString st = o.toString();"; code += " \t\tthis.txt_" + chanName + ".setText(st);"; } else { code += " \t\tfinal int [] values = getValues_" + chanName + " (" + "this.combo_" + chanName + ", boxcontent_" + chanName + "); "; code += showEventInGUICode (processName, chanName); if (isTranslatedAsSimpleSynchronised (chanName, this.prochid.get(processName), cmain)/*(this._envLoadingVisitor.getChanMultiSyncEnv().get(chanName) || this._envLoadingVisitor.getChanComplexCommEnv().get(chanName) || this._envLoadingVisitor.getChanDotFieldEnv().get(chanName) || this._envLoadingVisitor.getChanExtChoiceEnv().get(chanName) || (this._envLoadingVisitor.getChanDimEnv().get(chanName) == 0 && this._envLoadingVisitor.getChanMultiSyncEnv().get(chanName))*/ ) { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) { //"if" by Samuel Barrocas code += " \t\tint x = (Integer) " + chanName + bracketizedsValues (this.updatedChanDimEnv.get(chanName)) + ".guiTimerSimpleRead (area, valuesstr);"; code += " \t\t/*System.out.println (x);*/"; } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*11*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 0, this.prochid.get(processName) ); // HiddenFromGUIInfo.hiddenSyncCode( // hiddenChannelsFromGui, // bracketizedsValues (this.updatedChanDimEnv/*_envLoadingVisitor.getChanDimEnv()*/.get(chanName)), // "guiTimerSimpleRead (area)", this.prochid.get(processName)); //code += " \t\t/*System.out.println (x);*/"; } } else { if (this._envLoadingVisitor.getChanComplexCommEnv().get(chanName)) { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) {//"if" by Samuel Barrocas if (!this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + ccBracketizedsValues ( this.updatedChanDimEnv.get(chanName), chanName/*this.prochid.get(processName).get(chanName)*/ ) + ".timerSync(area, new int [] {0}, valuesstr);/*5*/"; } else { code += " \t\t" + chanName + ccBracketizedsValues ( this.updatedChanDimEnv.get(this.prochid.get(processName).get(chanName)), chanName/*this.prochid.get(processName).get(chanName)*/ ) + ".timerSync(area, new int [] {0}, valuesstr);/*5*/"; } } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*6*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 0, this.prochid.get(processName) ); //code += // HiddenFromGUIInfo.hiddenSyncCode( // hiddenChannelsFromGui, // ccBracketizedsValues (this.updatedChanDimEnv.get(chanName), chanName), // "timerSync (area, new int [] {0})/*6*/", this.prochid.get(processName)); } } else { if (!this.prochid.get(processName).getMainChannels().contains(chanName)) {//"if" by Samuel Barrocas if (this.parallelismUpdater.parallelismBeingUsed.get(processName)) { code += " \t\t" + chanName + bracketizedsValues (this._envLoadingVisitor.getChanDimEnv().get( this.prochid.get(processName).get(chanName) )) + ".timerSync(area, new int [] {0}, valuesstr);/*7.0*/"; } else { code += " \t\t" + chanName + bracketizedsValues (this._envLoadingVisitor.getChanDimEnv().get( chanName//this.prochid.get(processName).get(chanName) )) + ".timerSync(area, new int [] {0}, valuesstr);/*7.5*/"; } } else { Vector <String> hiddenChannelsFromGui = this.prochid.get(processName).reverseGet(chanName); Coadj2SimpleSynchTransEnv c2sste = new Coadj2SimpleSynchTransEnv ( chanName, this.prochid.get(processName), this._envLoadingVisitor.getChanMultiSyncEnv(), this._envLoadingVisitor.getChanComplexCommEnv(), this._envLoadingVisitor.getChanDotFieldEnv(), this._envLoadingVisitor.getChanExtChoiceEnv(), this._envLoadingVisitor.getChanDimEnv(), cmain ); code += "/*8*/" + HiddenFromGUIInfo.hiddenSyncCode ( hiddenChannelsFromGui, this._envLoadingVisitor.getChanComplexCommEnv(), this.updatedChanDimEnv, c2sste, 0, this.prochid.get(processName) ); //code += // HiddenFromGUIInfo.hiddenSyncCode( // hiddenChannelsFromGui, // bracketizedsValues (this._envLoadingVisitor.getChanDimEnv().get(chanName)), // "timerSync (area, new int [] {0})/*8*/", this.prochid.get(processName)); } } } } } code += " \t}"; return code; } /** * Creates the .bat file for a process. */ private void createBatFile(ProcInfo procInfo) throws JCircusException { String processName = procInfo.getProcessName(); // File from template HashMap<String, String> map = new HashMap<String, String>(); map.put(Constants.C_BAT_PROJ, _projectName); map.put(Constants.C_BAT_MAIN, getNameMain(processName)); try { //String fileName = _projectDir + "\\" + getNameBat(processName) + ".bat"; String fileName = _projectDir + "/" + getNameBat(processName) + ".bat"; Util.createFileFromTemplate(Constants.TMP_BAT, map, fileName); } catch (Throwable t) { throw new JCircusException("Error while trying to create .bat file for " + processName, t); } } /******************************************* * Simple accessors. *******************************************/ /** * Code for package declaration. */ public String getPackage(String projectName, String pkg, /*Par�metro acrescentado por Samuel*/String compl) { String code = ""; code = "package "; if (!_compl.equals ("")) { //code = code + compl + "."; } code = code + projectName + "." + "src." + projectName; if (pkg != null) { code += "." + pkg; } code += "; /**/"; return code; } /** * Code for imports of a class. */ /*M�todo abaixo acrescentado por Samuel*/ public String getCompl () { if (_compl == null) { return ""; } else return "/*" + _compl + ".*/paper."; } /*M�todo acima acrescentado por Samuel*/ public String getImports(String projectName) { String code = "/**/ "; code += "import java.util.*; import org.jcsp.lang.*; "; code += "import " + /*getCompl () + */ projectName + "." + "src." + projectName + ".axiomaticDefinitions.*; "; code += "import " + /*getCompl () + */ projectName + "." + "src." + projectName + ".processes.*; "; code += "import " + /*getCompl () + */ projectName + "." + "src." + projectName + ".typing.*; "; code += "import " + /*getCompl () + */ projectName + "." + "src." + projectName + ".channels.*; "; code += "import " + /*getCompl () + */ projectName + "." + "src." + projectName + ".ccmaps.*; "; code += "import newjcircusutil." + Constants.CLS_RANGEN + "; "; code += "import newjcircusutil.multisync.*; "; code += "import " + /*getCompl () +*/ projectName + "." + "src." + projectName + ".gui.*; "; return code; } /** * Returns the name of the GUI class. */ private String getNameGui(String processName) { return "Gui_" + processName; } /** * Returns the name of the .bat file. */ private String getNameBat(String processName) { return "Run_" + processName; } /** * Returns the name of the Main class. */ private String getNameMain(String processName) { return "Main_" + processName; } /** * Gets the parameters of a parameterized process in a list of VarDecl. * */ protected static List<VarDecl> getNormalizedParams(CircusProcess circusProcess) { Factory factory = new Factory(); List<VarDecl> normParams = new ArrayList(); if (circusProcess instanceof ParamProcess) { DeclList decls = ((ParamProcess) circusProcess).getDeclList(); //normParams = Util.formatDecls(decls); //By Angela, abaixo by Sam normParams = Util.formatDecls((ZDeclList) decls); //Sam's, modified do de cima } return normParams; } /** * Public Getters. */ public List<ProcInfo> getProcInfoList() { return _procInfoList; } public Environment getEnvironment() { return _environment; } } |