Skip to content

Commit 6d9a6ec

Browse files
committed
deal with Alias at Specification level => in properties #16
1 parent c3d9d56 commit 6d9a6ec

File tree

2 files changed

+78
-25
lines changed

2 files changed

+78
-25
lines changed

Diff for: fr.lip6.move.gal/src/fr/lip6/move/gal/instantiate/Instantiator.java

+2-25
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {
410410
//first substitute const param by value
411411
// replace all parameters by values
412412
int nbsub = replaceConstParam(type);
413-
nbsub += replaceAlias(type);
413+
414414
if (nbsub > 0) {
415415
Simplifier.simplifyAllExpressions(type);
416416
}
@@ -442,30 +442,7 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {
442442

443443

444444
}
445-
446-
private static int replaceAlias(TypeDeclaration type) {
447-
int nbsub = 0;
448-
if (type instanceof GALTypeDeclaration) {
449-
GALTypeDeclaration gal = (GALTypeDeclaration) type;
450-
if (! gal.getAlias().isEmpty()) {
451-
for (TreeIterator<EObject> it = gal.eAllContents() ; it.hasNext() ; ) {
452-
EObject obj = it.next();
453-
if (obj instanceof VariableReference) {
454-
VariableReference ref = (VariableReference) obj;
455-
if (ref.getRef() instanceof AliasDeclaration) {
456-
AliasDeclaration alias = (AliasDeclaration) ref.getRef();
457-
EcoreUtil.replace(obj, EcoreUtil.copy(alias.getExpr()));
458-
it.prune();
459-
nbsub++;
460-
}
461-
}
462-
}
463-
gal.getAlias().clear();
464-
}
465-
}
466-
return nbsub;
467-
}
468-
445+
469446
private static int replaceConstParam(EObject parent) {
470447
int nbsub = 0;
471448
for (TreeIterator<EObject> it = parent.eAllContents() ; it.hasNext() ; ) {

Diff for: fr.lip6.move.gal/src/fr/lip6/move/gal/instantiate/Simplifier.java

+76
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.emf.ecore.util.EcoreUtil;
2020

2121
import fr.lip6.move.gal.Abort;
22+
import fr.lip6.move.gal.AliasDeclaration;
2223
import fr.lip6.move.gal.AssignType;
2324
import fr.lip6.move.gal.CompositeTypeDeclaration;
2425
import fr.lip6.move.gal.InstanceCall;
@@ -68,6 +69,9 @@ private static Logger getLog() {
6869
public static Support simplify(Specification spec) {
6970
long debut = System.currentTimeMillis();
7071

72+
73+
replaceAlias(spec);
74+
7175
Set <GALTypeDeclaration> torem = new HashSet<GALTypeDeclaration>();
7276
Map<GALTypeDeclaration, Set<String>> trueLabs = new HashMap<GALTypeDeclaration,Set<String>>();
7377
Support toret = new Support();
@@ -198,6 +202,78 @@ public static <T> void retainAll ( List<T> container, Set<? extends T> tokeep )
198202
}
199203
}
200204

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+
}
201277

202278
public static void removeUncalledTransitions(Specification spec) {
203279
Map<TypeDeclaration, Set<String>> tokeep = new HashMap< TypeDeclaration, Set<String> > ();

0 commit comments

Comments
 (0)