Skip to content

Commit 00b6580

Browse files
committed
Implement "Alias" to support feature request
#16
1 parent 1be2a40 commit 00b6580

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: fr.lip6.move.gal/src/fr/lip6/move/Gal.xtext

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ GALTypeDeclaration:
5959
(typedefs+=TypedefDeclaration)
6060
|(variables+=VariableDeclaration)
6161
|(arrays+=ArrayDeclaration)
62+
|(alias+=AliasDeclaration)
6263
// |(lists+=ListDeclaration)
6364
)*
6465
(transitions+=Transition
@@ -93,7 +94,7 @@ TemplateTypeDeclaration :
9394

9495
/* ============ GAL System Content ================== */
9596

96-
NamedDeclaration : VarDecl | InstanceDecl ;
97+
NamedDeclaration : VarDecl | InstanceDecl | AliasDeclaration;
9798

9899
VarDecl :
99100
VariableDeclaration | ArrayDeclaration
@@ -103,6 +104,10 @@ InstanceDecl :
103104
InstanceDeclaration | ArrayInstanceDeclaration
104105
;
105106

107+
AliasDeclaration :
108+
'alias' name=FullyQualifiedName '=' expr=BitOr
109+
;
110+
106111
//Ex: int abc = 10 ;
107112
VariableDeclaration returns Variable:
108113
(comment=COMMENT)?

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

+25
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.emf.ecore.util.EcoreUtil;
2323

2424
import fr.lip6.move.gal.AbstractParameter;
25+
import fr.lip6.move.gal.AliasDeclaration;
2526
import fr.lip6.move.gal.ArrayInstanceDeclaration;
2627
import fr.lip6.move.gal.Assignment;
2728
import fr.lip6.move.gal.Event;
@@ -409,6 +410,7 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {
409410
//first substitute const param by value
410411
// replace all parameters by values
411412
int nbsub = replaceConstParam(type);
413+
nbsub += replaceAlias(type);
412414
if (nbsub > 0) {
413415
Simplifier.simplifyAllExpressions(type);
414416
}
@@ -441,6 +443,29 @@ private static void initializeParametersAndVariables(TypeDeclaration type) {
441443

442444
}
443445

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+
444469
private static int replaceConstParam(EObject parent) {
445470
int nbsub = 0;
446471
for (TreeIterator<EObject> it = parent.eAllContents() ; it.hasNext() ; ) {

Diff for: fr.lip6.move.gal/src/fr/lip6/move/scoping/GalScopeProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ private static IScope getVars(TypeDeclaration type) {
482482
List<EObject> res = new ArrayList<EObject>();
483483
res.addAll(gal.getVariables());
484484
res.addAll(gal.getArrays());
485+
res.addAll(gal.getAlias());
485486
return Scopes.scopeFor(res);
486487
}
487488
if (type instanceof CompositeTypeDeclaration) {

0 commit comments

Comments
 (0)