Skip to content

Commit c84573b

Browse files
authored
Add files via upload
1 parent ff314ff commit c84573b

File tree

75 files changed

+68862
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+68862
-0
lines changed

version24/BAnyStatement.class

2.39 KB
Binary file not shown.

version24/BAnyStatement.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import java.util.Vector;
2+
3+
/* Copyright K. Lano 2003-2013
4+
Package: B AMN
5+
*/
6+
7+
public class BAnyStatement extends BStatement
8+
{ private Vector vars = new Vector(); // of String
9+
private BExpression pred;
10+
private BStatement code;
11+
12+
public BAnyStatement(Vector vs, BExpression qual,
13+
BStatement body)
14+
{ vars = vs;
15+
pred = qual;
16+
code = body;
17+
}
18+
19+
public Vector getVars()
20+
{ return vars; }
21+
22+
public BExpression getWhere()
23+
{ return pred; }
24+
25+
public BStatement getThen()
26+
{ return code; }
27+
28+
public Vector wr()
29+
{ return code.wr(); }
30+
31+
public Vector rd()
32+
{ Vector res = pred.rd();
33+
res = VectorUtil.union(res,code.rd());
34+
res.removeAll(vars);
35+
return res;
36+
}
37+
38+
public String toString()
39+
{ String res = "ANY ";
40+
for (int i = 0; i < vars.size(); i++)
41+
{ String var = (String) vars.get(i);
42+
res = res + var;
43+
if (i < vars.size() - 1)
44+
{ res = res + ", "; }
45+
}
46+
res = res + " WHERE " + pred + "\n" + " THEN " +
47+
code + " END";
48+
return res;
49+
}
50+
51+
public BStatement substituteEq(String oldE, BExpression newE)
52+
{ if (vars.contains(oldE)) { return this; }
53+
BExpression npred = pred.substituteEq(oldE,newE);
54+
BStatement ncode = code.substituteEq(oldE,newE);
55+
return new BAnyStatement(vars,npred,ncode);
56+
}
57+
58+
public BStatement simplify()
59+
{ BExpression npred = pred.simplify();
60+
BStatement ncode = code.simplify();
61+
return new BAnyStatement(vars,npred,ncode);
62+
}
63+
64+
public BStatement seq2parallel()
65+
{ BStatement ncode = code.seq2parallel();
66+
return new BAnyStatement(vars,pred,ncode);
67+
}
68+
69+
public BStatement normalise()
70+
{ BAnyStatement res;
71+
BStatement stat = code.normalise();
72+
if (stat instanceof BAnyStatement)
73+
{ BAnyStatement inner = (BAnyStatement) stat;
74+
Vector newvars = new Vector();
75+
newvars.addAll(vars);
76+
newvars.addAll(inner.getVars());
77+
BExpression newpred = new BBinaryExpression("&",pred,inner.getWhere());
78+
res = new BAnyStatement(newvars,newpred,inner.getThen());
79+
}
80+
else
81+
{ res = new BAnyStatement(vars,pred,stat); }
82+
return res;
83+
}
84+
}
85+

version24/BApplyExpression.class

2.95 KB
Binary file not shown.

version24/BApplyExpression.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import java.util.Vector;
2+
3+
/* Copyright K. Lano 2003-2013
4+
Package: B AMN */
5+
6+
public class BApplyExpression extends BExpression
7+
{ private String function;
8+
private BExpression func; // function = func.toString()
9+
private BExpression arg; // may be list
10+
private Vector args;
11+
12+
public BApplyExpression(String f, BExpression a)
13+
{ function = f;
14+
func = new BBasicExpression(f);
15+
arg = a;
16+
}
17+
18+
public BApplyExpression(BExpression f, BExpression a)
19+
{ function = f + "";
20+
func = f;
21+
arg = a;
22+
}
23+
24+
public BApplyExpression(BExpression f, Vector arglist)
25+
{ function = f + "";
26+
func = f;
27+
args = arglist;
28+
String argstring = "";
29+
for (int i = 0; i < arglist.size(); i++)
30+
{ argstring = argstring + arglist.get(i);
31+
if (i < arglist.size() - 1)
32+
{ argstring = argstring + ","; }
33+
}
34+
arg = new BBasicExpression(argstring);
35+
}
36+
37+
public Vector rd()
38+
{ Vector res = func.rd();
39+
res = VectorUtil.union(res,arg.rd());
40+
return res;
41+
}
42+
43+
public String getFunction()
44+
{ return function; }
45+
46+
public BExpression getArgument()
47+
{ return arg; }
48+
49+
public void setMultiplicity(int m)
50+
{ multiplicity = m; }
51+
52+
public boolean setValued()
53+
{ if (multiplicity != ModelElement.ONE)
54+
{ return true; }
55+
else
56+
{ return arg.setValued(); }
57+
}
58+
59+
public BExpression simplify()
60+
{ if (arg == null)
61+
{ System.err.println("Function: " + function + " with null argument");
62+
return null;
63+
}
64+
65+
if (func instanceof BBinaryExpression) // (f <+ {x |-> b})(x) is b
66+
{ BBinaryExpression bbe = (BBinaryExpression) func;
67+
if (bbe.getOperator().equals("<+") && (bbe.getRight() instanceof BSetExpression))
68+
{ BSetExpression update = (BSetExpression) bbe.getRight();
69+
BExpression elem0 = update.getElement(0);
70+
if (elem0 != null && (elem0 instanceof BBinaryExpression))
71+
{ BBinaryExpression belem0 = (BBinaryExpression) elem0;
72+
if (belem0.getOperator().equals("|->") && (arg + "").equals(belem0.getLeft() + ""))
73+
{ return belem0.getRight(); }
74+
}
75+
}
76+
}
77+
78+
BExpression sarg = arg.simplify();
79+
if (sarg instanceof BSetExpression)
80+
{ BSetExpression se = (BSetExpression) sarg;
81+
if (se.isSingleton())
82+
{ BExpression argp = se.getElement(0);
83+
// Vector vv = new Vector();
84+
BApplyExpression newapp = new BApplyExpression(func,argp);
85+
newapp.setMultiplicity(multiplicity);
86+
// vv.add(newapp);
87+
// return new BSetExpression(vv);
88+
return newapp;
89+
} // f(set) is never meant for real in UML-RSDS
90+
}
91+
return
92+
new BApplyExpression(func,sarg);
93+
}
94+
95+
public BExpression substituteEq(String oldE, BExpression newE)
96+
{ if (oldE.equals(toString()))
97+
{ return newE; }
98+
BExpression argE = arg.substituteEq(oldE,newE);
99+
BExpression funcE = func.substituteEq(oldE,newE);
100+
if (funcE instanceof BBasicExpression) {}
101+
else
102+
{ funcE.setBrackets(true); }
103+
BExpression res = new BApplyExpression(funcE,argE);
104+
res.setMultiplicity(multiplicity);
105+
return res;
106+
}
107+
108+
public String toString()
109+
{ if (function == null)
110+
{ return func + "(" + arg + ")"; }
111+
return function + "(" + arg + ")";
112+
}
113+
}
114+
2.2 KB
Binary file not shown.

version24/BApplySetExpression.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import java.util.Vector;
2+
3+
public class BApplySetExpression extends BExpression
4+
{ private String function;
5+
private BExpression func;
6+
private BExpression arg;
7+
8+
public BApplySetExpression(String f, BExpression a)
9+
{ function = f;
10+
func = new BBasicExpression(f);
11+
arg = a;
12+
}
13+
14+
public BApplySetExpression(BExpression f, BExpression a)
15+
{ func = f;
16+
function = "" + f;
17+
arg = a;
18+
}
19+
20+
public Vector rd()
21+
{ Vector res = new Vector();
22+
res.addAll(func.rd());
23+
return VectorUtil.union(res,arg.rd());
24+
}
25+
26+
public boolean setValued()
27+
{ return true; }
28+
29+
public void setMultiplicity(int m)
30+
{ multiplicity = m; }
31+
32+
public BExpression simplify()
33+
{ BExpression sa = arg.simplify();
34+
if (sa instanceof BSetExpression)
35+
{ BSetExpression se = (BSetExpression) sa;
36+
if (se.isSingleton())
37+
{ BExpression arg1 = se.getElement(0);
38+
Vector rr = new Vector();
39+
if (arg1.setValued())
40+
{ // f[{arg1}] is f[arg]
41+
BApplySetExpression newaps = new BApplySetExpression(func,arg1);
42+
newaps.setMultiplicity(multiplicity);
43+
if (multiplicity == ModelElement.ONE)
44+
{ return newaps; }
45+
else
46+
{ return new BUnaryExpression("union",newaps); }
47+
} // else, its {f(arg1)}
48+
BApplyExpression ap =
49+
new BApplyExpression(func,arg1);
50+
ap.setMultiplicity(multiplicity);
51+
// if (multiplicity == ModelElement.ONE)
52+
// {
53+
rr.add(ap);
54+
return new BSetExpression(rr);
55+
// } // or just ap if setValued anyway
56+
// else
57+
// { return ap; }
58+
}
59+
else if (se.isEmpty())
60+
{ return new BSetExpression(new Vector()); }
61+
}
62+
BApplySetExpression res = new BApplySetExpression(func,sa);
63+
res.setMultiplicity(multiplicity);
64+
return res;
65+
}
66+
67+
public String toString()
68+
{ return function + "[" + arg + "]"; }
69+
70+
public BExpression substituteEq(String oldE, BExpression newE)
71+
{ if (oldE.equals(toString()))
72+
{ return newE; }
73+
BExpression argE = arg.substituteEq(oldE,newE);
74+
BExpression res = new BApplySetExpression(function,argE);
75+
res.setMultiplicity(multiplicity);
76+
return res;
77+
}
78+
} // and in func
79+

version24/BAssignStatement.class

2.19 KB
Binary file not shown.

version24/BAssignStatement.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import java.util.Vector;
2+
3+
/* Copyright K. Lano 2003-2013
4+
Package: B AMN
5+
*/
6+
7+
public class BAssignStatement extends BStatement
8+
{ private BExpression lhs;
9+
private BExpression rhs;
10+
11+
public BAssignStatement(BExpression l, BExpression r)
12+
{ lhs = l;
13+
rhs = r;
14+
}
15+
16+
public BExpression getRhs()
17+
{ return rhs; }
18+
19+
public BExpression getLhs()
20+
{ return lhs; }
21+
22+
public String toString()
23+
{ return lhs + " := " + rhs; }
24+
25+
public BStatement substituteEq(String oldE, BExpression newE)
26+
{ // BExpression nlhs = lhs.substituteEq(oldE,newE);
27+
BExpression nrhs = rhs.substituteEq(oldE,newE);
28+
return new BAssignStatement(lhs,nrhs);
29+
}
30+
31+
public BStatement simplify()
32+
{ // BExpression nlhs = lhs.substituteEq(oldE,newE);
33+
BExpression nrhs = rhs.simplify();
34+
return new BAssignStatement(lhs,nrhs);
35+
}
36+
37+
public Vector wr()
38+
{ Vector res = new Vector();
39+
40+
if (lhs instanceof BBasicExpression)
41+
{ res.add(lhs + "");
42+
return res;
43+
}
44+
if (lhs instanceof BApplyExpression)
45+
{ BApplyExpression bae = (BApplyExpression) lhs;
46+
String f = bae.getFunction();
47+
res.add(f);
48+
return res;
49+
}
50+
return res;
51+
}
52+
53+
public Vector rd()
54+
{ Vector res = new Vector();
55+
res.addAll(rhs.rd());
56+
57+
if (lhs instanceof BBasicExpression)
58+
{ return res; }
59+
60+
if (lhs instanceof BApplyExpression)
61+
{ BApplyExpression bae = (BApplyExpression) lhs;
62+
BExpression arg = bae.getArgument();
63+
res = VectorUtil.union(res,arg.rd());
64+
return res;
65+
}
66+
return res;
67+
}
68+
69+
public BStatement seq2parallel()
70+
{ return this; }
71+
72+
public BStatement normalise()
73+
{ if (lhs instanceof BBasicExpression)
74+
{ return this; }
75+
if (lhs instanceof BApplyExpression)
76+
{ BApplyExpression bae = (BApplyExpression) lhs;
77+
String f = bae.getFunction();
78+
BExpression arg = bae.getArgument();
79+
80+
BExpression maplet =
81+
new BBinaryExpression("|->",arg,rhs);
82+
BSetExpression bse =
83+
new BSetExpression();
84+
bse.addElement(maplet);
85+
BExpression newlhs =
86+
new BBasicExpression(f);
87+
BExpression newrhs =
88+
new BBinaryExpression("<+",newlhs,bse);
89+
newrhs.setBrackets(true);
90+
return new BAssignStatement(newlhs,newrhs);
91+
}
92+
return this;
93+
}
94+
95+
}
96+

version24/BBasicExpression.class

1.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)