Skip to content

Commit e789b35

Browse files
authored
Emulation for static operations, attributes
1 parent aba7380 commit e789b35

File tree

7 files changed

+154
-43
lines changed

7 files changed

+154
-43
lines changed

BasicExpression.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16955,7 +16955,7 @@ public Expression simplify(final Vector vars)
1695516955
public Expression evaluate(
1695616956
ModelSpecification sigma, ModelState beta)
1695716957
{ if (umlkind == VARIABLE)
16958-
{ String nme = getData();
16958+
{ String nme = getData();
1695916959
Expression expr = beta.getVariableValue(nme);
1696016960

1696116961
if (expr != null)
@@ -16974,6 +16974,14 @@ public Expression evaluate(
1697416974

1697516975
if (umlkind == ATTRIBUTE && objectRef != null)
1697616976
{ String nme = getData();
16977+
16978+
if (this.isStatic() && entity != null)
16979+
{ String ename = entity.getName();
16980+
Expression expr =
16981+
sigma.getStaticAttributeValue(ename, nme);
16982+
return expr;
16983+
}
16984+
1697716985
Expression obj = objectRef.evaluate(sigma,beta);
1697816986

1697916987
if (obj != null)
@@ -16983,6 +16991,14 @@ public Expression evaluate(
1698316991
if (umlkind == ATTRIBUTE && objectRef == null)
1698416992
{ // attribute of self
1698516993
String nme = getData();
16994+
16995+
if (this.isStatic() && entity != null)
16996+
{ String ename = entity.getName();
16997+
Expression expr =
16998+
sigma.getStaticAttributeValue(ename, nme);
16999+
return expr;
17000+
}
17001+
1698617002
Expression obj = beta.getVariableValue("self");
1698717003

1698817004
if (obj != null)
@@ -16997,30 +17013,36 @@ public Expression evaluate(
1699717013
String op = this.getData();
1699817014
Vector actualPars = this.getParameters();
1699917015
int npars = actualPars.size();
17016+
17017+
BehaviouralFeature bf = null;
17018+
Expression selfobject = null;
1700017019

17001-
Expression selfobject;
17002-
17003-
if (obj != null)
17004-
{ selfobject = obj.evaluate(sigma, beta); }
17020+
if (this.isStatic() && entity != null)
17021+
{ bf = entity.getOperation(op, npars);
17022+
selfobject = new BasicExpression("null");
17023+
}
1700517024
else
17006-
{ selfobject = beta.getVariableValue("self"); }
17025+
{ if (obj != null)
17026+
{ selfobject = obj.evaluate(sigma, beta); }
17027+
else
17028+
{ selfobject = beta.getVariableValue("self"); }
1700717029

17008-
if (selfobject == null) // error
17009-
{ return this; }
17030+
if (selfobject == null) // error
17031+
{ return this; }
1701017032

17011-
ObjectSpecification ospec =
17033+
ObjectSpecification ospec =
1701217034
sigma.getObjectSpec("" + selfobject);
1701317035

17014-
if (ospec == null) // error
17015-
{ return this; }
17036+
if (ospec == null) // static case
17037+
{ return this; }
1701617038

17017-
Entity ent = ospec.getEntity();
17039+
Entity ent = ospec.getEntity();
1701817040

17019-
if (ent == null)
17020-
{ return this; }
17041+
if (ent == null)
17042+
{ return this; }
1702117043

17022-
BehaviouralFeature bf = ent.getOperation(op, npars);
17023-
// assume not static:
17044+
bf = ent.getOperation(op, npars);
17045+
}
1702417046

1702517047
if (bf == null)
1702617048
{ return this; }
@@ -17037,7 +17059,8 @@ public Expression evaluate(
1703717059
}
1703817060

1703917061
Expression res =
17040-
bf.execute(sigma, opstackframe, parValues);
17062+
bf.execute(sigma, opstackframe, parValues);
17063+
1704117064
return res;
1704217065
}
1704317066

Entity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,6 +5795,7 @@ public void emulateOperation(String op)
57955795
ObjectSpecification obj = this.initialisedObject(oid);
57965796
ms.addObject(obj);
57975797
beta.addVariable("self", new BasicExpression(obj));
5798+
// new BasicExpression(oid)
57985799
System.out.println(">> Initial state = " + ms + "; " + beta);
57995800

58005801
bf.execute(ms, beta, pvals);

ModelSpecification.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class ModelSpecification
2424
// String -> ObjectSpecification
2525
java.util.Map objectsOfClass = new java.util.HashMap();
2626
// String -> Vector
27+
java.util.Map staticAttributesOfClass =
28+
new java.util.HashMap();
29+
// String -> Map(String, Expression)
2730

2831
public static int maxSourcePath = 1;
2932
public static int maxTargetPath = 1;
@@ -41,10 +44,23 @@ public ObjectSpecification getObjectSpec(String nme)
4144
{ return (ObjectSpecification) objectmap.get(nme); }
4245

4346
public void removeObject(Expression expr)
44-
{ objectmap.remove(expr + ""); }
47+
{ this.removeObject(expr + ""); }
4548

4649
public void removeObject(String nme)
47-
{ objectmap.remove(nme); }
50+
{ ObjectSpecification obj =
51+
(ObjectSpecification) objectmap.get(nme);
52+
objectmap.remove(nme);
53+
if (obj != null)
54+
{ objects.remove(obj);
55+
Entity ent = obj.entity;
56+
if (ent != null)
57+
{ String ename = ent.getName();
58+
Vector eobjs = (Vector) objectsOfClass.get(ename);
59+
if (eobjs != null)
60+
{ eobjs.remove(obj); }
61+
}
62+
}
63+
}
4864

4965
public void addObject(ObjectSpecification obj)
5066
{ if (objects.contains(obj)) { }
@@ -64,6 +80,25 @@ public void addObject(ObjectSpecification obj)
6480
}
6581
}
6682

83+
public void setStaticAttributeValue(String cls, String att,
84+
Expression val)
85+
{ java.util.Map cAtts =
86+
(java.util.Map) staticAttributesOfClass.get(cls);
87+
if (cAtts == null)
88+
{ cAtts = new java.util.HashMap(); }
89+
cAtts.put(att, val);
90+
staticAttributesOfClass.put(cls, cAtts);
91+
}
92+
93+
public Expression getStaticAttributeValue(String cls,
94+
String att)
95+
{ java.util.Map cAtts =
96+
(java.util.Map) staticAttributesOfClass.get(cls);
97+
if (cAtts == null)
98+
{ return null; }
99+
return (Expression) cAtts.get(att);
100+
}
101+
67102
public Vector getClassNames(Vector objs)
68103
{ Vector res = new Vector();
69104
for (int i = 0; i < objs.size(); i++)
@@ -137,6 +172,8 @@ public String toString()
137172
{ ObjectSpecification spec = (ObjectSpecification) objects.get(i);
138173
res = res + spec.details() + "\n";
139174
}
175+
176+
res = res + objectsOfClass + "\n";
140177

141178
for (int j = 0; j < correspondence.elements.size(); j++)
142179
{ Maplet mm = (Maplet) correspondence.elements.get(j);

ModelState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ else if (obj == null)
123123
}
124124
}
125125
else if (obj != null &&
126-
indx == null)
126+
indx == null)
127127
{ // object attribute
128128
Expression oid = obj.evaluate(sigma, this);
129129
ObjectSpecification ref = sigma.getObjectSpec("" + oid);

Statement.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,7 +5000,7 @@ public static InvocationStatement newInvocationStatement(
50005000
}
50015001

50025002
public int execute(ModelSpecification sigma,
5003-
ModelState beta)
5003+
ModelState beta)
50045004
{ int res = Statement.NORMAL;
50055005

50065006
if (callExp == null)
@@ -5017,29 +5017,41 @@ public int execute(ModelSpecification sigma,
50175017
Vector actualPars = cexpr.getParameters();
50185018
int npars = actualPars.size();
50195019

5020-
Expression selfobject;
5020+
Expression selfobject = null;
5021+
BehaviouralFeature bf = null;
5022+
5023+
JOptionPane.showInputDialog(callExp.isStatic() + " " +
5024+
callExp.getEntity());
50215025

5022-
if (obj != null)
5023-
{ selfobject = obj.evaluate(sigma, beta); }
5026+
if (callExp.isStatic() && callExp.getEntity() != null)
5027+
{ selfobject = new BasicExpression("null");
5028+
Entity ent = callExp.getEntity();
5029+
bf = ent.getOperation(op, npars);
5030+
}
50245031
else
5025-
{ selfobject = beta.getVariableValue("self"); }
5032+
{ if (obj != null)
5033+
{ selfobject = obj.evaluate(sigma, beta); }
5034+
else
5035+
{ selfobject = beta.getVariableValue("self"); }
50265036

5027-
if (selfobject == null) // error
5028-
{ return res; }
5037+
// JOptionPane.showInputDialog(selfobject);
5038+
5039+
if (selfobject == null) // error
5040+
{ return res; }
50295041

5030-
ObjectSpecification ospec =
5042+
ObjectSpecification ospec =
50315043
sigma.getObjectSpec("" + selfobject);
50325044

5033-
if (ospec == null) // error
5034-
{ return res; }
5035-
5036-
Entity ent = ospec.getEntity();
5045+
if (ospec == null)
5046+
{ return res; }
50375047

5038-
if (ent == null)
5039-
{ return res; }
5048+
Entity ent = ospec.getEntity();
50405049

5041-
BehaviouralFeature bf = ent.getOperation(op, npars);
5042-
// assume not static:
5050+
if (ent == null)
5051+
{ return res; }
5052+
5053+
bf = ent.getOperation(op, npars);
5054+
}
50435055

50445056
if (bf == null)
50455057
{ return res; }

UCDArea.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,14 +3679,17 @@ public void simulatedExecution(Entity cls)
36793679
String oid = Identifier.newIdentifier("oid_");
36803680
ObjectSpecification obj = cls.initialisedObject(oid);
36813681
ms.addObject(obj);
3682-
beta.addVariable("self", new BasicExpression(obj));
3683-
System.out.println(">> Initial state = " + ms + "; " + beta);
3682+
beta.addVariable("self", new BasicExpression(obj));
3683+
// new BasicExpression(oid)
3684+
System.out.println(">> Initial global state = " + ms);
3685+
System.out.println(">> Initial local state = " + beta);
36843686

36853687
bf.execute(ms, beta, pvals);
36863688
System.out.println();
3687-
System.out.println(">> Resulting state = " + ms + "; " + beta);
3689+
System.out.println(">> Resulting global state = " + ms);
3690+
System.out.println(">> Resulting local state = " + beta);
36883691
}
3689-
}
3692+
} // update UCDOperations
36903693

36913694
public void energyAnalysis()
36923695
{ java.util.Map clnes = new java.util.HashMap();

UnaryExpression.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,24 @@ public Expression evaluate(ModelSpecification sigma,
19011901
{ // Special cases for !e and ?x in sandboxed memory
19021902
// space in sigma.
19031903

1904+
if (operator.equals("->allInstances"))
1905+
{ Type resulttype = new Type("Sequence",null);
1906+
Type reselementType = argument.getElementType();
1907+
resulttype.setElementType(elementType);
1908+
SetExpression res = new SetExpression(true);
1909+
res.type = resulttype;
1910+
res.multiplicity = ModelElement.MANY;
1911+
res.modality = argument.modality;
1912+
Vector objs = sigma.getObjectsOf(argument + "");
1913+
for (int i = 0; i < objs.size(); i++)
1914+
{ ObjectSpecification obj =
1915+
(ObjectSpecification) objs.get(i);
1916+
res.addElement(new BasicExpression(obj));
1917+
}
1918+
1919+
return res;
1920+
}
1921+
19041922
Expression pre = argument.evaluate(sigma, beta);
19051923
return Expression.simplify(operator, pre);
19061924
}
@@ -1912,17 +1930,34 @@ public void execute(ModelSpecification sigma,
19121930
System.out.println("DISPLAY: " + val);
19131931
}
19141932
else if ("->isDeleted".equals(operator))
1915-
{ if (argument.umlkind == CLASSID &&
1916-
(argument instanceof BasicExpression) &&
1933+
{ if (argument instanceof BasicExpression &&
19171934
((BasicExpression) argument).arrayIndex == null)
1918-
{ // remove an object from its class
1935+
{ // remove the object from its class, and set the
1936+
// object variable to null:
1937+
19191938
Expression obj = argument.evaluate(sigma, beta);
19201939
sigma.removeObject(obj);
19211940
beta.updateState(sigma, argument,
19221941
new BasicExpression("null"));
19231942
System.out.println("DELETED: " + obj);
19241943
}
19251944
}
1945+
else if ("->oclIsNew".equals(operator) &&
1946+
(argument instanceof BasicExpression))
1947+
{ Type argt = argument.getType();
1948+
if (argt != null && argt.isEntity())
1949+
{ Entity argent = argt.getEntity();
1950+
String ename = argent.getName();
1951+
Expression obj = argument.evaluate(sigma, beta);
1952+
if ("null".equals(obj + ""))
1953+
{ String oid = Identifier.newIdentifier("oid_");
1954+
ObjectSpecification newobj =
1955+
argent.initialisedObject(oid);
1956+
sigma.addObject(newobj);
1957+
beta.updateState(sigma, argument, new BasicExpression(oid));
1958+
}
1959+
}
1960+
}
19261961
}
19271962

19281963
public String updateForm(java.util.Map env, boolean local)

0 commit comments

Comments
 (0)