Blame view
circus/src/jcircus/newutil/ChanSetUtil.java
9.36 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 |
package jcircus.newutil; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Vector; //import jcircus.complementaryenvs.ChanSetOfProcessIdSetsEnv; import jcircus.complementaryenvs.ProcProcessParaEnv; import jcircus.environment.ChanInfoEnv; import jcircus.environment.ProcChanUseEnv; import jcircus.util.Util; import net.sourceforge.czt.circus.ast.Action2; import net.sourceforge.czt.circus.ast.ActionPara; 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.ChannelSetPara; import net.sourceforge.czt.circus.ast.CircusAction; import net.sourceforge.czt.circus.ast.CircusChannelSet; import net.sourceforge.czt.circus.ast.CircusCommunicationList; 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.CommunicationList; import net.sourceforge.czt.circus.ast.ExtChoiceProcess; import net.sourceforge.czt.circus.ast.IntChoiceProcess; import net.sourceforge.czt.circus.ast.ParAction; import net.sourceforge.czt.circus.ast.ExtChoiceAction; import net.sourceforge.czt.circus.ast.IntChoiceAction; import net.sourceforge.czt.circus.ast.ParallelAction; import net.sourceforge.czt.circus.ast.ParallelProcess; import net.sourceforge.czt.circus.ast.ParamProcess; import net.sourceforge.czt.circus.ast.PrefixingAction; import net.sourceforge.czt.circus.ast.Communication; import net.sourceforge.czt.circus.ast.InterleaveAction; import net.sourceforge.czt.circus.ast.ProcessPara; import net.sourceforge.czt.circus.util.Factory; import net.sourceforge.czt.z.ast.Expr; import net.sourceforge.czt.z.ast.Expr0N; import net.sourceforge.czt.z.ast.NarrSect; 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.ZExprList; import net.sourceforge.czt.z.ast.ZParaList; import net.sourceforge.czt.z.ast.ZSect; public class ChanSetUtil { public static boolean isOnChannelSet (String channel, CircusAction action, Spec spec) { if ((channelSet (action, spec)).contains(channel)) { return true; } return false; } public static boolean isOnChannelSet (String channel, CircusProcess process, Spec spec) { if ((channelSet(process, spec)).contains(channel)) { return true; } return false; } private static Vector <String> getChannelNames (ChannelSetPara csp, ZParaList paralist) { Vector <String> channelNames = new Vector <String> (); CircusChannelSet ccs = (CircusChannelSet) csp.getChannelSet(); Expr expr = ccs.getExpr(); if (expr instanceof BasicChannelSetExpr) { Vector <String> channelnames = new Vector <String> (); CommunicationList commlist = (((BasicChannelSetExpr)expr).getCommunicationList()); int size = commlist.getChildren().length; for (int i = 0; i < size; i++) { channelnames.addElement (((Communication)commlist.getChildren() [i]).getChannelExpr().getZName().toString()); } return channelnames; } else if (expr instanceof RefExpr) { boolean aux = false; Vector <String> channelnames = new Vector <String> (); String name = ((RefExpr)expr).getZName().toString(); int size = paralist.size(); for (int i = 0; i < size; i++) { Para para = paralist.get(i); if (para instanceof ChannelSetPara) { String paraname = ((ChannelSetPara)para).getZName().toString(); if (para.equals(paraname)) { aux = true; channelnames.addAll (getChannelNames ((ChannelSetPara)para, paralist)); } } } if (!aux) { ExceptionUtil.throwException("The channel set paragraph " + name + " was not found..."); } return channelnames; } else { ExceptionUtil.throwImplementationException("ChanSetUtil.getChannelNames", expr.getClass()); return new Vector <String> (); } //CommunicationList commList = ((BasicChannelSetExpr)((CircusChannelSet)(((ParallelAction)action).getChannelSet())).getExpr()).getCommunicationList(); //int commListLength = commList.getChildren().length; //for (int i = 0; i < commListLength; i++) { // vec.addElement (((Communication)commList.getChildren() [i]).getChannelExpr().getZName().toString()); //} } private static HashMap <String, Vector <String>> mapNameToChannelSet (Spec spec) { HashMap <String, Vector <String>> map = new HashMap <String, Vector <String>> (); 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(); int size = paras.size(); for (int i = 0; i < size; i++) { Para para = paras.get(i); if (para instanceof ChannelSetPara) { ChannelSetPara csp = (ChannelSetPara)para; String csname = csp.getZName().toString(); map.put(csname, getChannelNames (csp, paras)); } } return map; } /*private static CommunicationList communications (Expr expr) { if (expr instanceof BasicChannelSetExpr) { } }*/ public static Vector <String> channelSet (CircusAction action, Spec spec) { Vector <String> vec = new Vector <String> (); if (action instanceof ParallelAction) { Expr channelexpr = ((CircusChannelSet)(((ParallelAction)action).getChannelSet())).getExpr(); if (channelexpr instanceof BasicChannelSetExpr) { CommunicationList commList = ((BasicChannelSetExpr)channelexpr).getCommunicationList(); //CommunicationList commList = ((BasicChannelSetExpr)((CircusChannelSet)(((ParallelAction)action).getChannelSet())).getExpr()).getCommunicationList(); int commListLength = commList.getChildren().length; for (int i = 0; i < commListLength; i++) { vec.addElement (((Communication)commList.getChildren() [i]).getChannelExpr().getZName().toString()); } return vec; } else if (channelexpr instanceof RefExpr) { String name = ((RefExpr)channelexpr).getZName().toString(); HashMap <String, Vector <String>> map = mapNameToChannelSet (spec); Vector <String> channelset = map.get(name); return channelset; } else { ExceptionUtil.throwImplementationException("ChanSetUtil.channelSet", channelexpr.getClass()); } } return vec; } /*public static void setActChannelSet (Vector <String> channelSet, CircusAction action) { if (action instanceof ParallelAction) { Factory f = new Factory (); CircusChannelSet circusChannelSet = f.createCircusChannelSet(); BasicChannelSetExpr bcse = f.createBasicChannelSetExpr(); CircusCommunicationList cl = f.createCircusCommunicationList(); for (int i = 0; i < channelSet.size(); i++) { Communication c = f.createCommunication( f.createRefExpr(f.createZName(channelSet.elementAt(i))), f.createCircusFieldList(), CommUsage.Normal,//OBS: Aqui n�o necessariamente � normal... Pode ser generic tbm, mas para a gente, n�o far� diferen�a, pois o que interessa � o nome do canal //c.getCommUsage(), CommPattern.Synch,//OBS: Idem para c�. � indiferente o CommPattern, s� interessa o nome do canal //c.getCommPattern(), new BigInteger ("0"), //OBS: � irrelevante aqui o valor do BigInteger //c.getMultiSych(), false //OBS: Irrelevante se � true ou false c.getIndexed() ); cl.add(c); } bcse.setCommunicationList(cl); circusChannelSet.setExpr(bcse); ((ParallelAction)action).setChannelSet (circusChannelSet); } }*/ public static Vector <String> channelSet (CircusProcess process, Spec spec) { Vector <String> vec = new Vector <String> (); if (process instanceof ParallelProcess) { Expr channelexpr = ((CircusChannelSet)(((ParallelProcess)process).getChannelSet())).getExpr(); if (channelexpr instanceof BasicChannelSetExpr) { CommunicationList commList = ((BasicChannelSetExpr)channelexpr).getCommunicationList(); //CommunicationList commList = ((BasicChannelSetExpr)((CircusChannelSet)(((ParallelAction)action).getChannelSet())).getExpr()).getCommunicationList(); int commListLength = commList.getChildren().length; for (int i = 0; i < commListLength; i++) { vec.addElement (((Communication)commList.getChildren() [i]).getChannelExpr().getZName().toString()); } return vec; } else if (channelexpr instanceof RefExpr) { String name = ((RefExpr)channelexpr).getZName().toString(); HashMap <String, Vector <String>> map = mapNameToChannelSet (spec); Vector <String> channelset = map.get(name); return channelset; } else { ExceptionUtil.throwImplementationException("ChanSetUtil.channelSet", channelexpr.getClass()); } } return vec; /*if (process instanceof ParallelProcess) { CommunicationList commList = ((BasicChannelSetExpr)((CircusChannelSet)(((ParallelProcess)process).getChannelSet())).getExpr()).getCommunicationList(); int commListLength = commList.getChildren().length; for (int i = 0; i < commListLength; i++) { vec.addElement (((Communication)commList.getChildren() [i]).getChannelExpr().getZName().toString()); } }*/ } } |