|
19 | 19 | import org.eclipse.emf.ecore.util.EcoreUtil;
|
20 | 20 |
|
21 | 21 | import fr.lip6.move.gal.Abort;
|
| 22 | +import fr.lip6.move.gal.AliasDeclaration; |
22 | 23 | import fr.lip6.move.gal.AssignType;
|
23 | 24 | import fr.lip6.move.gal.CompositeTypeDeclaration;
|
24 | 25 | import fr.lip6.move.gal.InstanceCall;
|
@@ -68,6 +69,9 @@ private static Logger getLog() {
|
68 | 69 | public static Support simplify(Specification spec) {
|
69 | 70 | long debut = System.currentTimeMillis();
|
70 | 71 |
|
| 72 | + |
| 73 | + replaceAlias(spec); |
| 74 | + |
71 | 75 | Set <GALTypeDeclaration> torem = new HashSet<GALTypeDeclaration>();
|
72 | 76 | Map<GALTypeDeclaration, Set<String>> trueLabs = new HashMap<GALTypeDeclaration,Set<String>>();
|
73 | 77 | Support toret = new Support();
|
@@ -198,6 +202,78 @@ public static <T> void retainAll ( List<T> container, Set<? extends T> tokeep )
|
198 | 202 | }
|
199 | 203 | }
|
200 | 204 |
|
| 205 | + private static int replaceAlias(Specification spec) { |
| 206 | + boolean doit = false; |
| 207 | + for (TypeDeclaration td : spec.getTypes()) { |
| 208 | + if (td instanceof GALTypeDeclaration) { |
| 209 | + GALTypeDeclaration gal = (GALTypeDeclaration) td; |
| 210 | + if (! gal.getAlias().isEmpty()) { |
| 211 | + doit = true; |
| 212 | + break; |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + if (!doit) return 0; |
| 217 | + |
| 218 | + int nbsub = 0; |
| 219 | + for (TreeIterator<EObject> it = spec.eAllContents() ; it.hasNext() ; ) { |
| 220 | + EObject obj = it.next(); |
| 221 | + if (obj instanceof VariableReference) { |
| 222 | + VariableReference ref = (VariableReference) obj; |
| 223 | + if (ref.getRef() instanceof AliasDeclaration) { |
| 224 | + AliasDeclaration alias = (AliasDeclaration) ref.getRef(); |
| 225 | + EObject par = obj.eContainer(); |
| 226 | + QualifiedReference qref = null; |
| 227 | + while (par instanceof QualifiedReference) { |
| 228 | + QualifiedReference parent = (QualifiedReference) par; |
| 229 | + QualifiedReference tmp = GalFactory.eINSTANCE.createQualifiedReference(); |
| 230 | + tmp.setQualifier(EcoreUtil.copy(parent.getQualifier())); |
| 231 | + tmp.setNext(qref); |
| 232 | + qref = tmp; |
| 233 | + par = par.eContainer(); |
| 234 | + } |
| 235 | + IntExpression expr = EcoreUtil.copy(alias.getExpr()); |
| 236 | + |
| 237 | + if (qref != null) { |
| 238 | + // now qualify all variables in the alias. |
| 239 | + for (TreeIterator<EObject> jt = expr.eAllContents() ; jt.hasNext() ; ) { |
| 240 | + EObject o = jt.next(); |
| 241 | + if (o instanceof VariableReference) { |
| 242 | + VariableReference vref = (VariableReference) o; |
| 243 | + QualifiedReference q = EcoreUtil.copy(qref); |
| 244 | + QualifiedReference qq = q; |
| 245 | + while (qq.getNext() != null) { |
| 246 | + qq = (QualifiedReference) qq.getNext(); |
| 247 | + } |
| 248 | + qq.setNext(EcoreUtil.copy(vref)); |
| 249 | + EcoreUtil.replace(o, q); |
| 250 | + jt.prune(); |
| 251 | + } |
| 252 | + } |
| 253 | + EObject torep = obj.eContainer(); |
| 254 | + while (torep.eContainer() instanceof QualifiedReference) { |
| 255 | + torep = torep.eContainer(); |
| 256 | + } |
| 257 | + EcoreUtil.replace(torep, expr); |
| 258 | + } else { |
| 259 | + EcoreUtil.replace(obj, expr); |
| 260 | + } |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + it.prune(); |
| 265 | + nbsub++; |
| 266 | + } |
| 267 | + } |
| 268 | + } |
| 269 | + for (TypeDeclaration td : spec.getTypes()) { |
| 270 | + if (td instanceof GALTypeDeclaration) { |
| 271 | + GALTypeDeclaration gal = (GALTypeDeclaration) td; |
| 272 | + gal.getAlias().clear(); |
| 273 | + } |
| 274 | + } |
| 275 | + return nbsub; |
| 276 | + } |
201 | 277 |
|
202 | 278 | public static void removeUncalledTransitions(Specification spec) {
|
203 | 279 | Map<TypeDeclaration, Set<String>> tokeep = new HashMap< TypeDeclaration, Set<String> > ();
|
|
0 commit comments