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