Blame view
circus/src/jcircus/complexcomms/CCUtil.java
27.8 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 |
package jcircus.complexcomms; import java.math.BigInteger; import java.util.Vector; import javax.swing.JOptionPane; import jcircus.complementaryenvs.TypeSizeEnv; import jcircus.environment.Environment; import jcircus.newfrontendmethod.FrontEndAnn; import org.jcsp.lang.Alternative; import org.jcsp.lang.Guard; import net.sourceforge.czt.util.Visitor; import net.sourceforge.czt.z.ast.Expr; import net.sourceforge.czt.z.ast.NumExpr; import net.sourceforge.czt.z.ast.ProdExpr; import net.sourceforge.czt.z.ast.RefExpr; import net.sourceforge.czt.z.ast.SetExpr; import net.sourceforge.czt.z.ast.ZExprList; import net.sourceforge.czt.z.ast.ZNameList; import net.sourceforge.czt.circus.ast.ChannelDecl; import net.sourceforge.czt.circus.ast.Communication; import net.sourceforge.czt.circus.ast.CircusFieldList; import net.sourceforge.czt.circus.ast.DotField; import net.sourceforge.czt.circus.ast.Field; import net.sourceforge.czt.circus.ast.InputField; public class CCUtil { //int [] values = new int [10 /*cfl.size()*/]; //Object [] commValues = new Object [10 /*cfl.size()*/]; //boolean [] inputDecoration /*cfl.getCircusFieldList()*/ = new boolean [10 /*cfl.size()*/]; //String str = ""; public static int [] makeArrayOf (int x, Communication c) { CircusFieldList cfl = c.getCircusFieldList(); int [] xis = new int [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { xis [i] = x; } return xis; } public static boolean [] initInputDecoration (int size) { //Inits the decoration sequence of the communication. For example, if it is chan.5?x?y, then the inputDecoration will be inited as {false, false, false} boolean [] in = new boolean [size]; for (int i = 0; i < size; i++) { in [i] = false; } return in; } public static Object [] initCommValues (int size) { //Inits the values communicated. //when inputDecoration [i] = false, the content of commValues [i] doesn't matter. Object [] c = new Object [size]; for (int i = 0; i < size; i++) { c [i] = null; } return c; } private int [] max (int [] values) { int [] max = new int [values.length]; for (int i = 0; i < max.length; i++) { max [i] = 9; } return max; } private static boolean equalsToMax (int [] values) { boolean aux = true; for (int i = 0; i < values.length; i++) { if (values [i] != 9) { aux = false; } } return aux; } public static boolean reachedMax (int [] values, Vector <Vector <BigInteger>> valuesSet/*int max*/) { //Auxiliar function int size = valuesSet.size()/*values.length*/; boolean aux = true; for (int i = 0; i < size; i++) { int size2 = valuesSet.elementAt(i).size(); int index = valuesSet.elementAt(i).indexOf(new BigInteger ("" + values [i] + "")); if (valuesSet.elementAt(i).indexOf(new BigInteger ("" + values [i] + "")) < size2 - 1/*max*/) aux = false; } return aux; } public static int [] minFromNowOn (int from, int [] values, boolean [] inputDecoration, int [] min) { int size = values.length; for (int i = from; i < size; i++) { if (inputDecoration [i]) values [i] = min [i]; } return values; } public static int nextOne (int i, int [] values, Vector <Vector <BigInteger>> valuesSet) { //Este m�todo sup�e que o conjunto de valores j� est� em ordem crescente, e sem repeti��o de valores int size = valuesSet.elementAt(i).size(); boolean contains = valuesSet.elementAt(i).contains(new BigInteger ("" + values [i] + "")); BigInteger currentValue = new BigInteger ("" + values [i] + ""); int next = valuesSet.elementAt(i).indexOf(currentValue) + 1; int returnedValue = valuesSet.elementAt(i).elementAt(next).intValue(); return valuesSet.elementAt(i).elementAt(next).intValue(); } public static Vector <Vector <BigInteger>> createTheASet (int order, int [] min, int [] max) { Vector <Vector <BigInteger>> set = new Vector <Vector <BigInteger>> (); Vector <BigInteger> subSet = new Vector <BigInteger> (); for (int i = 0; i < order; i++) { for (int j = min [i]; j <= max [i]; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement(subSet); subSet = new Vector <BigInteger> (); } return set; } public static String setExprCode (Vector <BigInteger> v/*SetExpr setExpr*/) { //TODO testar String str = ""; str = str + " subSet = new Vector <BigInteger> (); "; int setSize = v.size(); for (int k = 0; k < setSize; k++) { BigInteger expr = v.elementAt(k); str = str + " subSet.addElement (new BigInteger (\"" + expr + "\")); "; } return str; } public static String theATypeCode () { //TODO testar String str = " subSet = new Vector <BigInteger> (); "; for (int i = -9; i <= 9; i++) { //TODO Limites que impomos ao tipo inteiro, de 0 at� 9. Mas nem sempre dever� ser assim. str = str + " subSet.addElement (new BigInteger (\"" + i + "\")); "; } return str; } public static String chanExprCode (Vector <Vector <BigInteger>> vv) { String str = " set = new Vector <Vector <BigInteger>> (); "; if (vv == null) { System.out.print(""); } int prodSize = (vv == null || vv.isEmpty())? 0 : vv.size(); for (int i = 0; i < prodSize; i++) { Vector <BigInteger> expr = vv.elementAt(i); str = str + setExprCode (expr); str = str + " set.addElement (subSet); "; } return str; } /* public static String chanExprCode (Vector <BigInteger> v //SetExpr setExpr * ) { //TODO testar String str = " Vector <Vector <BigInteger>> set = new Vector <BigInteger> (); "; Vector <BigInteger> expr = v; str = str + setExprCode ((SetExpr)expr); str = str + " set.addElement (subSet); "; return str; } public static String chanExprCode () { //TODO testar String str = " Vector <Vector <BigInteger>> set = new Vector <BigInteger> (); "; str = str + aTypeCode (); str = str + " set.addElement (subSet); "; return str; } */ /* public static String makeEnvChannelsCode (String channelName, ChannelDecl channelDecl) { //TODO esse aqui testa v�rios TODO String str = " HashMap <String, Vector <Vector <BigInteger>>> env_channels = new HashMap <String, Vector <Vector <BigInteger>>> (); " + " Vector <BigInteger> subSet; " + " Vector <Vector <BigInteger>> set; " + " public void makeEnvChannels () { "; ZNameList names = channelDecl.getZChannelNameList(); Expr expr = channelDecl.getExpr(); if (expr instanceof RefExpr) { str = str + chanExprCode ((RefExpr)expr); } else if (expr instanceof SetExpr) { str = str + chanExprCode ((SetExpr)expr); } else //if (expr instanceof ProdExpr) { str = str + chanExprCode ((ProdExpr)expr); } String [] chanNames = new String [names.size()]; for (int i = 0; i < chanNames.length; i++) { chanNames [i] = names.get(i).toString(); str = str + " env_channels.put (\"" + chanNames [i] + "\", " + "set" + "); "; } return str + " } "; } */ public static String makeEnvChannelsCode (String [] channelNames, Channel2TypeEnvironment env) { String str = " public HashMap <String, Vector <Vector <BigInteger>>> env_channels = new HashMap <String, Vector <Vector <BigInteger>>> (); " + " Vector <BigInteger> subSet; " + " Vector <Vector <BigInteger>> set; "; for (int i = 0; i < channelNames.length; i++) { str = str + " public void makeEnvChannels" + i + " () { " + chanExprCode (env.get(channelNames [i])) + " env_channels.put (\"" + channelNames [i] + "\", " + "set" + "); " + " } "; } return str; } public static String makeEnvChannelsCode (String channelName1, Vector <Vector <BigInteger>> vv/*ChanTypeEnv4CC env*/) { String str = " public HashMap <String, Vector <Vector <BigInteger>>> env_channels = new HashMap <String, Vector <Vector <BigInteger>>> (); " + " Vector <BigInteger> subSet; " + " Vector <Vector <BigInteger>> set; " + " public void makeEnvChannels () { "; str = str + chanExprCode (vv); str = str + " env_channels.put (\"" + channelName1 + "\", " + "set" + "); " + " /*}*/ "; return str + " } ";//} "; } public static Vector <Vector <BigInteger>> toVVBigInteger (Expr ccExpr, int minComm, int maxComm, Environment env, TypeSizeEnv tse) { if (ccExpr instanceof RefExpr) { if (!((RefExpr)ccExpr).getName().toString().equals("$$SYNCH")) { Vector <Vector <BigInteger>> set = new Vector <Vector <BigInteger>> (); Vector <BigInteger> subSet = new Vector <BigInteger> (); RefExpr refExpr = (RefExpr)ccExpr; if (tse.getMap().keySet().contains(refExpr.getZName().toString())) { int x = 0; int y = tse.get(refExpr.getZName().toString()); for (int j = x; j < y; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement (subSet); //subSet = new Vector <BigInteger> (); return set; } else { //if (o tipo for inteiro, então) { //TODO faça com que minComm receba -maxComm/2, e itere até maxComm/2 //} for (int j = minComm; j <= maxComm; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement (subSet); subSet = new Vector <BigInteger> (); return set; } } else { return new Vector <Vector <BigInteger>> (); } } else if (ccExpr instanceof SetExpr) { Vector <Vector <BigInteger>> set = new Vector <Vector <BigInteger>> (); Vector <BigInteger> subSet = new Vector <BigInteger> (); ZExprList setExprList = ((SetExpr) ccExpr).getZExprList(); int setSize = setExprList.size(); for (int k = 0; k < setSize; k++) { Expr expr2 = setExprList.get(k); if (expr2 instanceof NumExpr) { //Aqui estamos admitindo que NumExpr sera um numero, e nao uma expressao numerica. //Sendo uma expressao numerica com operadores, variaveis, e etc, nao garanto que aqui vai funcionar subSet.addElement (((NumExpr)expr2).getValue());//Integer.parseInt(((NumExpr)expr2).getValue()); } } set.addElement (subSet); subSet = new Vector <BigInteger> (); return set; } else if (ccExpr instanceof ProdExpr) { Vector <Vector <BigInteger>> set = new Vector <Vector <BigInteger>> (); Vector <BigInteger> subSet = new Vector <BigInteger> (); ZExprList prodExprList = ((ProdExpr)ccExpr).getZExprList(); int prodSize = prodExprList.size(); for (int i = 0; i < prodSize; i++) { Expr expr = prodExprList.get(i); //set.addElement(obj); set.addAll(toVVBigInteger (expr, minComm, maxComm, env, tse)); } return set; } else /*if (any other condition?)*/{ return new Vector <Vector <BigInteger>> (); } } public static void printValues (int [] values) { for (int i = 0; i < values.length; i++) { System.out.print ("values [" + i + "] = " + values [i] + "; "); } System.out.println (); } public static int [] increment (int [] values, boolean [] inputDecoration, int [] min, int [] max, Vector <Vector <BigInteger>> valuesSet) { int size = values.length; boolean incremented = false; for (int i = size - 1; i >= 0; i--) { if (values [i] < max [i] && !incremented && inputDecoration [i]) { values [i] = nextOne (i, values, valuesSet); incremented = true; minFromNowOn (i + 1, values, inputDecoration, min); } } return values; } public int getCommValue (int index, int [] values) { return values [index]; } public static int [] getInitArrayOfValues (boolean [] inputDecoration, Vector <Vector <BigInteger>> vvb/*int min, int max*/) { int [] values = new int [inputDecoration.length]; int size = values.length; for (int i = 0; i < size; i++) { if (inputDecoration [i]) { values [i] = /*min*/ vvb.elementAt(i).elementAt(0).intValue(); } else values [i] = /*max*/ vvb.elementAt(i).elementAt(vvb.elementAt(i).size() - 1).intValue(); } return values; } public static String bracketized (Object value) { return "[" + value + "]"; } public static String bracketizeds (int x, Object value) { String str = ""; for (int i = 0; i < x; i++) { str = str + bracketized (value); } return str; } public static String bracketizeds (String chanName, int [] values, Object [] commValues, boolean [] inputDecoration, int label) { String str = chanName + " "; int size = values.length; for (int i = 0; i < size; i++) { if (inputDecoration [i]) str = str + bracketized ("abs_" + chanName + ".abs (" + "\"" + chanName + "\", " + i + ", new BigInteger (\"" + values [i] + "\"))"); else str = str + bracketized ("abs_" + chanName/*+ label*/ + ".abs (" + "\"" + chanName + "\", " + i + ", " + "new BigInteger (\"\" + (" + commValues [i] + ").getValue()/*toString()*/ + \"\")" + ")"); /*str = str + bracketized ("ccMaps.env_channels.get (" + "\"" + chanName + "\").elementAt (" + i + ").indexOf (new BigInteger (\"" + values [i] + "\"))"); else str = str + bracketized ("ccMaps.env_channels.get (" + "\"" + chanName + "\").elementAt (" + i + ").indexOf (" + "(new BigInteger ((" + commValues [i] + ").toString())" + "))");*/ } return str; } public static String [] varNames (Communication c) { //Testada CircusFieldList cfl = c.getCircusFieldList(); String [] names = new String [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { names [i] = ((InputField)cfl.get(i)).getVariableZName().toString(); } else { names [i] = "none"; } } return names; } public static boolean [] toInputDecoration (Communication communication) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } } return inputDecoration; } public static int [] boundsAType (Communication c, int min) { int size = c.getCircusFieldList().size(); int [] mins = new int [size]; for (int i = 0; i < size; i++) { mins [i] = min; } return mins; } public static Object [] toCommValues (Communication communication, Visitor c) { //TODO n�o testada. A fun��o guardsCode que inclui a assinatura com Communication pode ser simplificada com o uso de toCommValues e toInputDecoration CircusFieldList cfl = communication.getCircusFieldList(); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { commValues [i] = -1; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } return commValues; } public static String makeSyncOnOtherEndsButFirstCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector <Vector <BigInteger>> valuesSet, int label, Channel2TypeEnvironment cte4cc) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } printNames (varNames (communication)); return makeSyncOnOtherEndsButFirstCode (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label, cte4cc); } public static String getTypeInstantiation (String typeName, String valueName) { if (typeName.equals ("CircusInteger")) { return valueName; } else return "new CircusInteger ((new " + typeName + " (" + typeName + "." + valueName + ")).getValue ())"; } public static String complementarCommParams (boolean isDecl, Communication c, Channel2TypeEnvironment cte4cc) { String channelName = c.getChannelExpr().getZName().toString(); CircusFieldList cfl = c.getCircusFieldList(); String str = cfl.size() > 0? "" : ""; for (int i = 0; i < cfl.size(); i++) { Field field = cfl.get(i); if (field instanceof DotField) { Expr expr = ((DotField)field).getExpr(); if (expr instanceof RefExpr) { String strexpr = ((RefExpr)expr).getName().toString(); str = str + ", "; if (isDecl) { str = str + "CircusInteger " + strexpr; } else { str = str + getTypeInstantiation (cte4cc.getFreeType(channelName, i), strexpr); } //str = str + ((RefExpr)expr).getName().toString(); } } } return str; } protected static String indexesbutfirstcode () { return " private static int [] endindexesbutfirst (int [] endindexes) { " + " int [] indexesbutfirst = new int [endindexes.length - 1]; " + " for (int i = 1; i < endindexes.length; i++) { " + " indexesbutfirst [i - 1] = endindexes [i]; " + " } " + " return indexesbutfirst; "+ " } "; } public static String makeSyncOnOtherEndsButFirstCode (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector <Vector <BigInteger>> valuesSet, int label, Channel2TypeEnvironment cte4cc) { int counter = 0; String str = ""; //str = str + indexesbutfirstcode (); str = str + " public static void syncOnOtherEndsButFirst_" + chanName + " (final GeneralChannel " + bracketizeds (commValues.length, "") + chanName + ", final Abs_" + chanName + " abs_" + chanName + "" + complementarCommParams (true, communication, cte4cc) + ", int [] endindexes) { "; if (!isCCSyncType (valuesSet)) { /*str = str + " switch (select) { ";*/ str = str + " int [] indexesbutfirst = endindexesbutfirst (endindexes); "; str = str + " if (indexesbutfirst.length == 0) { " + " //Nothing to do " + " } " + " else { " + " int select = (new org.jcsp.lang.Alternative ( " + " new org.jcsp.lang.Guard [] { "; int [] values = getInitArrayOfValues (inputDecoration, valuesSet); while (!reachedMax (values, valuesSet)) { str = str + " " + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd (indexesbutfirst), "; increment (values, inputDecoration, min, max, valuesSet); counter++; } str = str + " } "; str = str + " )).select (); "; str = str + " syncOnOtherEndsButFirst_" + chanName + " " +"(" + chanName + ", abs_" + chanName + complementarCommParams (false, communication, cte4cc) + ", indexesbutfirst" + "); " ; str = str + " } " + " } "; return str; } else { FrontEndAnn fea = FrontEndAnn.getFrontEndAnn(communication); str = str + " " + chanName + ".syncOnOtherEndsButFirst (" + FrontEndAnn.getFrontEndAnn(communication).toString() + "); "; } str = str + " }"; return str; } public static int countGuards (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector <Vector <BigInteger>> valuesSet, int label) { int counter = 1; if (!isCCSyncType (valuesSet)) { int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; while (!reachedMax (values, valuesSet)) { increment (values, inputDecoration, min, max, valuesSet); counter++; } return counter; } else { return 1; } } public static String guardsCode (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector <Vector <BigInteger>> valuesSet, int label) { if (!isCCSyncType (valuesSet)) { int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; while (!reachedMax (values, valuesSet)) { str = str + " " + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "),"; increment (values, inputDecoration, min, max, valuesSet); } str = str + " " + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "), "; return str; } else { return chanName + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "), "; } } private static boolean isCCSyncType (Vector <Vector <BigInteger>> valuesSet) { if (valuesSet.isEmpty()) { return true; } else { int size = valuesSet.size(); if (size == 0) return true; else if (size == 1) { if (valuesSet.elementAt(0).isEmpty()) { return true; } } return false; } } public static StringAndCounter envsCode (Object [] commValues, boolean [] inputDecoration, String [] names, int [] min, int [] max, int indexOfChosenComm, int initCounterSelect, boolean extChoice, Vector <Vector <BigInteger>> valuesSet) { //int [] values = getInitArrayOfValues (inputDecoration, min, max); StringAndCounter sac = new StringAndCounter(); if (!isCCSyncType (valuesSet)){ int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; int counter = 0/*initCounterSelect*/; while (!reachedMax (values, valuesSet/*max*/)) { boolean reached = reachedMax (values, valuesSet); str = str + " HashMap select_" + (counter + initCounterSelect) + " = new HashMap (); "; for (int i = 0; i < names.length; i++) { if (inputDecoration [i]/*!names [i].equals ("none")*/) { str = str + " select_" + (counter + initCounterSelect) + ".put (\"" + names [i] + "\", new Integer (" + values [i] + ")); "; } } str = str + " mapFromSelectToVarEnv.put (new Integer (" + (counter + initCounterSelect) + "), " + "select_" + (counter + initCounterSelect) + "); "; if (extChoice) str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + ")); "; //System.out.println ("LOOP INFINITO??"); if (!reachedMax (values, valuesSet)) increment (values, inputDecoration, min, max, valuesSet); counter++; } str = str + " HashMap select_" + (counter + initCounterSelect) + " = new HashMap ();"; for (int i = 0; i < names.length; i++) { if (inputDecoration [i]) { str = str + " select_" + (counter + initCounterSelect) + ".put (\"" + names [i] + "\", new Integer (" + values [i] + ")); "; } } str = str + " mapFromSelectToVarEnv.put (new Integer (" + (counter + initCounterSelect) + "), " + "select_" + (counter + initCounterSelect) + "); "; if (extChoice) { str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + ")); "; System.out.print (""); } if (!reachedMax (values, valuesSet)) increment (values, inputDecoration, min, max, valuesSet); counter++; //initCounterSelect = counter; sac.str = str; sac.counter = counter; return sac; } else { String str = ""; int counter = 0;/*initCounterSelect;*/ str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + ")); "; counter++; sac.str = str; sac.counter = counter; //initCounterSelect = counter; return sac; } } public static StringAndCounter envsCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, int indexOfChosenComm, int initCounterSelect, boolean extChoice, Vector <Vector <BigInteger>> valuesSet) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); String [] names = new String [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; names [i] = ((InputField)cfl.get(i)).getVariableZName().toString(); } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); names [i] = "none"; } } printNames (varNames (communication)); //if (inputDecoration.length >0) return envsCode (commValues, inputDecoration, names, min, max, indexOfChosenComm, initCounterSelect, extChoice, valuesSet); //else return new StringAndCounter (); } public static int countGuards (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector <Vector <BigInteger>> valuesSet, int label) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } //printNames (varNames (communication)); return countGuards (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label); } public static String guardsCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector <Vector <BigInteger>> valuesSet, int label) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } printNames (varNames (communication)); return guardsCode (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label); } public static void printNames (String [] names) { //METODO TEMPORARIO. Depois que a funcao varNames for verificada e estiver correta, esta aqui eh dispensavel String str = ""; for (int i = 0; i < names.length; i++) { str = str + names [i] + " "; } //JOptionPane.showMessageDialog (null, str); } public static int potInt (int b, int e) { ////Servir� para a gera��o do m�todo getProcessSyncEnds na vers�o estendida int aux = 1; for (int i = 1; i <= e; i++) { aux = aux * b; } return aux; } public static int valueOfCommInputPart (int line, int pos, int numOfInputs, int minValue, int maxValue) { return (line / (potInt (maxValue - minValue + 1, numOfInputs - pos))) % (maxValue - minValue + 1); } public static int indexOfInputPart (int pos, boolean [] inputDecoration) { int n = 0; if (!inputDecoration [pos]) { return -1; } else { for (int i = pos; i < inputDecoration.length; i++) { if (inputDecoration [i]) n++; } } return n; } public static int numOfInputs (boolean [] inputDecoration) { int x = 0; for (int i = 0; i < inputDecoration.length; i++) { if (inputDecoration [i]) x++; } return x; } public static int numOfGuards (boolean [] inputDecoration, Vector <Vector <BigInteger>> v) { int m = v.size(); int aux = 0; for (int i = 0; i < m; i++) { if (inputDecoration [i]) { for (int j = 0; j < v.elementAt(i).size(); j++) { aux++; } } else aux++; } return aux; } public static void main (String args []) { //System.out.println (guardsCode ("chan", new boolean [] {true, false, true, true}, new Object [] {-1, 5, -1, -1}, new int [] {0, 0, 0, 0}, new int [] {9, 9, 9, 9})); //System.out.print (calculateCommValue (0, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (1, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (2, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (3, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); } } |