Skip to content

Commit

Permalink
deal with Alias at Specification level => in properties #16
Browse files Browse the repository at this point in the history
  • Loading branch information
yanntm committed Jul 23, 2019
1 parent c3d9d56 commit 6d9a6ec
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {
//first substitute const param by value
// replace all parameters by values
int nbsub = replaceConstParam(type);
nbsub += replaceAlias(type);

if (nbsub > 0) {
Simplifier.simplifyAllExpressions(type);
}
Expand Down Expand Up @@ -442,30 +442,7 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {


}

private static int replaceAlias(TypeDeclaration type) {
int nbsub = 0;
if (type instanceof GALTypeDeclaration) {
GALTypeDeclaration gal = (GALTypeDeclaration) type;
if (! gal.getAlias().isEmpty()) {
for (TreeIterator<EObject> it = gal.eAllContents() ; it.hasNext() ; ) {
EObject obj = it.next();
if (obj instanceof VariableReference) {
VariableReference ref = (VariableReference) obj;
if (ref.getRef() instanceof AliasDeclaration) {
AliasDeclaration alias = (AliasDeclaration) ref.getRef();
EcoreUtil.replace(obj, EcoreUtil.copy(alias.getExpr()));
it.prune();
nbsub++;
}
}
}
gal.getAlias().clear();
}
}
return nbsub;
}


private static int replaceConstParam(EObject parent) {
int nbsub = 0;
for (TreeIterator<EObject> it = parent.eAllContents() ; it.hasNext() ; ) {
Expand Down
76 changes: 76 additions & 0 deletions fr.lip6.move.gal/src/fr/lip6/move/gal/instantiate/Simplifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;

import fr.lip6.move.gal.Abort;
import fr.lip6.move.gal.AliasDeclaration;
import fr.lip6.move.gal.AssignType;
import fr.lip6.move.gal.CompositeTypeDeclaration;
import fr.lip6.move.gal.InstanceCall;
Expand Down Expand Up @@ -68,6 +69,9 @@ private static Logger getLog() {
public static Support simplify(Specification spec) {
long debut = System.currentTimeMillis();


replaceAlias(spec);

Set <GALTypeDeclaration> torem = new HashSet<GALTypeDeclaration>();
Map<GALTypeDeclaration, Set<String>> trueLabs = new HashMap<GALTypeDeclaration,Set<String>>();
Support toret = new Support();
Expand Down Expand Up @@ -198,6 +202,78 @@ public static <T> void retainAll ( List<T> container, Set<? extends T> tokeep )
}
}

private static int replaceAlias(Specification spec) {
boolean doit = false;
for (TypeDeclaration td : spec.getTypes()) {
if (td instanceof GALTypeDeclaration) {
GALTypeDeclaration gal = (GALTypeDeclaration) td;
if (! gal.getAlias().isEmpty()) {
doit = true;
break;
}
}
}
if (!doit) return 0;

int nbsub = 0;
for (TreeIterator<EObject> it = spec.eAllContents() ; it.hasNext() ; ) {
EObject obj = it.next();
if (obj instanceof VariableReference) {
VariableReference ref = (VariableReference) obj;
if (ref.getRef() instanceof AliasDeclaration) {
AliasDeclaration alias = (AliasDeclaration) ref.getRef();
EObject par = obj.eContainer();
QualifiedReference qref = null;
while (par instanceof QualifiedReference) {
QualifiedReference parent = (QualifiedReference) par;
QualifiedReference tmp = GalFactory.eINSTANCE.createQualifiedReference();
tmp.setQualifier(EcoreUtil.copy(parent.getQualifier()));
tmp.setNext(qref);
qref = tmp;
par = par.eContainer();
}
IntExpression expr = EcoreUtil.copy(alias.getExpr());

if (qref != null) {
// now qualify all variables in the alias.
for (TreeIterator<EObject> jt = expr.eAllContents() ; jt.hasNext() ; ) {
EObject o = jt.next();
if (o instanceof VariableReference) {
VariableReference vref = (VariableReference) o;
QualifiedReference q = EcoreUtil.copy(qref);
QualifiedReference qq = q;
while (qq.getNext() != null) {
qq = (QualifiedReference) qq.getNext();
}
qq.setNext(EcoreUtil.copy(vref));
EcoreUtil.replace(o, q);
jt.prune();
}
}
EObject torep = obj.eContainer();
while (torep.eContainer() instanceof QualifiedReference) {
torep = torep.eContainer();
}
EcoreUtil.replace(torep, expr);
} else {
EcoreUtil.replace(obj, expr);
}



it.prune();
nbsub++;
}
}
}
for (TypeDeclaration td : spec.getTypes()) {
if (td instanceof GALTypeDeclaration) {
GALTypeDeclaration gal = (GALTypeDeclaration) td;
gal.getAlias().clear();
}
}
return nbsub;
}

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

0 comments on commit 6d9a6ec

Please sign in to comment.