Skip to content

Commit b77f500

Browse files
authored
extended simulator
1 parent 94b5d66 commit b77f500

12 files changed

+377
-64
lines changed

BasicExpression.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17046,10 +17046,9 @@ public Expression evaluate(
1704617046

1704717047
if (bf == null)
1704817048
{ return this; }
17049-
17050-
ModelState opstackframe = (ModelState) beta.clone();
17051-
opstackframe.addNewEnvironment();
17052-
opstackframe.addVariable("self", selfobject);
17049+
17050+
beta.addNewEnvironment();
17051+
beta.addVariable("self", selfobject);
1705317052

1705417053
Vector parValues = new Vector();
1705517054
for (int i = 0; i < actualPars.size(); i++)
@@ -17059,7 +17058,9 @@ public Expression evaluate(
1705917058
}
1706017059

1706117060
Expression res =
17062-
bf.execute(sigma, opstackframe, parValues);
17061+
bf.execute(sigma, beta, parValues);
17062+
17063+
beta.removeLastEnvironment();
1706317064

1706417065
return res;
1706517066
}

BehaviouralFeature.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ public Expression execute(ModelSpecification sigma,
147147

148148
// return value is that computed by this operation,
149149
// if it returns a value.
150-
151-
ModelState local = (ModelState) beta.clone();
152150

153151
System.out.println(">> Executing operation " + this +
154152
" on parameters " + parValues +
@@ -162,24 +160,27 @@ public Expression execute(ModelSpecification sigma,
162160
String pname = par.getName();
163161
if (i < parValues.size())
164162
{ Expression pval = (Expression) parValues.get(i);
165-
local.addVariable(pname, pval);
163+
beta.addVariable(pname, pval);
166164
}
167165
else if (typ != null)
168166
{ Expression def = Type.defaultInitialValueExpression(typ);
169-
local.addVariable(pname, def);
167+
beta.addVariable(pname, def);
170168
}
171169
}
172170

173171
if (resultType != null)
174172
{ Expression res =
175173
Type.defaultInitialValueExpression(resultType);
176-
local.addVariable("result", res);
174+
beta.addVariable("result", res);
177175
}
178176

179-
int status = activity.execute(sigma,local);
177+
int status = activity.execute(sigma, beta);
180178

179+
/* JOptionPane.showInputDialog(">> Operation result is " +
180+
beta.getVariableValue("result")); */
181+
181182
if (resultType != null)
182-
{ return local.getVariableValue("result"); }
183+
{ return beta.getVariableValue("result"); }
183184

184185
return null;
185186
}

BinaryExpression.java

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19162,6 +19162,32 @@ public Expression evaluate(ModelSpecification sigma,
1916219162

1916319163
Expression lft = left.evaluate(sigma, beta);
1916419164
Expression rgt = right.evaluate(sigma, beta);
19165+
19166+
if ("->apply".equals(operator) &&
19167+
lft instanceof UnaryExpression &&
19168+
((UnaryExpression) lft).getOperator().equals("lambda"))
19169+
{ UnaryExpression lam = (UnaryExpression) lft;
19170+
// create a new local state binding lam.accumulator to rgt
19171+
// Evaluate lft in that state.
19172+
19173+
Expression arg = lam.getArgument();
19174+
Attribute acc = lam.getAccumulator();
19175+
19176+
if (acc != null)
19177+
{ String nme = acc.getName();
19178+
beta.addNewEnvironment();
19179+
beta.addVariable(nme, rgt);
19180+
19181+
// JOptionPane.showInputDialog("Evaluating " + arg + " in environment " + beta);
19182+
19183+
Expression res = arg.evaluate(sigma, beta);
19184+
beta.removeLastEnvironment();
19185+
return res.simplify();
19186+
}
19187+
19188+
return new BasicExpression("null");
19189+
}
19190+
1916519191
return simplify(operator, lft, rgt, false);
1916619192
}
1916719193

@@ -21645,7 +21671,7 @@ public Expression simplifyOCL()
2164521671
synLeft > synRight)
2164621672
{ BinaryExpression res =
2164721673
new BinaryExpression(operator, rexpr, lexpr);
21648-
System.out.println(">> OCL efficiency smell (OES): Inefficient logical combination: " + this);
21674+
System.err.println("! Possible OCL efficiency smell (OES): Inefficient logical combination: " + this);
2164921675
return res;
2165021676
}
2165121677

@@ -21663,7 +21689,7 @@ public Expression simplifyOCL()
2166321689

2166421690
if (leftargop.equals("->select"))
2166521691
{ // s->select(P)->size() = 0
21666-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21692+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2166721693

2166821694
UnaryExpression notpred =
2166921695
new UnaryExpression("not", leftargpred);
@@ -21674,7 +21700,7 @@ public Expression simplifyOCL()
2167421700
}
2167521701
else if (leftargop.equals("->reject"))
2167621702
{ // s->reject(P)->size() = 0
21677-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21703+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2167821704

2167921705
BinaryExpression res =
2168021706
new BinaryExpression("->forAll", leftargleft,
@@ -21683,7 +21709,7 @@ else if (leftargop.equals("->reject"))
2168321709
}
2168421710
else if (leftargop.equals("|"))
2168521711
{ // s->select(x | P)->size() = 0
21686-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21712+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2168721713

2168821714
UnaryExpression notpred =
2168921715
new UnaryExpression("not", leftargpred);
@@ -21694,7 +21720,7 @@ else if (leftargop.equals("|"))
2169421720
}
2169521721
else if (leftargop.equals("|R"))
2169621722
{ // s->reject(x | P)->size() = 0
21697-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21723+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2169821724

2169921725
BinaryExpression res =
2170021726
new BinaryExpression("!", leftargleft,
@@ -21704,7 +21730,7 @@ else if (leftargop.equals("|R"))
2170421730
}
2170521731
else if ("->size".equals(leftop))
2170621732
{ // col->size() = 0 is col->isEmpty()
21707-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21733+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2170821734

2170921735
Expression col = arg.getArgument();
2171021736
UnaryExpression res =
@@ -21720,7 +21746,7 @@ else if ("->size".equals(leftop))
2172021746
if (leftop.equals("->count"))
2172121747
{ // s->count(x) = 0
2172221748

21723-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21749+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2172421750

2172521751
BinaryExpression res =
2172621752
new BinaryExpression("->excludes", be.getLeft(),
@@ -21743,7 +21769,7 @@ else if ("->size".equals(leftop))
2174321769

2174421770
if (leftargop.equals("->select"))
2174521771
{ // s->select(P)->size() = 1
21746-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21772+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2174721773

2174821774
BinaryExpression res =
2174921775
new BinaryExpression("->exists1", leftargleft,
@@ -21752,7 +21778,7 @@ else if ("->size".equals(leftop))
2175221778
}
2175321779
else if (leftargop.equals("->reject"))
2175421780
{ // s->reject(P)->size() = 1
21755-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21781+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2175621782

2175721783
UnaryExpression notpred =
2175821784
new UnaryExpression("not", leftargpred);
@@ -21763,7 +21789,7 @@ else if (leftargop.equals("->reject"))
2176321789
}
2176421790
else if (leftargop.equals("|"))
2176521791
{ // s->select(x | P)->size() = 1
21766-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21792+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2176721793

2176821794
BinaryExpression res =
2176921795
new BinaryExpression("#1", leftargleft,
@@ -21772,7 +21798,7 @@ else if (leftargop.equals("|"))
2177221798
}
2177321799
else if (leftargop.equals("|R"))
2177421800
{ // s->reject(x | P)->size() = 1
21775-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21801+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2177621802

2177721803
UnaryExpression notpred =
2177821804
new UnaryExpression("not", leftargpred);
@@ -21799,7 +21825,7 @@ else if (leftargop.equals("|R"))
2179921825

2180021826
if (leftargop.equals("->select"))
2180121827
{ // s->select(P)->size() > 0
21802-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21828+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2180321829

2180421830
BinaryExpression res =
2180521831
new BinaryExpression("->exists", leftargleft,
@@ -21808,7 +21834,7 @@ else if (leftargop.equals("|R"))
2180821834
}
2180921835
else if (leftargop.equals("->reject"))
2181021836
{ // s->reject(P)->size() > 0
21811-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21837+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2181221838

2181321839
UnaryExpression notpred =
2181421840
new UnaryExpression("not", leftargpred);
@@ -21820,7 +21846,7 @@ else if (leftargop.equals("->reject"))
2182021846
else if (leftargop.equals("|"))
2182121847
{ // s->select(x | P)->size() > 0
2182221848

21823-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21849+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2182421850

2182521851
BinaryExpression res =
2182621852
new BinaryExpression("#", leftargleft,
@@ -21830,7 +21856,7 @@ else if (leftargop.equals("|"))
2183021856
else if (leftargop.equals("|R"))
2183121857
{ // s->reject(x | P)->size() > 0
2183221858

21833-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21859+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2183421860

2183521861
UnaryExpression notpred =
2183621862
new UnaryExpression("not", leftargpred);
@@ -21843,7 +21869,7 @@ else if (leftargop.equals("|R"))
2184321869
else if ("->size".equals(leftop))
2184421870
{ // col->size() > 0
2184521871

21846-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21872+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2184721873
Expression col = arg.getArgument();
2184821874
UnaryExpression res =
2184921875
new UnaryExpression("->notEmpty", col);
@@ -21857,7 +21883,7 @@ else if ("->size".equals(leftop))
2185721883
String leftop = be.getOperator();
2185821884
if (leftop.equals("->count"))
2185921885
{ // s->count(x) > 0
21860-
System.out.println(">> OCL efficiency smell (OES): Inefficient comparison: " + this);
21886+
System.err.println("!! OCL efficiency smell (OES): Inefficient comparison: " + this);
2186121887

2186221888
BinaryExpression res =
2186321889
new BinaryExpression("->includes", be.getLeft(),
@@ -21873,7 +21899,7 @@ else if ("->size".equals(leftop))
2187321899
{ BinaryExpression lbe = (BinaryExpression) domain;
2187421900

2187521901
if (lbe.operator.equals("->select"))
21876-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select: " + this);
21902+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select: " + this);
2187721903
Expression newleft = lbe.getLeft();
2187821904
Expression newright = lbe.getRight();
2187921905
BasicExpression ref =
@@ -21887,7 +21913,7 @@ else if ("->size".equals(leftop))
2188721913
return new BinaryExpression("|", newdomain, newpred);
2188821914
}
2188921915
else if (lbe.operator.equals("->reject"))
21890-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select: " + this);
21916+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select: " + this);
2189121917
Expression newleft = lbe.getLeft();
2189221918
Expression newright = lbe.getRight();
2189321919
BasicExpression ref =
@@ -21911,7 +21937,7 @@ else if (operator.equals("|R"))
2191121937
{ BinaryExpression lbe = (BinaryExpression) domain;
2191221938

2191321939
if (lbe.operator.equals("->select"))
21914-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select/reject: " + this);
21940+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select/reject: " + this);
2191521941
Expression newleft = lbe.getLeft();
2191621942
Expression newright = lbe.getRight();
2191721943
BasicExpression ref =
@@ -21926,7 +21952,7 @@ else if (operator.equals("|R"))
2192621952
return new BinaryExpression("|", newdomain, newpred);
2192721953
}
2192821954
else if (lbe.operator.equals("->reject"))
21929-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested reject: " + this);
21955+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested reject: " + this);
2193021956
Expression newleft = lbe.getLeft();
2193121957
Expression newright = lbe.getRight();
2193221958
BasicExpression ref =
@@ -21948,19 +21974,19 @@ else if (operator.equals("->select"))
2194821974
if (left instanceof BinaryExpression)
2194921975
{ BinaryExpression lbe = (BinaryExpression) left;
2195021976
if (lbe.operator.equals("->select"))
21951-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select: " + this);
21977+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select: " + this);
2195221978
Expression predicate1 = lbe.getRight();
2195321979
Expression combinedPred =
2195421980
new BinaryExpression("&", predicate1, right);
2195521981
BinaryExpression res = (BinaryExpression) clone();
2195621982
res.left = lbe.getLeft();
2195721983
res.operator = "->select";
2195821984
res.right = combinedPred;
21959-
System.out.println(">> Replacing with: " + res);
21985+
System.out.println("!! Replacing with: " + res);
2196021986
return res;
2196121987
}
2196221988
else if (lbe.operator.equals("->reject"))
21963-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select: " + this);
21989+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select: " + this);
2196421990
Expression predicate1 = lbe.getRight();
2196521991
Expression pred2 =
2196621992
Expression.negate(predicate1);
@@ -21970,7 +21996,7 @@ else if (lbe.operator.equals("->reject"))
2197021996
res.left = lbe.getLeft();
2197121997
res.operator = "->select";
2197221998
res.right = combinedPred;
21973-
System.out.println(">> Replacing with: " + res);
21999+
System.out.println("!! Replacing with: " + res);
2197422000
return res;
2197522001
}
2197622002
}
@@ -21980,7 +22006,7 @@ else if (operator.equals("->reject"))
2198022006
if (left instanceof BinaryExpression)
2198122007
{ BinaryExpression lbe = (BinaryExpression) left;
2198222008
if (lbe.operator.equals("->select"))
21983-
{ System.out.println(">> OCL efficiency smell (OES): Inefficient nested select: " + this);
22009+
{ System.err.println("!! OCL efficiency smell (OES): Inefficient nested select: " + this);
2198422010
Expression predicate1 = lbe.getRight();
2198522011
Expression combinedPred =
2198622012
new BinaryExpression("&",
@@ -21989,7 +22015,7 @@ else if (operator.equals("->reject"))
2198922015
res.left = lbe.getLeft();
2199022016
res.operator = "->select";
2199122017
res.right = combinedPred;
21992-
System.out.println(">> Replacing with: " + res);
22018+
System.out.println("!! Replacing with: " + res);
2199322019
return res;
2199422020
}
2199522021
else if (lbe.operator.equals("->reject"))

CGSpec.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import java.util.Vector;
1212
import java.io.*;
1313
import java.util.regex.Matcher;
14-
import java.util.regex.Pattern;
14+
import java.util.regex.Pattern;
15+
16+
import javax.swing.JOptionPane;
1517

1618

1719
public class CGSpec
@@ -802,12 +804,18 @@ else if (op.startsWith("->") && trimmedlhs.endsWith(op + "()"))
802804
{ selected = r; }
803805
else if (trimmedlhs.startsWith(op))
804806
{ selected = r; }
807+
else if (op.equals("lambda") &&
808+
trimmedlhs.startsWith("(" + op))
809+
{ selected = r; }
810+
811+
// JOptionPane.showInputDialog(">>> unary expression rule " + r + " for " + e + " selected: " + selected + " " + args);
805812

806813
if (selected != null &&
807814
selected.satisfiesConditions(args,
808815
entities,this))
809816
{ return selected; }
810817
}
818+
811819
return null;
812820
} // _1 binds to argument
813821

Entity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ public ObjectSpecification initialisedObject(String nme)
365365
new ObjectSpecification(nme, this);
366366

367367
for (int i = 0; i < attributes.size(); i++)
368-
{ Attribute attr = (Attribute) attributes.get(i);
368+
{ Attribute attr = (Attribute) attributes.get(i);
369+
if (attr.isStatic())
370+
{ continue; }
369371
String aname = attr.getName();
370372
Expression aval = attr.getInitialisation();
371373
res.setOCLValue(aname, aval);

0 commit comments

Comments
 (0)