Skip to content

Commit 4211ff1

Browse files
author
nmacedo
committed
fixed #178
1 parent 4952b31 commit 4211ff1

File tree

8 files changed

+60
-41
lines changed

8 files changed

+60
-41
lines changed

examples/pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
1515
defaultValueLiteral="New"/>
1616
<eStructuralFeatures xsi:type="ecore:EReference" name="tables" upperBound="-1"
17-
eType="ecore:EClass /pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Table"
18-
containment="true" eOpposite="/pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Table/scheme"/>
17+
eType="#//Table" containment="true" eOpposite="#//Table/scheme"/>
1918
</eClassifiers>
2019
<eClassifiers xsi:type="ecore:EClass" name="Table">
2120
<eAnnotations source="echo/Gen">
@@ -36,11 +35,9 @@
3635
</eOperations>
3736
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
3837
<eStructuralFeatures xsi:type="ecore:EReference" name="columns" upperBound="-1"
39-
eType="ecore:EClass /pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Column"
40-
containment="true" eOpposite="/pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Column/table"/>
38+
eType="#//Column" containment="true" eOpposite="#//Column/table"/>
4139
<eStructuralFeatures xsi:type="ecore:EReference" name="scheme" lowerBound="1"
42-
eType="ecore:EClass /pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Scheme"
43-
eOpposite="/pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Scheme/tables"/>
40+
eType="#//Scheme" eOpposite="#//Scheme/tables"/>
4441
</eClassifiers>
4542
<eClassifiers xsi:type="ecore:EClass" name="Column">
4643
<eOperations name="setName">
@@ -56,7 +53,7 @@
5653
<eParameters name="n" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
5754
</eOperations>
5855
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
59-
<eStructuralFeatures xsi:type="ecore:EReference" name="table" lowerBound="1" eType="ecore:EClass /pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Table"
60-
eOpposite="/pt.uminho.haslab.echo.examples/metamodels/uml2rdbms_simple/RDBMS.ecore#//Table/columns"/>
56+
<eStructuralFeatures xsi:type="ecore:EReference" name="table" lowerBound="1" eType="#//Table"
57+
eOpposite="#//Table/columns"/>
6158
</eClassifiers>
6259
</ecore:EPackage>

examples/pt.uminho.haslab.echo.examples/models/hsm2nhsm/HSM_expanded.xmi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
name="machine">
99
<states xsi:type="hsm:CompositeState"
1010
name="Active"/>
11-
<states name="Idle"/>
1211
<states name="Running"
1312
container="//@states.0"/>
1413
<states name="Waiting"
1514
container="//@states.0"/>
1615
<transitions
1716
source="//@states.1"
18-
target="//@states.3"/>
17+
target="//@states.2"/>
1918
</hsm:StateMachine>

examples/pt.uminho.haslab.echo.examples/models/hsm2nhsm/NHM_example.xmi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
xsi:schemaLocation="NHSM /pt.uminho.haslab.echo.examples/metamodels/hsm2nhsm/NHSM.ecore"
88
name="machine">
99
<states name="Active"/>
10-
<states name="Idle"/>
1110
<states name="Error"/>
1211
<transitions
13-
source="//@states.1"
12+
source="//@states.0"
1413
target="//@states.0"/>
1514
<transitions
1615
source="//@states.0"
17-
target="//@states.2"/>
16+
target="//@states.1"/>
1817
</nhsm:StateMachine>

plugins/pt.uminho.haslab.echo/src/pt/uminho/haslab/echo/engine/OCLTranslator.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ else if (expr instanceof PropertyCallExp) {
5252
return n;
5353
}
5454
else if (expr instanceof IfExp)
55-
return translateExpression((IfExp) expr);
55+
return translate((IfExp) expr);
5656
else if (expr instanceof UnlimitedNaturalLiteralExp)
5757
return translateInteger((UnlimitedNaturalLiteralExp) expr);
5858
else if (expr instanceof TypeExp)
@@ -82,6 +82,8 @@ else if (expr instanceof OperationCallExp) {
8282
if (n instanceof IFormula)
8383
return (IFormula) n;
8484
}
85+
else if (expr instanceof IfExp)
86+
return (IFormula) translate((IfExp) expr);
8587
else if (expr instanceof RelationCallExp) {
8688
INode n = translate((RelationCallExp) expr);
8789
if (n instanceof IFormula)
@@ -96,7 +98,7 @@ public IExpression translateExpression(OCLExpression expr) throws EchoError {
9698
else if (expr instanceof VariableExp)
9799
return translateExpression((VariableExp) expr);
98100
else if (expr instanceof IfExp)
99-
return translateExpression((IfExp) expr);
101+
return (IExpression) translate((IfExp) expr);
100102

101103
else if (expr instanceof PropertyCallExp) {
102104
INode n = translate((PropertyCallExp) expr);
@@ -218,13 +220,17 @@ else if (ocl.equals(Constants.FALSE()))
218220
return result;
219221
}
220222

221-
private IExpression translateExpression(IfExp expr) throws EchoError {
223+
private INode translate(IfExp expr) throws EchoError {
222224
IFormula eif = translateFormula(expr.getCondition());
223-
IExpression thenExpr = translateExpression(expr.getThenExpression());
224-
IExpression elseExpr = translateExpression(expr.getElseExpression());
225+
INode thenExpr = translate(expr.getThenExpression());
226+
INode elseExpr = translate(expr.getElseExpression());
225227

226-
IExpression res = eif.thenElse(thenExpr, elseExpr);
227-
return res;
228+
if (thenExpr instanceof IExpression && elseExpr instanceof IExpression)
229+
return eif.thenElse((IExpression) thenExpr,(IExpression) elseExpr);
230+
else if (thenExpr instanceof IFormula && elseExpr instanceof IFormula)
231+
return (IFormula) eif.thenElse((IFormula) thenExpr,(IFormula) elseExpr);
232+
233+
throw new EchoTypeError("Expression: "+expr.getClass());
228234
}
229235

230236
private INode translate(PropertyCallExp expr) throws EchoError {

plugins/pt.uminho.haslab.echo/src/pt/uminho/haslab/echo/engine/alloy/AlloyFormula.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pt.uminho.haslab.echo.engine.ast.IDecl;
1010
import pt.uminho.haslab.echo.engine.ast.IExpression;
1111
import pt.uminho.haslab.echo.engine.ast.IFormula;
12+
import pt.uminho.haslab.echo.engine.ast.INode;
1213

1314
/**
1415
* Alloy representation of formulas.
@@ -26,46 +27,54 @@ class AlloyFormula implements IFormula {
2627

2728
/** {@inheritDoc} */
2829
@Override
29-
public IFormula and(IFormula f) {
30+
public AlloyFormula and(IFormula f) {
3031
return new AlloyFormula(FORMULA.and(((AlloyFormula) f).FORMULA));
3132
}
3233

3334
/** {@inheritDoc} */
3435
@Override
35-
public IFormula or(IFormula f) {
36+
public AlloyFormula or(IFormula f) {
3637
return new AlloyFormula(FORMULA.or(((AlloyFormula) f).FORMULA));
3738
}
3839

3940
/** {@inheritDoc} */
4041
@Override
41-
public IFormula iff(IFormula f) {
42+
public AlloyFormula iff(IFormula f) {
4243
return new AlloyFormula(FORMULA.iff(((AlloyFormula) f).FORMULA));
4344
}
4445

4546
/** {@inheritDoc} */
4647
@Override
47-
public IFormula implies(IFormula f) {
48+
public AlloyFormula implies(IFormula f) {
4849
return new AlloyFormula(FORMULA.implies(((AlloyFormula) f).FORMULA));
4950
}
5051

5152
/** {@inheritDoc} */
5253
@Override
53-
public IFormula not() {
54+
public AlloyFormula not() {
5455
return new AlloyFormula(FORMULA.not());
5556
}
5657

5758
/** {@inheritDoc} */
5859
@Override
59-
public IExpression thenElse(IExpression thenExpr, IExpression elseExpr) {
60+
public AlloyExpression thenElse(IExpression thenExpr, IExpression elseExpr) {
6061
return new AlloyExpression(ExprITE.make(null, FORMULA,
6162
((AlloyExpression) thenExpr).EXPR,
6263
((AlloyExpression) elseExpr).EXPR));
6364
}
6465

66+
/** {@inheritDoc} */
67+
@Override
68+
public AlloyFormula thenElse(IFormula thenExpr, IFormula elseExpr) {
69+
return new AlloyFormula(ExprITE.make(null, FORMULA,
70+
((AlloyFormula) thenExpr).FORMULA,
71+
((AlloyFormula) elseExpr).FORMULA));
72+
}
73+
6574
//TODO check
6675
/** {@inheritDoc} */
6776
@Override
68-
public IExpression comprehension(IDecl firstDecl, IDecl... extraDecls) throws ErrorInternalEngine {
77+
public AlloyExpression comprehension(IDecl firstDecl, IDecl... extraDecls) throws ErrorInternalEngine {
6978
Decl[] ds = new Decl[extraDecls.length];
7079
for(int i = 0; i < extraDecls.length; i++)
7180
ds[i] = (((AlloyDecl) extraDecls[i]).DECL);
@@ -81,7 +90,7 @@ public IExpression comprehension(IDecl firstDecl, IDecl... extraDecls) throws Er
8190

8291
/** {@inheritDoc} */
8392
@Override
84-
public IFormula forAll(IDecl decl, IDecl... extraDecls) throws ErrorInternalEngine {
93+
public AlloyFormula forAll(IDecl decl, IDecl... extraDecls) throws ErrorInternalEngine {
8594
Decl[] ds = new Decl[extraDecls.length];
8695
for(int i = 0; i < extraDecls.length; i++)
8796
ds[i] = (((AlloyDecl) extraDecls[i]).DECL);
@@ -95,7 +104,7 @@ public IFormula forAll(IDecl decl, IDecl... extraDecls) throws ErrorInternalEngi
95104

96105
/** {@inheritDoc} */
97106
@Override
98-
public IFormula forSome(IDecl decl, IDecl... extraDecls) throws ErrorInternalEngine {
107+
public AlloyFormula forSome(IDecl decl, IDecl... extraDecls) throws ErrorInternalEngine {
99108
Decl[] ds = new Decl[extraDecls.length];
100109
for(int i = 0; i < extraDecls.length; i++)
101110
ds[i] = (((AlloyDecl) extraDecls[i]).DECL);
@@ -109,7 +118,7 @@ public IFormula forSome(IDecl decl, IDecl... extraDecls) throws ErrorInternalEng
109118

110119
/** {@inheritDoc} */
111120
@Override
112-
public IFormula forOne(IDecl d) throws ErrorInternalEngine {
121+
public AlloyFormula forOne(IDecl d) throws ErrorInternalEngine {
113122
try {
114123
return new AlloyFormula(FORMULA.forOne(((AlloyDecl) d).DECL));
115124
} catch (Err e) {

plugins/pt.uminho.haslab.echo/src/pt/uminho/haslab/echo/engine/alloy/AlloyRunner.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,19 @@ public boolean repair(String modelID) throws ErrorAlloy {
175175
EAlloyModel model = AlloyEchoTranslator.getInstance().getModel(
176176
modelID);
177177
EAlloyMetamodel metamodel = model.metamodel;
178-
edelta = metamodel.getDeltaSetFunc().call(original, target)
179-
.cardinality();
180-
edelta = metamodel.getDeltaRelFunc().call(original, target);
178+
edelta = metamodel.getDeltaSetFunc().call(original, target);
179+
try {
180+
Collection<Sig> aux = new ArrayList<Sig>();
181+
aux.add(Sig.UNIV);
182+
SubsetSig news = new SubsetSig(EchoHelper.NEWSNAME,
183+
aux, new Attr[0]);
184+
allsigs.add(news);
185+
finalfact = finalfact.and(news.equal(edelta));
186+
} catch (Err e) {
187+
// TODO Auto-generated catch block
188+
e.printStackTrace();
189+
}
190+
edelta = edelta.cardinality().iplus(metamodel.getDeltaRelFunc().call(original, target));
181191
AlloyEchoTranslator.getInstance().createScopesFromID(modelIDs);
182192
finalfact = finalfact.and(model.metamodel.getConforms(modelID).FORMULA);
183193
finalfact = finalfact.and(model.getModelConstraint().FORMULA);
@@ -324,6 +334,8 @@ public boolean enforce(String transformationID, List<String> modelIDs,
324334
.getConforms(modelID).FORMULA);
325335
if (!EchoOptionsSetup.getInstance().isOperationBased()) {
326336
EAlloyMetamodel metamodel = model.metamodel;
337+
edelta = metamodel.getDeltaSetFunc().call(original,
338+
target);
327339
try {
328340
Collection<Sig> aux = new ArrayList<Sig>();
329341
aux.add(Sig.UNIV);
@@ -335,11 +347,9 @@ public boolean enforce(String transformationID, List<String> modelIDs,
335347
// TODO Auto-generated catch block
336348
e.printStackTrace();
337349
}
338-
Expr temp = metamodel.getDeltaSetFunc().call(original,
339-
target);
340-
edelta = edelta.iplus(temp.cardinality().iplus(
350+
edelta = edelta.cardinality().iplus(
341351
metamodel.getDeltaRelFunc().call(original,
342-
target)));
352+
target));
343353
} else {
344354
edelta = Sig.NONE.no();
345355
}

plugins/pt.uminho.haslab.echo/src/pt/uminho/haslab/echo/engine/alloy/EAlloyMetamodel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ List<PrimSig> getCAllSigs() {
242242
*/
243243
protected AlloyFormula getConforms(String modelID) throws ErrorAlloy {
244244
if(!doneContainments){
245-
makeContainmentConstraint();
245+
//makeContainmentConstraint();
246246
doneContainments = true;
247247
}
248248

plugins/pt.uminho.haslab.echo/src/pt/uminho/haslab/echo/engine/ast/IFormula.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ public interface IFormula extends INode{
1313
IFormula and(IFormula f);
1414
IFormula or(IFormula f);
1515

16+
IExpression thenElse(IExpression thenExpr, IExpression elseExpr);
17+
IFormula thenElse(IFormula thenExpr, IFormula elseExpr);
1618

1719
IFormula iff(IFormula f);
1820
IFormula implies(IFormula f);
1921

2022
IFormula not();
2123

22-
IExpression thenElse(IExpression thenExpr, IExpression elseExpr);
23-
2424
IExpression comprehension(IDecl firstDecl, IDecl... extraDecls) throws ErrorInternalEngine;
2525

26-
2726
IFormula forAll(IDecl decl, IDecl... moreDecls) throws ErrorInternalEngine;
2827
IFormula forSome(IDecl decl, IDecl... moreDecls) throws ErrorInternalEngine;
2928
IFormula forOne(IDecl d) throws ErrorInternalEngine;

0 commit comments

Comments
 (0)