4 class AbstractInterferes {
5 Termination termination;
7 public AbstractInterferes(Termination t) {
11 /** Does performing the AbstractRepair ar satisfy (or falsify if satisfy=false)
13 static public boolean interferes(AbstractRepair ar, Rule r, boolean satisfy) {
15 boolean mayremove=false;
16 switch (ar.getType()) {
17 case AbstractRepair.ADDTOSET:
18 case AbstractRepair.ADDTORELATION:
19 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
23 case AbstractRepair.REMOVEFROMSET:
24 case AbstractRepair.REMOVEFROMRELATION:
25 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
29 case AbstractRepair.MODIFYRELATION:
30 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
32 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
38 throw new Error("Unrecognized Abstract Repair");
42 drule=r.getDNFGuardExpr();
44 drule=r.getDNFNegGuardExpr();
46 for(int i=0;i<drule.size();i++) {
47 RuleConjunction rconj=drule.get(i);
48 for(int j=0;j<rconj.size();j++) {
49 DNFExpr dexpr=rconj.get(j);
50 Expr expr=dexpr.getExpr();
51 if (expr.usesDescriptor(ar.getDescriptor())) {
53 if ((mayadd&&!dexpr.getNegation())||(mayremove&&dexpr.getNegation()))
61 /** Does performing the AbstractRepair ar falsify the predicate dp */
63 public boolean interferes(AbstractRepair ar, DNFPredicate dp) {
64 if ((ar.getDescriptor()!=dp.getPredicate().getDescriptor()) &&
65 ((ar.getDescriptor() instanceof SetDescriptor)||
66 !dp.getPredicate().usesDescriptor((RelationDescriptor)ar.getDescriptor())))
69 /* This if handles all the c comparisons in the paper */
70 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
71 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
72 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
73 (dp.getPredicate() instanceof ExprPredicate)&&
74 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
75 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
76 boolean neg1=ar.getPredicate().isNegated();
77 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
78 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
79 boolean neg2=dp.isNegated();
80 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
81 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
82 op1=Opcode.translateOpcode(neg1,op1);
83 op2=Opcode.translateOpcode(neg2,op2);
85 if ((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE) {
87 if((op1==Opcode.EQ)||(op1==Opcode.GE))
89 if((op1==Opcode.GT)||(op1==Opcode.NE))
92 if (((op2==Opcode.EQ)&&(size1a==size2))||
93 ((op2==Opcode.NE)&&(size1a!=size2))||
96 ((op2==Opcode.LE)&&(size1a<=size2))||
97 ((op2==Opcode.LT)&&(size1a<size2)))
102 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
103 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
104 (dp.getPredicate() instanceof ExprPredicate)&&
105 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
106 boolean neg2=dp.isNegated();
107 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
108 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
110 op2=Opcode.translateOpcode(neg2,op2);
112 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
115 ((op2==Opcode.LT&&size2>maxsize)||
116 (op2==Opcode.LE&&size2>=maxsize)||
117 (op2==Opcode.EQ&&size2>=maxsize)))
120 if (((op2==Opcode.NE)&&(size2==0))||
126 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
127 (ar.getType()==AbstractRepair.MODIFYRELATION)&&
128 (dp.getPredicate() instanceof ExprPredicate)&&
129 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
130 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
132 boolean neg1=ar.getPredicate().isNegated();
133 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
134 boolean isInt1=((ExprPredicate)ar.getPredicate().getPredicate()).isRightInt();
135 int size1=isInt1?((ExprPredicate)ar.getPredicate().getPredicate()).rightSize():0;
136 Expr expr1=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).right;
139 boolean neg2=dp.isNegated();
140 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
141 boolean isInt2=((ExprPredicate)dp.getPredicate()).isRightInt();
142 int size2=isInt2?((ExprPredicate)dp.getPredicate()).rightSize():0;
143 Expr expr2=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).right;
145 /* Translate the opcodes */
146 op1=Opcode.translateOpcode(neg1,op1);
147 op2=Opcode.translateOpcode(neg2,op2);
149 /* Obvious cases which can't interfere */
150 if (((op1==Opcode.GT)||
156 if (((op1==Opcode.LT)||
162 if (isInt1&&isInt2) {
163 if (((op1==Opcode.EQ)||(op1==Opcode.GE)||(op1==Opcode.LE))&&
164 ((op2==Opcode.EQ)||(op2==Opcode.GE)||(op2==Opcode.LE))&&
174 size1a++; /*FLAGNE this is current behavior for NE repairs */
181 if (((op1==Opcode.GE)||(op1==Opcode.GT))&&
182 ((op2==Opcode.LE)||(op2==Opcode.EQ)||(op2==Opcode.LT))&&
186 if (((op1==Opcode.LE)||(op1==Opcode.LT))&&
187 ((op2==Opcode.GE)||(op2==Opcode.EQ)||(op2==Opcode.GT))&&
191 if ((op1==Opcode.EQ)&&(op2==Opcode.EQ)&&
195 if ((op1==Opcode.EQ)&&
196 ((op2==Opcode.LE)||(op2==Opcode.LT))&&
200 if ((op1==Opcode.EQ)&&
201 ((op2==Opcode.GE)||(op2==Opcode.GT))&&
205 if (op2==Opcode.NE) /*FLAGNE this is current behavior for NE repairs */
209 if ((op1==Opcode.NE)&&
214 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
215 ((op2==Opcode.GT)||(op2==Opcode.GE))&&
219 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
220 ((op2==Opcode.LT)||(op2==Opcode.LE))&&
226 /* This handles all the c comparisons in the paper */
227 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
228 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
229 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
230 (dp.getPredicate() instanceof ExprPredicate)&&
231 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
232 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
233 boolean neg1=ar.getPredicate().isNegated();
234 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
235 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
236 boolean neg2=dp.isNegated();
237 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
238 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
239 /* Translate the opcodes */
240 op1=Opcode.translateOpcode(neg1,op1);
241 op2=Opcode.translateOpcode(neg2,op2);
243 if (((op1==Opcode.EQ)||(op1==Opcode.LT)||op1==Opcode.LE)||(op1==Opcode.NE)) {
246 if((op1==Opcode.EQ)||(op1==Opcode.LE))
248 if((op1==Opcode.LT)||(op1==Opcode.NE))
251 if (((op2==Opcode.EQ)&&(size1a==size2))||
252 ((op2==Opcode.NE)&&(size1a!=size2))||
255 ((op2==Opcode.GE)&&(size1a>=size2))||
256 ((op2==Opcode.GT)&&(size1a>size2)))
261 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
262 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
263 (dp.getPredicate() instanceof ExprPredicate)&&
264 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
265 boolean neg2=dp.isNegated();
266 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
267 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
268 op2=Opcode.translateOpcode(neg2,op2);
270 if (((op2==Opcode.EQ)&&(size2==0))||
276 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
277 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
278 (dp.getPredicate() instanceof InclusionPredicate)&&
279 (dp.isNegated()==false))
280 return false; /* Could only satisfy this predicate */
282 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
283 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
284 (dp.getPredicate() instanceof InclusionPredicate)&&
285 (dp.isNegated()==true))
286 return false; /* Could only satisfy this predicate */
291 /** Does the increase (or decrease) in scope of a model defintion rule represented by sn
292 * falsify the predicate dp */
294 public boolean interferes(ScopeNode sn, DNFPredicate dp) {
295 if (!sn.getSatisfy()&&(sn.getDescriptor() instanceof SetDescriptor)) {
297 Set target=r.getInclusion().getTargetDescriptors();
299 for(int i=0;i<r.numQuantifiers();i++) {
300 Quantifier q=r.getQuantifier(i);
301 if (q instanceof SetQuantifier) {
302 SetQuantifier sq=(SetQuantifier) q;
303 if (target.contains(sq.getSet())) {
310 sn.getDescriptor()==dp.getPredicate().getDescriptor()&&
311 (dp.getPredicate() instanceof ExprPredicate)&&
312 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
313 boolean neg=dp.isNegated();
314 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
315 int size=((ExprPredicate)dp.getPredicate()).rightSize();
316 op=Opcode.translateOpcode(neg,op);
318 if ((op==Opcode.GE)&&
319 ((size==0)||(size==1)))
321 if ((op==Opcode.GT)&&
326 return interferes(sn.getDescriptor(), sn.getSatisfy(),dp);
329 /** Does increasing (or decreasing if satisfy=false) the size of the set or relation des
330 * falsify the predicate dp */
332 public boolean interferes(Descriptor des, boolean satisfy, DNFPredicate dp) {
333 if ((des!=dp.getPredicate().getDescriptor()) &&
334 ((des instanceof SetDescriptor)||
335 !dp.getPredicate().usesDescriptor((RelationDescriptor)des)))
338 /* This if handles all the c comparisons in the paper */
339 if (des==dp.getPredicate().getDescriptor()&&
341 (dp.getPredicate() instanceof ExprPredicate)&&
342 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
343 boolean neg2=dp.isNegated();
344 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
345 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
346 op2=Opcode.translateOpcode(neg2,op2);
349 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
352 ((op2==Opcode.LT&&size2>maxsize)||
353 (op2==Opcode.LE&&size2>=maxsize)||
354 (op2==Opcode.EQ&&size2>=maxsize)))
357 if ((op2==Opcode.GE)||
359 (op2==Opcode.NE)&&(size2==0))
363 /* This if handles all the c comparisons in the paper */
364 if (des==dp.getPredicate().getDescriptor()&&
366 (dp.getPredicate() instanceof ExprPredicate)&&
367 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
368 boolean neg2=dp.isNegated();
369 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
370 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
371 op2=Opcode.translateOpcode(neg2,op2);
373 if (((op2==Opcode.EQ)&&(size2==0))||
379 if ((des==dp.getPredicate().getDescriptor())&&
381 (dp.getPredicate() instanceof InclusionPredicate)&&
382 (dp.isNegated()==false))
383 return false; /* Could only satisfy this predicate */
385 if ((des==dp.getPredicate().getDescriptor())&&
387 (dp.getPredicate() instanceof InclusionPredicate)&&
388 (dp.isNegated()==true))
389 return false; /* Could only satisfy this predicate */
394 static public boolean interferesquantifier(Descriptor des, boolean satisfy, Quantifiers r, boolean satisfyrule) {
395 for(int i=0;i<r.numQuantifiers();i++) {
396 Quantifier q=r.getQuantifier(i);
397 if (q instanceof RelationQuantifier||q instanceof SetQuantifier) {
398 if (q.getRequiredDescriptors().contains(des)&&(satisfy==satisfyrule))
400 } else if (q instanceof ForQuantifier) {
401 if (q.getRequiredDescriptors().contains(des))
403 } else throw new Error("Unrecognized Quantifier");
408 static public boolean interferes(AbstractRepair ar, Quantifiers q) {
409 if (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)
410 return interferesquantifier(ar.getDescriptor(),true,q,true);
414 static public boolean interferes(Descriptor des, boolean satisfy, Quantifiers q) {
415 return interferesquantifier(des, satisfy, q,true);
418 static public boolean interferes(Descriptor des, boolean satisfy, Rule r, boolean satisfyrule) {
419 if (interferesquantifier(des,satisfy,r,satisfyrule))
422 DNFRule drule=r.getDNFGuardExpr();
423 for(int i=0;i<drule.size();i++) {
424 RuleConjunction rconj=drule.get(i);
425 for(int j=0;j<rconj.size();j++) {
426 DNFExpr dexpr=rconj.get(j);
427 Expr expr=dexpr.getExpr();
428 boolean negated=dexpr.getNegation();
436 boolean satisfiesrule=(satisfy^negated);/*XOR of these */
437 if (satisfiesrule==satisfyrule) {
438 /* Effect is the one being tested for */
439 /* Only expr's to be concerned with are TupleOfExpr and
441 if (expr.getRequiredDescriptors().contains(des)) {
442 if (((expr instanceof ElementOfExpr)||
443 (expr instanceof TupleOfExpr))&&
444 (expr.getRequiredDescriptors().size()==1))
447 throw new Error("Unrecognized EXPR");