ParallelismUpdater.java 46.3 KB
   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
package jcircus.parallelism;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;

import net.sourceforge.czt.circus.ast.Action1;
import net.sourceforge.czt.circus.ast.Action2;
import net.sourceforge.czt.circus.ast.ActionPara;
import net.sourceforge.czt.circus.ast.AssignmentCommand;
import net.sourceforge.czt.circus.ast.AssignmentPairs;
import net.sourceforge.czt.circus.ast.BasicChannelSetExpr;
import net.sourceforge.czt.circus.ast.BasicProcess;
import net.sourceforge.czt.circus.ast.CallAction;
import net.sourceforge.czt.circus.ast.CallProcess;
import net.sourceforge.czt.circus.ast.ChannelDecl;
import net.sourceforge.czt.circus.ast.ChannelPara;
import net.sourceforge.czt.circus.ast.ChannelSet;
import net.sourceforge.czt.circus.ast.ChaosAction;
import net.sourceforge.czt.circus.ast.CircusAction;
import net.sourceforge.czt.circus.ast.CircusActionList;
import net.sourceforge.czt.circus.ast.CircusChannelSet;
import net.sourceforge.czt.circus.ast.CircusCommand;
import net.sourceforge.czt.circus.ast.CircusProcess;
import net.sourceforge.czt.circus.ast.CommPattern;
import net.sourceforge.czt.circus.ast.CommUsage;
import net.sourceforge.czt.circus.ast.Communication;
import net.sourceforge.czt.circus.ast.ExtChoiceAction;
import net.sourceforge.czt.circus.ast.ExtChoiceActionIte;
import net.sourceforge.czt.circus.ast.FieldList;
import net.sourceforge.czt.circus.ast.GuardedAction;
import net.sourceforge.czt.circus.ast.HideAction;
import net.sourceforge.czt.circus.ast.IfGuardedCommand;
import net.sourceforge.czt.circus.ast.IntChoiceAction;
import net.sourceforge.czt.circus.ast.IntChoiceActionIte;
import net.sourceforge.czt.circus.ast.InterleaveAction;
import net.sourceforge.czt.circus.ast.InterleaveActionIte;
import net.sourceforge.czt.circus.ast.InterleaveProcess;
import net.sourceforge.czt.circus.ast.MuAction;
import net.sourceforge.czt.circus.ast.OnTheFlyDefAnn;
import net.sourceforge.czt.circus.ast.ParAction;
import net.sourceforge.czt.circus.ast.ParProcess;
import net.sourceforge.czt.circus.ast.ParallelAction;
import net.sourceforge.czt.circus.ast.ParallelActionIte;
import net.sourceforge.czt.circus.ast.ParamAction;
import net.sourceforge.czt.circus.ast.ParamProcess;
import net.sourceforge.czt.circus.ast.PrefixingAction;
import net.sourceforge.czt.circus.ast.Process2;
import net.sourceforge.czt.circus.ast.ProcessPara;
import net.sourceforge.czt.circus.ast.RenameAction;
import net.sourceforge.czt.circus.ast.SeqAction;
import net.sourceforge.czt.circus.ast.SeqActionIte;
import net.sourceforge.czt.circus.ast.SkipAction;
import net.sourceforge.czt.circus.ast.StopAction;
import net.sourceforge.czt.circus.ast.VarDeclCommand;
import net.sourceforge.czt.circus.impl.CircusActionImpl;
import net.sourceforge.czt.circus.impl.ExtChoiceActionImpl;
import net.sourceforge.czt.circus.impl.PrefixingActionImpl;
import net.sourceforge.czt.circus.ast.ParallelProcess;
import net.sourceforge.czt.circus.ast.CircusCommunicationList;
import net.sourceforge.czt.circus.util.Factory;
import net.sourceforge.czt.util.Visitor;
import net.sourceforge.czt.z.ast.Expr;
import net.sourceforge.czt.z.ast.LatexMarkupPara;
import net.sourceforge.czt.z.ast.NarrPara;
import net.sourceforge.czt.z.ast.NarrSect;
import net.sourceforge.czt.z.ast.Para;
import net.sourceforge.czt.z.ast.ParaList;
import net.sourceforge.czt.z.ast.RefExpr;
import net.sourceforge.czt.z.ast.Spec;
import net.sourceforge.czt.z.ast.ZDeclList;
import net.sourceforge.czt.z.ast.ZExprList;
import net.sourceforge.czt.z.ast.ZName;
import net.sourceforge.czt.z.ast.ZNameList;
import net.sourceforge.czt.z.ast.ZParaList;
import net.sourceforge.czt.z.ast.ZSect;

import java.lang.*;

import javax.swing.JOptionPane;

import jcircus.environment.ChanInfoEnv;
import jcircus.environment.ProcChanEnv;
import jcircus.newfrontendmethod.FrontEndCounter;
import jcircus.newutil.CallUtil;
import jcircus.newutil.ChanSetUtil;
import jcircus.newutil.ChannelUtil;
import jcircus.newutil.ExceptionUtil;
import jcircus.newutil.FactoryUtil;
import jcircus.newutil.ProcessUtil;
import jcircus.newutil.PrinterUtil;
import jcircus.newutil.RenamingUtil;

public class ParallelismUpdater { //Antiga classe ParallelismVisitor

/*Atributos*/
int counterHash = 0;
static FactoryUtil pf = new FactoryUtil ();
static HashMap <String, String> call2call = new LinkedHashMap <String, String> ();
static HashMap <String, HashMap <String, FriendshipSets>> call2pfe = new HashMap <String, HashMap <String, FriendshipSets>> ();
static String complementaryActionAnn = "complementaryAction";
/*Atributos*/

public HashMap <String, Boolean> parallelismBeingUsed = new LinkedHashMap <String, Boolean> ();//false;
public HiddenFromGUIInfo hid = new HiddenFromGUIInfo ();
public ProcHiddenFromGUIEnv prochid = new ProcHiddenFromGUIEnv ();
private void hiddenPut (String chan, Integer [] renamingIndexes) {
String [] hidden = arrayOfChannels (chan, renamingIndexes);
hid.put(chan, HiddenFromGUIInfo.toVector (hidden));
}
public static boolean isComplementaryActionPara (ActionPara para) {
if (para.getCircusAction().getAnn(String.class).equals(complementaryActionAnn)) {
return true;
}
return false;
}
public static boolean isMainActionPara (ActionPara para) {
if (para.getName().toString().contains("MainAction") && para.getName().toString().contains("$$")) {
return true;
}
return false;
}
private static boolean containsChannel (String channel, Object [] str) {
boolean aux = false;
for (int i = 0; i < str.length; i++) {
if (str [i] == channel) {
aux = true;
}
}
return aux;
}
private static String [] arrayOfChannels (String chanName, Integer [] x) {
String [] str = new String [x.length];
for (int i = 0; i < str.length; i++) {
str [i] = chanName + x [i];
}
return str;
}
private static Vector <String> vectorOfChannels (String chanName, Integer [] x) {
Vector <String> str = new Vector <String> ();
//String [] str = new String [x.length];
for (int i = 0; i < x.length; i++) {
str.addElement(chanName + x [i]);
}
return str;
}
public static boolean contains (String str, String [] strs) {
boolean aux = false;
for (int i = 0; i < strs.length; i++) {
if (strs [i].equals(str))
aux = true;
}
return aux;
}

private static boolean channelIsOnNameList (String channel, ZNameList channelList) {
boolean aux = false;
for (int i = 0; i < channelList.size(); i++) {
if (channelList.get(i).toString().equals(channel)) {
aux = true;
}
}
return aux;
}
public static boolean channelIsOnChannelDecl (String channel, ChannelDecl channelDecl) {
ZNameList nameList = channelDecl.getZChannelNameList();
return channelIsOnNameList (channel, nameList);
}

private boolean hasMainChannelOnDecl (String channel, ChannelDecl cdecl) {
boolean aux = false;
ZNameList names = cdecl.getZChannelNameList();
int size = names.size();
for (int i = 0; i < size; i++) {
String name = names.get(i).toString();
if (name.equals(this.hid.get(channel))) {
aux = true;
}
}
return aux;
}

private ChannelDecl updateChannelDecl (HashMap <String, FriendshipSets> map, Factory f, Expr expr, ChannelDecl cdecl) {
for (int k = 0; k < map.keySet().size(); k++) {
int iSize = map.get(map.keySet().toArray()[k]).getFriendshipSets().size();
HashMap <String, Integer []> mapstrint = FriendshipSets.renamingIndexes(map, k);

for (int i = 0; i < iSize; i++) {
Integer [] allindexes = objectToInteger (FriendshipSets.allIndexes((String) mapstrint.keySet().toArray() [k], map).toArray());
Object [] channelKeys = arrayOfChannels ((String) mapstrint.keySet().toArray() [k], allindexes);

hiddenPut ((String) mapstrint.keySet().toArray() [k], allindexes);

for (int j = 0; j < channelKeys.length; j++) {
if (!channelIsOnChannelDecl ((String)channelKeys [j], cdecl) && hasMainChannelOnDecl ((String)channelKeys [j], cdecl))
cdecl.getZChannelNameList().add(f.createZName((String)channelKeys [j]));
}
System.out.print("");
}
}
return cdecl;
}
public static String [] objectToString (Object [] o) {
String [] str = new String [o.length];
for (int i = 0; i < str.length; i++) {
str [i] = (String) o [i];
}
return str;
}
public static Integer [] objectToInteger (Object [] o) {
Integer [] str = new Integer [o.length];
for (int i = 0; i < str.length; i++) {
str [i] = (Integer) o [i];
}
return str;
}
private static Expr [] objectToExpr (Object [] o) {
Expr [] str = new Expr [o.length];
for (int i = 0; i < str.length; i++) {
str [i] = (Expr) o [i];
}
return str;
}

private void addAsPreviousActionPara (ActionPara para, ZParaList previousParas) { //TODO TESTAR!
//Adiciona a versão original do parágrafo de ação, a que estava antes da mudança por causa do paralelismo, caso ele exista.
//A intenção aqui é permitir que um mesmo parágrafo de ação possa ser modificado mais de uma vez
Factory f = new Factory ();
ActionPara previous = f.createActionPara();
String name =
(para.getZName().toString().contains("mainAction") && !para.getZName().toString().contains("Previous"))?
"MA"
: (para.getZName().toString().contains("mainAction"))? "PreviousMA" : para.getZName().toString();
previous.setName(f.createZName("Previous" + name));
previous.setCircusAction(/*pf.createCircusAction*/(para.getCircusAction()));
previousParas.add(previous);
}

public boolean needsParallelismRenamingMethod (CircusAction action, CircusProcess process, Spec spec, String actionName, String procName) {
if (process instanceof BasicProcess || process instanceof ParamProcess) {
Vector <String> actionNames = new Vector <String> ();
actionNames.add(actionName);
action = CallUtil.expandAction (actionNames, action, process, spec);
this.counterHash = 0;
addAnnsToActionBranches (action, /*false,*/ process);
String str = PrinterUtil.printAnns4Action(action, spec);//printAction(action);
HashMap <String, FriendshipSets> map = ultimateConstructFriendshipSets (action, process, actionName, spec);
Vector <String> visibleChannels = ChannelUtil.getVisibleChannels (action, process, actionName, spec);
boolean aux = false;
for (int i = 0; i < visibleChannels.size(); i++) {
if (map.get(visibleChannels.elementAt(i)).getFriendshipSets().size() > 1) {
aux = true;
}
}
removeAnnsFromActionBranches (action, process);
return aux;
}
else if (process instanceof Process2) {
if (process instanceof ParProcess) {
Vector <String> visibleLeft = ChannelUtil.getVisibleChannels (((ParProcess)process).getLeftProcess(), spec);
Vector <String> visibleRight = ChannelUtil.getVisibleChannels (((ParProcess)process).getRightProcess(), spec);
Vector <String> channelSet = new Vector <String> ();
if (process instanceof ParallelProcess) {
channelSet = ChanSetUtil.channelSet(process, spec);
}

if (FriendshipSets.forcedInter (visibleLeft, visibleRight, channelSet).size() > 0) {
return true;
}
return false;
/*boolean nprm1 = needsParallelismRenamingMethod (action, ((ParProcess)process).getLeftProcess(), spec, actionName, procName);
boolean nprm2 = needsParallelismRenamingMethod (action, ((ParProcess)process).getRightProcess(), spec, actionName, procName);
return nprm1 || nprm2;*/
}
else {
boolean nprm1 = needsParallelismRenamingMethod (action, ((Process2)process).getLeftProcess(), spec, actionName, procName);
boolean nprm2 = needsParallelismRenamingMethod (action, ((Process2)process).getRightProcess(), spec, actionName, procName);
return nprm1 && nprm2;
}
}
else if (process instanceof CallProcess) {
CircusProcess content = ProcessUtil.getContentOfCallProcess((CallProcess)process, spec);
return needsParallelismRenamingMethod (action, content, spec, actionName, procName);
}
else return false;
}

public boolean needsParallelismRenamingMethod (CircusProcess process, Spec spec, String procName) {
FactoryUtil pf = new FactoryUtil ();
CircusAction action = pf.createExpandedCircusAction(ProcessUtil.resultingExpandedMainAction2 (process, spec), process, spec);
Vector <String> mucalls = CallUtil.muCalls (action, process, spec);
CallUtil.addMuCallAnns (action, process, spec, mucalls);
this.counterHash = 0;
return needsParallelismRenamingMethod (action, process, spec, "mainAction", procName);
}

public void updateSpec (Spec spec) {
ZSect zSect;
if (spec.getSect().get(0) instanceof NarrSect)
zSect = (ZSect) spec.getSect().get(1);
else
zSect = (ZSect) spec.getSect().get(0);
ZParaList paras = (ZParaList) zSect.getParaList();
for (int i = 0; i < paras.size(); i++) {
if (paras.get(i) instanceof ProcessPara) {
ProcessPara para = (ProcessPara) paras.get(i); //Aqui vai invocar os visitadores dos paragrafos que nao forem narrativos (com texto), ou de tags de Latex
String paraName = para.getZName().toString();
if (para.getCircusProcess() instanceof BasicProcess) {
BasicProcess basic = (BasicProcess)para.getCircusProcess();
ZParaList paralist = basic.getZParaList();
//CallUtil.transformActionParasToRecursive(paralist, basic, spec);
//Já tem em CallUtil.expandCallsOnMainActions, então não precisa invocar aqui (08/07/2013)
}
if (needsParallelismRenamingMethod (para.getCircusProcess(), spec, para.getZName().toString())) {
parallelismBeingUsed.put(paraName, true);
if (para.getAnn(CopyProcessAnn.class) == null) {
/**
//CircusProcess p = ProcessUtil.transformToBasicProcess(para.getCircusProcess(), spec, paraName);
//para.setCircusProcess(p);
//Aqui também não precisa mais, pois ProcessUtil.updateProcessesToBasicProcesses já tem
*/
this.counterHash = 0;
updateProcessPara (para, spec);
System.out.print("");
}
}
else {
parallelismBeingUsed.put(paraName, false);
this.prochid.put(paraName, new HiddenFromGUIInfo ());
}
}
}
}
public void updateProcessPara (ProcessPara processPara, Spec spec) {
ZSect zSect;
if (spec.getSect().get(0) instanceof NarrSect)
zSect = (ZSect) spec.getSect().get(1);
else
zSect = (ZSect) spec.getSect().get(0);
ZParaList paras = (ZParaList) zSect.getParaList();
Factory f = new Factory ();
ZParaList newParas = f.createZParaList();
ChannelDecl channelDecl = f.createChannelDecl();
HashMap <String, FriendshipSets> map = new HashMap <String, FriendshipSets> ();
ZParaList previousActionParas = f.createZParaList();
BasicProcess process = processPara.getCircusBasicProcess();
ParaList paraList = process.getParaList();
int size = ((ZParaList)paraList).size();
for (int i = 0; i < ((ZParaList)paraList).size(); i++) {
Para para = (Para) ((ZParaList) paraList).get(i);
this.counterHash = 0;
if (para instanceof ActionPara) {
CircusAction action = ((ActionPara)para).getCircusAction();
Vector <String> mucalls = CallUtil.muCalls (action, process, spec);
CallUtil.addMuCallAnns (action, process, spec, mucalls);
//CircusAction action = ((ActionPara)para).getCircusAction();
String actionName = ((ActionPara)para).getName().toString();
/**
//para = CallUtil.similarRecursiveActionPara ((ActionPara)para, process, spec);
//((ActionPara)para).setCircusAction(CallUtil.seqVersionOfAction(((ActionPara) para).getCircusAction()));
* Também não são mais necessários...
**/
((ZParaList) paraList).set(i, para);
addAsPreviousActionPara ((ActionPara)para, previousActionParas);
System.out.print("");
}
}
for (int i = 0; i < ((ZParaList)paraList).size(); i++) {
Para para = (Para) ((ZParaList) paraList).get(i);
this.counterHash = 0;
if (para instanceof ActionPara) {
CircusAction action = ((ActionPara)para).getCircusAction();
Vector <String> mucalls = CallUtil.muCalls (action, process, spec);
CallUtil.addMuCallAnns (action, process, spec, mucalls);
//CircusAction action = ((ActionPara)para).getCircusAction();
String actionName = ((ActionPara)para).getName().toString();
addAnnsToActionBranches (action, process);
if (!actionName.contains("Previous")) {
map = ultimateConstructFriendshipSets (action, process, actionName, spec);
System.out.println (PrinterUtil.printAction(action, spec));
System.out.println (FriendshipSets.printMap(map));
CircusAction cA = updatedParAction (action, process, map, ((ActionPara)para).getName().toString(), newParas, true, spec);
((ActionPara)para).setCircusAction(cA);
}
}
}
System.out.print("");
for (int i = 0; i < newParas.size(); i++) {
Para para = (Para) newParas.get(i);
if (para instanceof ActionPara) {
this.counterHash = 0;
CircusAction action = ((ActionPara)para).getCircusAction();
//String actionName = ((ActionPara)para).getName().toString();
if (action != null) {
/**
map = ultimateConstructFriendshipSets (action, process, actionName, spec);
CircusAction cA = updatedParAction (action, process, map, ((ActionPara)para).getName().toString(), f.createZParaList(), true, spec);
//if (action instanceof ParAction)
((ActionPara)para).setCircusAction(cA);
*/
newParas.set(i, para);
System.out.print ("");
}
}
}
((ZParaList)paraList).addAll(previousActionParas);
updateChannelDecls (processPara.getZName().toString(), paras, map);
//Atualiza os canais declarados na especificação.
}

private void updateChannelDecls (String proc, ZParaList paras, HashMap <String, FriendshipSets> map) {
Factory f = new Factory ();
Vector <String> allchannels = new Vector <String> ();
Vector <Expr> allexpressions = new Vector <Expr> ();
for (int i = 0; i < paras.size(); i++) {
Para para = paras.get(i);
if (para instanceof ChannelPara) {
ChannelPara para2 = (ChannelPara) para;
ZDeclList declList = para2.getZDeclList();
int size = declList.size();
Expr cDeclExpr = f.createRefExpr();
for (int j = 0; j < size; j++) {
ChannelDecl channelDecl2 = (ChannelDecl) declList.get(j);
cDeclExpr = channelDecl2.getExpr();
ZNameList genFormals = channelDecl2.getZGenFormals();
ZNameList channelNames = channelDecl2.getZChannelNameList();
declList.set(0, updateChannelDecl (map, f, cDeclExpr, channelDecl2));
System.out.print("");
}
this.prochid.put(proc, this.hid);
this.hid = new HiddenFromGUIInfo ();
para2.setDeclList(declList);
}
}
System.out.print("");
}
public void removeAnnsFromActionBranches (CircusAction action, /*boolean extOrIntChoice,*/ CircusProcess process) {
if (action instanceof PrefixingAction) {
action.getAnns().remove(new Integer (this.counterHash));
CircusAction action2 = ((PrefixingAction)action).getCircusAction();
removeAnnsFromActionBranches (action2, /*false,*/ process);
}
else if (action instanceof CallAction) {
action.getAnns().remove(new Integer (this.counterHash));
}
else if (action instanceof Action2) {
removeAnnsFromActionBranches (((Action2)action).getLeftAction(), /*false,*/ process);
removeAnnsFromActionBranches (((Action2)action).getRightAction(), /*false,*/ process);
}
}
public void addAnnsToActionBranches (CircusAction action, CircusProcess process) {
if (action instanceof PrefixingAction) {
action.getAnns().add(new Integer (this.counterHash));
CircusAction action2 = ((PrefixingAction)action).getCircusAction();
if (action2 instanceof ParAction)
this.counterHash++;
addAnnsToActionBranches (action2, process);
}
else if (action instanceof CallAction) {
action.getAnns().add(new Integer (this.counterHash));
}
else if (action instanceof ParAction) {
addAnnsToActionBranches (((ParAction)action).getLeftAction(), /*false,*/ process);
this.counterHash++;
addAnnsToActionBranches (((ParAction)action).getRightAction(), /*false,*/ process);
}
else if (action instanceof ExtChoiceAction || action instanceof IntChoiceAction) {
addAnnsToActionBranches (((Action2)action).getLeftAction(), /*true,*/ process);
addAnnsToActionBranches (((Action2)action).getRightAction(), /*true,*/ process);
}
else if (action instanceof Action2) {
addAnnsToActionBranches (((Action2)action).getLeftAction(), /*false,*/ process);
addAnnsToActionBranches (((Action2)action).getRightAction(), /*false,*/ process);
}
else if (action instanceof Action1) {
action.getAnns().add(new Integer (this.counterHash));
addAnnsToActionBranches (((Action1)action).getCircusAction(), /*false,*/ process);
}
else if (action instanceof CircusCommand) {
Factory f = new Factory ();
if (action instanceof IfGuardedCommand) {
IfGuardedCommand igc = (IfGuardedCommand) action;
CircusActionList cal = igc.getGuardedActionList();
int size = cal.size();
for (int i = 0; i < size; i++) {
GuardedAction ca = (GuardedAction) cal.get(i);
addAnnsToActionBranches (ca, process);
}
}
else if (action instanceof AssignmentCommand) {
//Não faz nada
}
else if (action instanceof VarDeclCommand) {
addAnnsToActionBranches (((VarDeclCommand)action).getCircusAction(), process);
}
else {
ExceptionUtil.throwImplementationException("ParallelismUpdater.addAnnsToActionBranches", action.getClass());
}
}
}
public HashMap <String, FriendshipSets> ultimateConstructFriendshipSets (CircusAction action, CircusProcess process, String actionParaName, Spec spec) {
return ultimateConstructFriendshipSets (action, process, actionParaName, new Vector <String> (), spec);
}

public HashMap <String, FriendshipSets> ultimateConstructFriendshipSets (CircusAction action, CircusProcess process, String actionParaName, Vector <String> mucalls, Spec spec) {
if (action instanceof PrefixingAction) {
HashMap <String, FriendshipSets> map = new HashMap <String, FriendshipSets> ();
Vector <String> visibleChannels = ChannelUtil.getVisibleChannels (action, process, actionParaName, mucalls, spec);
for (int i = 0; i < visibleChannels.size(); i++) {
FriendshipSets pfe = new FriendshipSets ();
HashSet <HashSet <Integer>> friendshipSets = new HashSet <HashSet <Integer>> ();
HashSet <Integer> fSet = new HashSet <Integer> ();
fSet.add(action.getAnn(Integer.class)); //Com counterHash = 0, o id da ação 0, e fSet fica com {0};
friendshipSets.add(fSet); //Para o caso acima, aqui fica friendshipSets = {{0}}
pfe.setFriendshipSets(friendshipSets);
map.put(visibleChannels.elementAt(i), pfe); //Para o canal visivel "a", aqui temos map = "a" --> {{0}}
}
return map;
}
else if (action instanceof ExtChoiceAction) {
HashMap <String, FriendshipSets> map =
ultimateConstructFriendshipSets (((ExtChoiceAction) action).getLeftAction(), process, actionParaName, mucalls, spec);
HashMap <String, FriendshipSets> mapRight =
ultimateConstructFriendshipSets (((ExtChoiceAction) action).getRightAction(), process, actionParaName, mucalls, spec);
map.putAll(mapRight);
return map;
}
else if (action instanceof IntChoiceAction) {
HashMap <String, FriendshipSets>
map = ultimateConstructFriendshipSets (((IntChoiceAction) action).getLeftAction(), process, actionParaName, mucalls, spec);
HashMap <String, FriendshipSets> mapRight =
ultimateConstructFriendshipSets (((IntChoiceAction) action).getRightAction(), process, actionParaName, mucalls, spec);
map.putAll(mapRight);
return map;
}
else if (action instanceof ParAction) { //TESTADO
HashMap <String, FriendshipSets> map = new HashMap <String, FriendshipSets> ();
Vector <String> channelSet = ChanSetUtil.channelSet(action, spec);
CircusAction leftAction;
CircusAction rightAction;
if (action instanceof ParallelAction) {
leftAction = ((ParallelAction)action).getLeftAction();
rightAction = ((ParallelAction)action).getRightAction();
}
else {
leftAction = ((InterleaveAction)action).getLeftAction();
rightAction = ((InterleaveAction)action).getRightAction();
}

Vector <String> leftVisible = ChannelUtil.getVisibleChannels (leftAction, process, actionParaName, mucalls, spec);
Vector <String> rightVisible = ChannelUtil.getVisibleChannels (rightAction, process, actionParaName, mucalls, spec);
Vector <String> alreadySeen = new Vector <String> ();
for (int i = 0; i < leftVisible.size(); i++) {
String chan = leftVisible.elementAt(i);
if (rightVisible.contains(chan) && !channelSet.contains(chan)) {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
HashMap <String, FriendshipSets> ucfsleft = ultimateConstructFriendshipSets (leftAction, process, actionParaName, mucalls, spec);
HashMap <String, FriendshipSets> ucfsright = ultimateConstructFriendshipSets (rightAction, process, actionParaName, mucalls, spec);
HashSet <HashSet <Integer>> leftSet =
ucfsleft.keySet().contains(chan)?
ucfsleft.get(chan).getFriendshipSets()
: new HashSet <HashSet <Integer>> ();
HashSet <HashSet <Integer>> rightSet =
ucfsright.keySet().contains(chan)? ucfsright.get(chan).getFriendshipSets() : new HashSet <HashSet <Integer>> ();
map.put(
chan,
new FriendshipSets (FriendshipSets.interleave (leftSet,rightSet))
);
}
}
else if (rightVisible.contains(chan) && channelSet.contains(chan)) {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
map.put(
chan,
new FriendshipSets (FriendshipSets.cartesianProduct (
ultimateConstructFriendshipSets (leftAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets(),
ultimateConstructFriendshipSets (rightAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets())));
}
}
else {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
map.put(
chan,
new FriendshipSets (ultimateConstructFriendshipSets (leftAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets())
);
}
}
}
for (int i = 0; i < rightVisible.size(); i++) {
String chan = rightVisible.elementAt(i);
if (leftVisible.contains(chan) && !channelSet.contains(chan)) {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
map.put(
chan,
new FriendshipSets (FriendshipSets.interleave (
ultimateConstructFriendshipSets (leftAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets(),
ultimateConstructFriendshipSets (rightAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets())));
}
}
else if (leftVisible.contains(chan) && channelSet.contains(chan)) {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
map.put(
chan,
new FriendshipSets (FriendshipSets.cartesianProduct (
ultimateConstructFriendshipSets (leftAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets(),
ultimateConstructFriendshipSets (rightAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets())));
}
}
else {
if (!alreadySeen.contains(chan)) {
alreadySeen.add(chan);
map.put(
chan,
new FriendshipSets (ultimateConstructFriendshipSets (rightAction, process, actionParaName, mucalls, spec).get(chan).getFriendshipSets())
);
}
}
}
return map;
}
else if (action instanceof SeqAction) {
HashMap <String, FriendshipSets> map = ultimateConstructFriendshipSets (((SeqAction) action).getLeftAction(), process, actionParaName, mucalls, spec);
HashMap <String, FriendshipSets> mapRight = ultimateConstructFriendshipSets (((SeqAction) action).getRightAction(), process, actionParaName, mucalls, spec);
map.putAll(mapRight);
return map;
}
else if (action instanceof CallAction) {
String newName = ((CallAction)action).getName().toString();
if (mucalls.contains(newName)) {
return new HashMap <String, FriendshipSets> ();
}
if (newName.equals(actionParaName)) {
return new HashMap <String, FriendshipSets> ();
}
/*HashMap <String, Integer> callsmap = CallUtil.calls (action, process, spec);
if (callsmap.keySet().contains(newName)) {
return new HashMap <String, FriendshipSets> ();
}*/
CircusAction action2 = CallUtil.getContentOfCallAction (((CallAction)action), process, spec);
HashMap <String, FriendshipSets> map = ultimateConstructFriendshipSets (action2, process, actionParaName, mucalls, spec);
return map;
}
else if (action instanceof Action2) {
HashMap <String, FriendshipSets> map = ultimateConstructFriendshipSets (((Action2) action).getLeftAction(), process, actionParaName, mucalls, spec);
HashMap <String, FriendshipSets> mapRight = ultimateConstructFriendshipSets (((Action2) action).getRightAction(), process, actionParaName, mucalls, spec);
map.putAll(mapRight);
return map;
}
/*else if (action instanceof Action1) { //TODO N�O TESTADO
return ultimateConstructFriendshipSets (((Action1)action).getCircusAction(), process, actionParaName);
}*/
else if (action instanceof GuardedAction) {
return ultimateConstructFriendshipSets (((GuardedAction)action).getCircusAction(), process, actionParaName, mucalls, spec);
}
else if (action instanceof MuAction) {
String muname = ((MuAction)action).getZName().toString();
mucalls.addElement(muname);
CircusAction action2 = ((MuAction)action).getCircusAction();
return ultimateConstructFriendshipSets (action2/*((MuAction)action).getCircusAction()*/, process, actionParaName, mucalls, spec);
}
else if (action instanceof HideAction) {
return ultimateConstructFriendshipSets (((HideAction)action).getCircusAction(), process, actionParaName, mucalls, spec);
}
else if (action instanceof Action1) {
return ultimateConstructFriendshipSets (((Action1)action).getCircusAction(), process, actionParaName, mucalls, spec);
}
else if (action instanceof CircusCommand) {
if (action instanceof AssignmentCommand) {
return new HashMap <String, FriendshipSets> ();
}
else if (action instanceof IfGuardedCommand) {
FrontEndCounter fec = new FrontEndCounter ();
IfGuardedCommand igc = (IfGuardedCommand)action;
CircusActionList cal = igc.getGuardedActionList();
HashMap <String, FriendshipSets> mapp = new HashMap <String, FriendshipSets> ();
for (int i = 0; i < cal.size(); i++) {
GuardedAction ga = (GuardedAction) cal.get(i);
HashMap <String, FriendshipSets> map = ultimateConstructFriendshipSets ((GuardedAction) ga, process, actionParaName, mucalls, spec);
mapp.putAll(map);
}
return mapp;
}
else if (action instanceof VarDeclCommand) {
return ultimateConstructFriendshipSets (((VarDeclCommand)action).getCircusAction(), process, actionParaName, mucalls, spec);
}
/*else if (...){
//TODO ALGO MAIS?
}*/
else {
ExceptionUtil.throwImplementationException("ParallelismUpdater.ultimateConstructFriendshipSets", action.getClass());
return new HashMap <String, FriendshipSets> ();
}
}
else /*if (action instanceof SkipAction)*/ {
return new HashMap <String, FriendshipSets> ();
}
}
public static Integer [] indFromTo (int x, int y, Integer [] indexes) {
int r1 = x, r2 = y - x + 1, counter = 0;
Integer [] z = new Integer [r2];
for (int i = r1; i < r2; i++) {
z[i] = indexes [counter];
counter++;
}
return z;
}
public static PrefixingAction prefixingActionWithRenamedComm (PrefixingAction pa, int index, Integer [] indexes, CircusAction action, CircusProcess process, HashMap <String, FriendshipSets> spfemap, String actionParaName, ZParaList paraList, boolean rename, Spec spec) {
String name = pa.getCommunication().getChannelExpr().getName().toString();
if (spfemap.get(name).getFriendshipSets().size() > 1 && rename) {
return RenamingUtil.prefixingActionWithRenamedComm(pa, name + indexes [index], action, process, spfemap, actionParaName, paraList, rename, spec);
}
else
return RenamingUtil.prefixingActionWithRenamedComm(pa, name, action, process, spfemap, actionParaName, paraList, rename, spec);
}

public static CircusAction prefActToExtChoiceActWithRenamedComms (PrefixingAction pa, Integer [] indexes,
/*Daqui para diante eh apenas para colocar como parâmetro de updatedParAction*/
CircusAction action, CircusProcess process, HashMap <String, FriendshipSets> spfemap,
String actionParaName, ZParaList paraList, boolean rename, Spec spec
) {
int length = (indexes == null? 0 : indexes.length);
if (length == 1) {
return prefixingActionWithRenamedComm (pa, 0, indexes, action, process, spfemap, actionParaName, paraList, rename, spec);
}
if (length == 0) {
return pa;
}
else {
Factory f = new Factory ();
ExtChoiceActionImpl eca = (ExtChoiceActionImpl) f.createExtChoiceAction();
eca.setLeftAction (prefActToExtChoiceActWithRenamedComms (pa, indFromTo (0, length - 2, indexes), action, process, spfemap, actionParaName, paraList, rename, spec)); //-2 porque ele exclui o ultimo do array, que tem indice "length - 1".
eca.setRightAction (prefixingActionWithRenamedComm (pa, length - 1, indexes, action, process, spfemap, actionParaName, paraList, rename, spec));
return eca;
}
}
public static void addActionParaToProcess (ActionPara para, ZParaList paraList) {
List actionParas = null;
paraList.add(para);
/*if (process instanceof BasicProcess) {
actionParas = (List) ((BasicProcess)process).getZParaList();
actionParas.add(para);
((BasicProcess)process).setParaList((ParaList)actionParas);
}
if (process instanceof ParamProcess) { //TODO BLOCO N�O TESTADO
actionParas = (List) ((ParamProcess)process).getCircusBasicProcess().getZParaList(); //TODO falta testar esta linha
actionParas.add(para);
((ParamProcess)process).getCircusBasicProcess().setParaList((ParaList)actionParas);
}*/
}
public static CircusCommunicationList listOfRenamedComms (Communication communication, HashMap <String, FriendshipSets> spfemap) {
Factory f = new Factory ();
CircusCommunicationList ccl = f.createCircusCommunicationList();
int fssize = 0;
if (spfemap.containsKey(communication.getChannelExpr().getName().toString()))
fssize = spfemap.get(communication.getChannelExpr().getName().toString()).friendshipSets.size();
int size = ccl.size();
for (int i = 0; i < fssize; i++) {
Communication c = f.createCommunication(
f.createRefExpr(f.createZName(communication.getChannelExpr().getName().toString() + (fssize > 1? i : ""))),
f.createCircusFieldList(communication.getCircusFieldList()),
communication.getCommUsage(),
communication.getCommPattern(),
communication.getMultiSych(),
communication.getIndexed()
);
ccl.add(c);
}
return ccl;
}

public static void updateChannelSet (CircusAction action, HashMap <String, FriendshipSets> spfemap) {
if (action instanceof ParallelAction) {
CircusChannelSet channelSet = (CircusChannelSet)((ParallelAction)action).getChannelSet();
Expr channelExpr = channelSet.getExpr();
Factory f = new Factory ();
FactoryUtil pf = new FactoryUtil ();
if (channelExpr instanceof BasicChannelSetExpr) {
CircusCommunicationList ccl = ((BasicChannelSetExpr)channelExpr).getCircusCommunicationList();
CircusCommunicationList ccl2 = f.createCircusCommunicationList();
int size = ccl.size();
for (int i = 0; i < size; i++) {
Communication c = pf.createCommunication (ccl.get(i));
ccl2.addAll(listOfRenamedComms (c, spfemap));
}
((BasicChannelSetExpr)((CircusChannelSet)((ParallelAction)action).getChannelSet()).getExpr()).setCommunicationList(ccl2);
}
//updateChannelSet (((ParallelAction)action).getLeftAction(), spfemap);
//updateChannelSet (((ParallelAction)action).getRightAction(), spfemap);
}
/*Object [] keys = spfemap.keySet().toArray();
for (int i = 0; i < keys.length; i++) {
int fslength = spfemap.get((String)keys [i]).friendshipSets.size();
}*/
}
public static CircusAction updatedParAction (CircusAction circusaction, CircusProcess process, HashMap <String, FriendshipSets> spfemap, String actionParaName, ZParaList paraList, boolean rename, Spec spec) {
FactoryUtil fu = new FactoryUtil ();
Factory f = new Factory ();
//SeqAction seq = f.createSeqAction();
CircusAction action = fu.createCircusAction (circusaction);
if (action instanceof PrefixingAction) {
int index = 0;
if (action.getAnn(Integer.class) != null)
index = action.getAnn(Integer.class);
Communication c = ((PrefixingAction)action).getCommunication();
CircusAction ca = ((PrefixingAction)action).getCircusAction();
HashMap <String, Integer []> mapstrint = FriendshipSets.renamingIndexes(spfemap, index);
String commName = c.getChannelExpr().getName().toString();
Integer [] indexes = mapstrint.get(commName);

CircusAction finalcircusaction = prefActToExtChoiceActWithRenamedComms ((PrefixingAction)action, indexes, action, process, spfemap, actionParaName, paraList, rename, spec);
return finalcircusaction;
}
else if (action instanceof ExtChoiceAction) { //CASO TESTADO, E FUNCIONANDO
ExtChoiceAction eca = f.createExtChoiceAction();
eca.getAnns().addAll(action.getAnns());
eca.setLeftAction (updatedParAction (((ExtChoiceAction)action).getLeftAction(), process, spfemap, actionParaName, paraList, rename, spec));
eca.setRightAction (updatedParAction (((ExtChoiceAction)action).getRightAction(), process, spfemap, actionParaName, paraList, rename, spec));
return eca;
}
else if (action instanceof IntChoiceAction) { //AN�LOGO AO DE CIMA, PORTANTO TAMB�M EST� FUNCIONANDO
IntChoiceAction ica = f.createIntChoiceAction();
ica.getAnns().addAll(action.getAnns());
ica.setLeftAction (updatedParAction (((IntChoiceAction)action).getLeftAction(), process, spfemap, actionParaName, paraList, rename, spec));
ica.setRightAction (updatedParAction (((IntChoiceAction)action).getRightAction(), process, spfemap, actionParaName, paraList, rename, spec));
return ica;
}
else if (action instanceof ParallelAction) { //TESTADO
ParallelAction pa = f.createParallelAction();
pa.getAnns().addAll(action.getAnns());
pa.setLeftAction (updatedParAction (((ParallelAction)action).getLeftAction(), process, spfemap, actionParaName, paraList, rename, spec));
pa.setRightAction (updatedParAction (((ParallelAction)action).getRightAction(), process, spfemap, actionParaName, paraList, rename, spec));
Vector <String> visibleChannels = ChannelUtil.getVisibleChannels (action/*pa*/, process, actionParaName, spec);
pa.setChannelSet(((ParallelAction)action).getChannelSet());
pa.setLeftNameSet(((ParallelAction)action).getLeftNameSet());
pa.setRightNameSet(((ParallelAction)action).getRightNameSet());
updateChannelSet (pa, spfemap);
//JOptionPane.showMessageDialog (null, "I am at ParallelismVisitor, line 879. Action == " + ParallelismPrinter.printAction (pa));
return pa;
}
else if (action instanceof InterleaveAction) { //TESTADO
InterleaveAction ia = f.createInterleaveAction();
ia.getAnns().addAll(action.getAnns());
ia.setLeftAction (updatedParAction (((InterleaveAction)action).getLeftAction(), process, spfemap, actionParaName, paraList, rename, spec));
ia.setRightAction (updatedParAction (((InterleaveAction)action).getRightAction(), process, spfemap, actionParaName, paraList, rename, spec));
ia.setLeftNameSet(((InterleaveAction)action).getLeftNameSet());
ia.setRightNameSet(((InterleaveAction)action).getRightNameSet());
return ia;
}
else if (action instanceof SeqAction) { //TESTADO
SeqAction sa = f.createSeqAction();
sa.getAnns().addAll(action.getAnns());
sa.setLeftAction (updatedParAction (((SeqAction)action).getLeftAction(), process, spfemap, actionParaName, paraList, rename, spec));
sa.setRightAction (updatedParAction (((SeqAction)action).getRightAction(), process, spfemap, actionParaName, paraList, rename, spec));
return sa;
}
else if (action instanceof CallAction) { //TESTADO
CallAction actionLinha = f.createCallAction();
String actionParaName2 = actionParaName.contains("mainAction")? "MainAction" : actionParaName;
String actionLinhaName = ((CallAction)action).getName().toString();// + actionParaName2 + action.getAnn(Integer.class);
actionLinha.setName(f.createZName(actionLinhaName));
actionLinha.setExprList(f.createZExprList());
CircusAction contentOfActionLinha = CallUtil.getContentOfCallAction ((CallAction)action, process, spec);
ActionPara paraLinha = f.createActionPara();
paraLinha.setName(f.createZName (actionLinhaName));
paraLinha.setCircusAction(contentOfActionLinha);
addActionParaToProcess (paraLinha, paraList); //TESTADO
return actionLinha;
}
else if (action instanceof GuardedAction) { //TODO NAO TESTADO
GuardedAction ga = f.createGuardedAction();
ga.setPred(((GuardedAction)action).getPred());
ga.setCircusAction(updatedParAction (((GuardedAction)action).getCircusAction(), process, spfemap, actionParaName, paraList, rename, spec));
return ga;
}
else if (action instanceof HideAction) { //TODO OBS: QUANDO E SE O HIDING FOR IMPLEMENTADO, ESTA LINHA TAMBÉM TERÁ QUE ATUALIZAR O CHANNELSET DA HIDEACTION
return updatedParAction (((HideAction)action).getCircusAction(), process, spfemap, actionParaName, paraList, rename, spec);
}
else if (action instanceof SkipAction) {
SkipAction skp = f.createSkipAction();
skp.getAnns().addAll(action.getAnns());
return skp;
}
else if (action instanceof ChaosAction) {
ChaosAction skp = f.createChaosAction();
skp.getAnns().addAll(action.getAnns());
return skp;
}
else if (action instanceof MuAction) {
MuAction mu = f.createMuAction();
mu.setName(((MuAction)action).getName());
mu.setCircusAction (
updatedParAction (((MuAction)action).getCircusAction(), process, spfemap, actionParaName, paraList, rename, spec)
//((MuAction)action).getCircusAction()
);
return mu;
}
else if (action instanceof CircusCommand) {
if (action instanceof AssignmentCommand) {
return action;
}
else if (action instanceof IfGuardedCommand) {
IfGuardedCommand newigc = f.createIfGuardedCommand();
IfGuardedCommand igc = (IfGuardedCommand) action;
CircusActionList cal = igc.getGuardedActionList();
CircusActionList newcal = f.createCircusActionList();
//newcal.add(e)
int size = cal.size();
for (int i = 0; i < size; i++) {
GuardedAction ca = (GuardedAction) cal.get(i);
GuardedAction newca = f.createGuardedAction();
newca.setPred(ca.getPred());
newca.setCircusAction(updatedParAction (ca, process, spfemap, actionParaName, paraList, rename, spec));
newcal.add(newca);
}
newigc.setActionList(newcal);
return newigc;
}
else if (action instanceof VarDeclCommand) {
VarDeclCommand vdc = f.createVarDeclCommand ();
vdc.setDeclList(((VarDeclCommand)action).getZDeclList());
vdc.setCircusAction(updatedParAction(((VarDeclCommand)action).getCircusAction(), process, spfemap, actionParaName, paraList, rename, spec));
return vdc;
}
else {
ExceptionUtil.throwImplementationException("ParallelismUpdater.updatedParAction", action.getClass());
return action;
}
}
else if (action instanceof ParamAction) {
ParamAction pa = f.createParamAction ();
pa.setDeclList(((ParamAction)action).getZDeclList());
pa.setCircusAction(updatedParAction(((ParamAction)action).getCircusAction(), process, spfemap, actionParaName, paraList, rename, spec));
return pa;
}
else {
ExceptionUtil.throwImplementationException("ParallelismUpdater.updatedParAction", action.getClass());
if (action != null) {
StopAction stp = f.createStopAction();
stp.getAnns().addAll(action.getAnns());
return stp;
}
else {
return action;
}
}
}
}
/*else if (action instanceof ExtChoiceActionIte) {
ExtChoiceActionIte ecaIte = f.createExtChoiceActionIte();
ecaIte.setDeclList(f.createZDeclList());
ZDeclList list = ((ExtChoiceActionIte)action).getZDeclList();
for (int i = 0; i < list.size(); i++) {
ecaIte.getZDeclList().add(sequencedAction (list.get(i)));
}
return ecaIte;
}
else if (action instanceof IntChoiceActionIte) {
IntChoiceActionIte icaIte = f.createIntChoiceActionIte();
icaIte.setDeclList(((IntChoiceActionIte)action).getZDeclList()); //TODO ainda n�o sei se � assim
return icaIte;
}
else if (action instanceof ParallelActionIte) { //TODO n�o testado
ParallelActionIte paIte = f.createParallelActionIte();
return paIte;
}
else if (action instanceof InterleaveActionIte) { //TODO n�o testado
InterleaveActionIte iaIte = f.createInterleaveActionIte();

return iaIte;
}
else if (action instanceof SeqActionIte) { //TODO n�o testado
SeqActionIte saIte = f.createSeqActionIte();

return saIte;
}*/
//f.createHideAction()