Skip to content

Commit

Permalink
Implement "Alias" to support feature request
Browse files Browse the repository at this point in the history
  • Loading branch information
yanntm committed Jul 22, 2019
1 parent 1be2a40 commit 00b6580
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fr.lip6.move.gal/src/fr/lip6/move/Gal.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ GALTypeDeclaration:
(typedefs+=TypedefDeclaration)
|(variables+=VariableDeclaration)
|(arrays+=ArrayDeclaration)
|(alias+=AliasDeclaration)
// |(lists+=ListDeclaration)
)*
(transitions+=Transition
Expand Down Expand Up @@ -93,7 +94,7 @@ TemplateTypeDeclaration :

/* ============ GAL System Content ================== */

NamedDeclaration : VarDecl | InstanceDecl ;
NamedDeclaration : VarDecl | InstanceDecl | AliasDeclaration;

VarDecl :
VariableDeclaration | ArrayDeclaration
Expand All @@ -103,6 +104,10 @@ InstanceDecl :
InstanceDeclaration | ArrayInstanceDeclaration
;

AliasDeclaration :
'alias' name=FullyQualifiedName '=' expr=BitOr
;

//Ex: int abc = 10 ;
VariableDeclaration returns Variable:
(comment=COMMENT)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;

import fr.lip6.move.gal.AbstractParameter;
import fr.lip6.move.gal.AliasDeclaration;
import fr.lip6.move.gal.ArrayInstanceDeclaration;
import fr.lip6.move.gal.Assignment;
import fr.lip6.move.gal.Event;
Expand Down Expand Up @@ -409,6 +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 @@ -441,6 +443,29 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ private static IScope getVars(TypeDeclaration type) {
List<EObject> res = new ArrayList<EObject>();
res.addAll(gal.getVariables());
res.addAll(gal.getArrays());
res.addAll(gal.getAlias());
return Scopes.scopeFor(res);
}
if (type instanceof CompositeTypeDeclaration) {
Expand Down

0 comments on commit 00b6580

Please sign in to comment.