4 class AbstractInterferes {
5 Termination termination;
7 public AbstractInterferes(Termination t) {
12 /** Does performing the AbstractRepair ar satisfy (or falsify if satisfy=false)
15 static public boolean interfereswithrule(AbstractRepair ar, Rule r, boolean satisfy) {
17 boolean mayremove=false;
18 switch (ar.getType()) {
19 case AbstractRepair.ADDTOSET:
20 case AbstractRepair.ADDTORELATION:
21 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
25 case AbstractRepair.REMOVEFROMSET:
26 case AbstractRepair.REMOVEFROMRELATION:
27 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
31 case AbstractRepair.MODIFYRELATION:
32 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
34 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
40 throw new Error("Unrecognized Abstract Repair");
44 drule=r.getDNFGuardExpr();
46 drule=r.getDNFNegGuardExpr();
48 for(int i=0;i<drule.size();i++) {
49 RuleConjunction rconj=drule.get(i);
50 for(int j=0;j<rconj.size();j++) {
51 DNFExpr dexpr=rconj.get(j);
52 Expr expr=dexpr.getExpr();
53 if (expr.usesDescriptor(ar.getDescriptor())) {
55 if ((mayadd&&!dexpr.getNegation())||(mayremove&&dexpr.getNegation()))
63 /** This method is designed to check that modifying a relation
64 * doesn't violate a relation well-formedness constraint
65 * (ie. [forall <a,b> in R], a in S1 and b in S2; */
67 public boolean checkrelationconstraint(AbstractRepair ar, Constraint c) {
68 if (c.numQuantifiers()==1&&
69 (c.getQuantifier(0) instanceof RelationQuantifier)) {
70 RelationQuantifier rq=(RelationQuantifier)c.getQuantifier(0);
71 if (rq.getRelation()==ar.getDescriptor()) {
72 Hashtable ht=new Hashtable();
73 if (ar.getDomainSet()!=null)
74 ht.put(rq.x,ar.getDomainSet());
75 if (ar.getRangeSet()!=null)
76 ht.put(rq.y,ar.getRangeSet());
77 DNFConstraint dconst=c.dnfconstraint;
79 for(int i=0;i<dconst.size();i++) {
80 Conjunction conj=dconst.get(i);
82 for(int j=0;j<conj.size();j++) {
83 DNFPredicate dpred=conj.get(j);
84 Predicate p=dpred.getPredicate();
85 if ((p instanceof InclusionPredicate)&&(!dpred.isNegated())) {
86 InclusionPredicate ip=(InclusionPredicate)p;
87 if (ip.expr instanceof VarExpr&&
88 ip.setexpr.getDescriptor() instanceof SetDescriptor) {
89 VarDescriptor vd=((VarExpr)ip.expr).getVar();
90 if (ht.containsKey(vd)) {
91 SetDescriptor td=(SetDescriptor)ip.setexpr.getDescriptor();
92 SetDescriptor s=(SetDescriptor)ht.get(vd);
108 /** Check to see if performing the repair ar on repair_c does not
109 * inferere with interfere_c. Returns true if there is no
112 public boolean interferemodifies(AbstractRepair ar, Constraint repair_c, DNFPredicate interfere_pred, Constraint interfere_c) {
113 DNFConstraint precondition=repair_c.getDNFConstraint().not();
114 if (repair_c.numQuantifiers()!=1||
115 interfere_c.numQuantifiers()!=1||
116 !(repair_c.getQuantifier(0) instanceof SetQuantifier)||
117 !(interfere_c.getQuantifier(0) instanceof SetQuantifier)||
118 ((SetQuantifier)repair_c.getQuantifier(0)).getSet()!=((SetQuantifier)interfere_c.getQuantifier(0)).getSet())
121 Hashtable mapping=new Hashtable();
122 mapping.put(((SetQuantifier)repair_c.getQuantifier(0)).getVar(),
123 ((SetQuantifier)interfere_c.getQuantifier(0)).getVar());
125 if (ar.getType()!=AbstractRepair.MODIFYRELATION||
126 !(ar.getPredicate().getPredicate() instanceof ExprPredicate)||
127 !(interfere_pred.getPredicate() instanceof ExprPredicate))
129 Expr e=((ExprPredicate)interfere_pred.getPredicate()).expr;
130 Expr leftside=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).left;
131 Set relationset=e.useDescriptor(ar.getDescriptor());
132 for(Iterator relit=relationset.iterator();relit.hasNext();) {
133 Expr e2=(Expr)relit.next();
134 if (!leftside.equals(mapping,e2))
137 /* Prune precondition using any ar's in the same conjunction */
138 adjustcondition(precondition, ar);
139 Conjunction conj=findConjunction(repair_c.getDNFConstraint(),ar.getPredicate());
140 for(int i=0;i<conj.size();i++) {
141 DNFPredicate dp=conj.get(i);
142 Set s=(Set)termination.predtoabstractmap.get(dp);
143 for(Iterator it=s.iterator();it.hasNext();) {
144 GraphNode gn=(GraphNode)it.next();
145 TermNode tn=(TermNode)gn.getOwner();
146 AbstractRepair dp_ar=tn.getAbstract();
147 adjustcondition(precondition, dp_ar);
150 /* We now have precondition after interference */
151 if (precondition.size()==0)
153 DNFConstraint infr_const=interfere_c.getDNFConstraint();
156 for(int i=0;i<infr_const.size();i++) {
157 Conjunction infr_conj=infr_const.get(i);
158 for(int j=0;j<infr_conj.size();j++) {
159 DNFPredicate infr_dp=infr_conj.get(j);
161 for(int i2=0;i2<precondition.size();i2++) {
162 Conjunction pre_conj=precondition.get(i2);
163 for(int j2=0;j2<pre_conj.size();j2++) {
164 DNFPredicate pre_dp=pre_conj.get(j2);
165 if (checkPreEnsures(pre_dp,infr_dp,mapping))
166 continue next_pre_conj;
169 continue next_conj; /* The precondition doesn't ensure this conjunction is true */
172 return true; /*Found a conjunction that must be
173 true...therefore the precondition
174 guarantees that the second constraint is
175 always true after repair*/
180 static private Conjunction findConjunction(DNFConstraint cons, DNFPredicate dp) {
181 for(int i=0;i<cons.size();i++) {
182 Conjunction conj=cons.get(i);
183 for(int j=0;j<conj.size();j++) {
184 DNFPredicate curr_dp=conj.get(j);
189 throw new Error("Not found");
192 /** This method removes predicates that the abstract repair may
195 private void adjustcondition(DNFConstraint precond, AbstractRepair ar) {
196 HashSet conjremove=new HashSet();
197 for(int i=0;i<precond.size();i++) {
198 Conjunction conj=precond.get(i);
199 HashSet toremove=new HashSet();
200 for(int j=0;j<conj.size();j++) {
201 DNFPredicate dp=conj.get(j);
202 if (interfereswithpredicate(ar,dp)) {
203 /* Remove dp from precond */
207 conj.predicates.removeAll(toremove);
209 conjremove.add(conj);
211 precond.conjunctions.removeAll(conjremove);
214 private boolean checkPreEnsures(DNFPredicate pre_dp, DNFPredicate infr_dp, Hashtable mapping) {
215 if (pre_dp.isNegated()==infr_dp.isNegated()&&(pre_dp.getPredicate() instanceof ExprPredicate)&&
216 (infr_dp.getPredicate() instanceof ExprPredicate)) {
217 if (((ExprPredicate)pre_dp.getPredicate()).expr.equals(mapping, ((ExprPredicate)infr_dp.getPredicate()).expr))
220 if ((!pre_dp.isNegated())&&infr_dp.isNegated()&&(pre_dp.getPredicate() instanceof ExprPredicate)&&
221 (infr_dp.getPredicate() instanceof ExprPredicate)) {
222 ExprPredicate pre_ep=(ExprPredicate)pre_dp.getPredicate();
223 ExprPredicate infr_ep=(ExprPredicate)infr_dp.getPredicate();
224 if (pre_ep.getType()==ExprPredicate.COMPARISON&&
225 infr_ep.getType()==ExprPredicate.COMPARISON&&
226 pre_ep.isRightInt()&&
227 infr_ep.isRightInt()&&
228 pre_ep.rightSize()!=infr_ep.rightSize()&&
229 pre_ep.getOp()==Opcode.EQ&&
230 infr_ep.getOp()==Opcode.EQ) {
231 if (((OpExpr)pre_ep.expr).left.equals(mapping,((OpExpr)infr_ep.expr).left))
238 /** This method checks whether a modify relation abstract repair
239 * to satisfy ar may violate dp. It returns true if there is no
242 private boolean interferemodifies(DNFPredicate ar,DNFPredicate dp) {
243 boolean neg1=ar.isNegated();
244 Opcode op1=((ExprPredicate)ar.getPredicate()).getOp();
245 Expr rexpr1=((OpExpr)((ExprPredicate)ar.getPredicate()).expr).right;
246 Expr lexpr1=((OpExpr)((ExprPredicate)ar.getPredicate()).expr).left;
247 RelationDescriptor updated_des=(RelationDescriptor)((ExprPredicate)ar.getPredicate()).getDescriptor();
249 boolean neg2=dp.isNegated();
250 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
251 Expr rexpr2=((OpExpr)((ExprPredicate)dp.getPredicate()).expr).right;
252 Expr lexpr2=((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left;
254 /* Translate the opcodes */
255 op1=Opcode.translateOpcode(neg1,op1);
256 op2=Opcode.translateOpcode(neg2,op2);
258 if (((op1==Opcode.EQ)||(op1==Opcode.GE)||(op1==Opcode.LE))&&
259 ((op2==Opcode.EQ)||(op2==Opcode.GE)||(op2==Opcode.LE))&&
260 !rexpr2.usesDescriptor(updated_des)) {
261 Hashtable varmap=new Hashtable();
265 boolean initialrelation=true;
266 boolean onetoone=true;
268 if ((l1 instanceof VarExpr)&&
269 (l2 instanceof VarExpr)) {
270 VarDescriptor vd1=((VarExpr)l1).getVar();
271 VarDescriptor vd2=((VarExpr)l2).getVar();
274 } else if ((l1 instanceof RelationExpr)&&
275 (l2 instanceof RelationExpr)) {
276 RelationExpr re1=(RelationExpr)l1;
277 RelationExpr re2=(RelationExpr)l2;
278 if (re1.getRelation()!=re2.getRelation()||
279 re1.inverted()!=re2.inverted())
282 if (!initialrelation) {
284 ConstraintDependence.rulesensurefunction(termination.state, re1.getRelation(),re1.getExpr().getSet(),!re1.inverted(),true)||
285 ConstraintDependence.constraintsensurefunction(termination.state, re1.getRelation(),re1.getExpr().getSet(),!re1.inverted(),true)))
287 //need check one-to-one property here
288 } else initialrelation=false;
291 } else return false; // bad match
293 Set freevars=rexpr1.freeVars();
295 for(Iterator it=freevars.iterator();it.hasNext();) {
296 VarDescriptor vd=(VarDescriptor)it.next();
298 continue; //globals are fine
299 else if (varmap.containsKey(vd)&&onetoone) //the mapped variable is fine if we have a 1-1 mapping
301 else if (termination.maxsize.getsize(vd.getSet())==1)
305 return rexpr1.equals(varmap,rexpr2);
310 /** Returns true if performing the AbstractRepair ar may falsify
313 public boolean interfereswithpredicate(AbstractRepair ar, DNFPredicate dp) {
314 if ((ar.getDescriptor()!=dp.getPredicate().getDescriptor()) &&
315 // ((ar.getDescriptor() instanceof SetDescriptor)||
316 // If the second predicate uses the size of the set, modifying the set size could falsify it...
317 !dp.getPredicate().usesDescriptor(ar.getDescriptor()))
322 // If the update changes something in the middle of a size
323 // expression, it interferes with it.
324 if ((dp.getPredicate() instanceof ExprPredicate)&&
325 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)&&
326 (((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr instanceof ImageSetExpr)&&
327 ((ImageSetExpr)((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr).isimageset&&
328 ((ImageSetExpr)((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr).ise.usesDescriptor(ar.getDescriptor())) {
332 // If the update changes something in the middle of a
333 // comparison expression, it interferes with it.
334 if ((dp.getPredicate() instanceof ExprPredicate)&&
335 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)&&
336 (((RelationExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).getExpr().usesDescriptor(ar.getDescriptor()))) {
340 /* This if handles all the c comparisons in the paper */
341 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
342 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
343 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
344 (dp.getPredicate() instanceof ExprPredicate)&&
345 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
346 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
347 boolean neg1=ar.getPredicate().isNegated();
348 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
349 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
350 boolean neg2=dp.isNegated();
351 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
352 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
353 op1=Opcode.translateOpcode(neg1,op1);
354 op2=Opcode.translateOpcode(neg2,op2);
356 if ((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE) {
358 if((op1==Opcode.EQ)||(op1==Opcode.GE))
360 if((op1==Opcode.GT)||(op1==Opcode.NE))
363 if (((op2==Opcode.EQ)&&(size1a==size2))||
364 ((op2==Opcode.NE)&&(size1a!=size2))||
367 ((op2==Opcode.LE)&&(size1a<=size2))||
368 ((op2==Opcode.LT)&&(size1a<size2)))
373 /* This if handles all the c comparisons in the paper */
374 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
375 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
376 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
377 (dp.getPredicate() instanceof ExprPredicate)&&
378 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
379 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
380 boolean neg1=ar.getPredicate().isNegated();
381 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
382 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
384 op1=Opcode.translateOpcode(neg1,op1);
386 if ((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE) {
388 if((op1==Opcode.EQ)||(op1==Opcode.GE))
390 if((op1==Opcode.GT)||(op1==Opcode.NE))
397 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
398 (ar.getType()==AbstractRepair.MODIFYRELATION)&&
399 (dp.getPredicate() instanceof ExprPredicate)&&
400 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
401 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
404 boolean neg2=dp.isNegated();
405 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
406 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
408 op2=Opcode.translateOpcode(neg2,op2);
410 if (((op2==Opcode.EQ)&&(size1==size2))||
411 ((op2==Opcode.NE)&&(size1!=size2))||
412 ((op2==Opcode.GE)&&(size1>=size2))||
413 ((op2==Opcode.GT)&&(size1>size2))||
414 ((op2==Opcode.LE)&&(size1<=size2))||
415 ((op2==Opcode.LT)&&(size1<size2)))
419 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
420 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
421 (dp.getPredicate() instanceof ExprPredicate)&&
422 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
423 boolean neg2=dp.isNegated();
424 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
425 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
427 op2=Opcode.translateOpcode(neg2,op2);
429 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
432 ((op2==Opcode.LT&&size2>maxsize)||
433 (op2==Opcode.LE&&size2>=maxsize)||
434 (op2==Opcode.EQ&&size2>=maxsize)))
437 if (((op2==Opcode.NE)&&(size2==0))||
444 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
445 (ar.getType()==AbstractRepair.MODIFYRELATION)&&
446 (dp.getPredicate() instanceof ExprPredicate)&&
447 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
448 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
450 boolean neg1=ar.getPredicate().isNegated();
451 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
452 boolean isInt1=((ExprPredicate)ar.getPredicate().getPredicate()).isRightInt();
453 int size1=isInt1?((ExprPredicate)ar.getPredicate().getPredicate()).rightSize():0;
454 Expr expr1=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).right;
457 boolean neg2=dp.isNegated();
458 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
459 boolean isInt2=((ExprPredicate)dp.getPredicate()).isRightInt();
460 int size2=isInt2?((ExprPredicate)dp.getPredicate()).rightSize():0;
461 Expr expr2=((OpExpr)((ExprPredicate)dp.getPredicate()).expr).right;
464 /* If the left sides of the comparisons are both from
465 different sets, the update is orthogonal to the expr dp */
467 Expr lexpr1=((RelationExpr)((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).getLeftExpr()).getExpr();
468 Expr lexpr2=((RelationExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).getLeftExpr()).getExpr();
469 SetDescriptor sd1=lexpr1.getSet();
470 SetDescriptor sd2=lexpr2.getSet();
471 if (termination.mutuallyexclusive(sd1,sd2))
475 /* Translate the opcodes */
476 op1=Opcode.translateOpcode(neg1,op1);
477 op2=Opcode.translateOpcode(neg2,op2);
479 /* Obvious cases which can't interfere */
480 if (((op1==Opcode.GT)||
485 if (((op1==Opcode.LT)||
491 if (interferemodifies(ar.getPredicate(),dp))
494 if (isInt1&&isInt2) {
495 if (((op1==Opcode.EQ)||(op1==Opcode.GE)||(op1==Opcode.LE))&&
496 ((op2==Opcode.EQ)||(op2==Opcode.GE)||(op2==Opcode.LE))&&
506 size1a++; /*FLAGNE this is current behavior for NE repairs */
512 if (((op1==Opcode.GE)||(op1==Opcode.GT))&&
513 ((op2==Opcode.LE)||(op2==Opcode.EQ)||(op2==Opcode.LT))&&
516 if (((op1==Opcode.LE)||(op1==Opcode.LT))&&
517 ((op2==Opcode.GE)||(op2==Opcode.EQ)||(op2==Opcode.GT))&&
520 if ((op1==Opcode.EQ)&&(op2==Opcode.EQ)&&
523 if ((op1==Opcode.EQ)&&
524 ((op2==Opcode.LE)||(op2==Opcode.LT))&&
527 if ((op1==Opcode.EQ)&&
528 ((op2==Opcode.GE)||(op2==Opcode.GT))&&
531 if (op2==Opcode.NE) /*FLAGNE this is current behavior for NE repairs */
534 if ((op1==Opcode.NE)&&
538 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
539 ((op2==Opcode.GT)||(op2==Opcode.GE))&&
542 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
543 ((op2==Opcode.LT)||(op2==Opcode.LE))&&
548 /* This handles all the c comparisons in the paper */
549 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
550 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
551 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
552 (dp.getPredicate() instanceof ExprPredicate)&&
553 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
554 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
555 boolean neg1=ar.getPredicate().isNegated();
556 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
557 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
558 boolean neg2=dp.isNegated();
559 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
560 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
561 /* Translate the opcodes */
562 op1=Opcode.translateOpcode(neg1,op1);
563 op2=Opcode.translateOpcode(neg2,op2);
565 if (((op1==Opcode.EQ)||(op1==Opcode.LT)||op1==Opcode.LE)||(op1==Opcode.NE)) {
568 if((op1==Opcode.EQ)||(op1==Opcode.LE))
570 if((op1==Opcode.LT)||(op1==Opcode.NE))
573 if (((op2==Opcode.EQ)&&(size1a==size2))||
574 ((op2==Opcode.NE)&&(size1a!=size2))||
577 ((op2==Opcode.GE)&&(size1a>=size2))||
578 ((op2==Opcode.GT)&&(size1a>size2)))
583 /* This handles all the c comparisons in the paper */
584 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
585 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
586 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
587 (dp.getPredicate() instanceof ExprPredicate)&&
588 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
589 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
590 boolean neg1=ar.getPredicate().isNegated();
591 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
592 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
594 /* Translate the opcodes */
595 op1=Opcode.translateOpcode(neg1,op1);
597 if (((op1==Opcode.EQ)||(op1==Opcode.LT)||op1==Opcode.LE)||(op1==Opcode.NE)) {
600 if((op1==Opcode.EQ)||(op1==Opcode.LE))
602 if((op1==Opcode.LT)||(op1==Opcode.NE))
610 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
611 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
612 (dp.getPredicate() instanceof ExprPredicate)&&
613 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
614 boolean neg2=dp.isNegated();
615 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
616 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
617 op2=Opcode.translateOpcode(neg2,op2);
619 if (((op2==Opcode.EQ)&&(size2==0))||
624 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
625 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
626 (dp.getPredicate() instanceof InclusionPredicate)&&
627 (dp.isNegated()==false))
628 return false; /* Could only satisfy this predicate */
630 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
631 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
632 (dp.getPredicate() instanceof InclusionPredicate)&&
633 (dp.isNegated()==true))
634 return false; /* Could only satisfy this predicate */
638 /** Does the increase (or decrease) in scope of a model defintion
639 * rule represented by sn falsify the predicate dp. */
641 public boolean scopeinterfereswithpredicate(ScopeNode sn, DNFPredicate dp) {
642 if (!sn.getSatisfy()&&(sn.getDescriptor() instanceof SetDescriptor)) {
644 Set target=r.getInclusion().getTargetDescriptors();
646 for(int i=0;i<r.numQuantifiers();i++) {
647 Quantifier q=r.getQuantifier(i);
648 if (q instanceof SetQuantifier) {
649 SetQuantifier sq=(SetQuantifier) q;
650 if (target.contains(sq.getSet())) {
657 sn.getDescriptor()==dp.getPredicate().getDescriptor()&&
658 (dp.getPredicate() instanceof ExprPredicate)&&
659 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
660 boolean neg=dp.isNegated();
661 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
662 int size=((ExprPredicate)dp.getPredicate()).rightSize();
663 op=Opcode.translateOpcode(neg,op);
665 if ((op==Opcode.GE)&&
666 ((size==0)||(size==1)))
668 if ((op==Opcode.GT)&&
673 return interferes(sn.getDescriptor(), sn.getSatisfy(),dp);
676 /** Does increasing (or decreasing if satisfy=false) the size of
677 * the set or relation des falsify the predicate dp. */
679 private boolean interferes(Descriptor des, boolean satisfy, DNFPredicate dp) {
680 if ((des!=dp.getPredicate().getDescriptor()) &&
681 //((des instanceof SetDescriptor)||
682 !dp.getPredicate().usesDescriptor(des))//)
685 /* This if handles all the c comparisons in the paper */
686 if (des==dp.getPredicate().getDescriptor()&&
688 (dp.getPredicate() instanceof ExprPredicate)&&
689 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
690 boolean neg2=dp.isNegated();
691 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
692 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
693 op2=Opcode.translateOpcode(neg2,op2);
696 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
699 ((op2==Opcode.LT&&size2>maxsize)||
700 (op2==Opcode.LE&&size2>=maxsize)||
701 (op2==Opcode.EQ&&size2>=maxsize)))
704 if ((op2==Opcode.GE)||
706 (op2==Opcode.NE)&&(size2==0))
710 /* This if handles all the c comparisons in the paper */
711 if (des==dp.getPredicate().getDescriptor()&&
713 (dp.getPredicate() instanceof ExprPredicate)&&
714 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
715 boolean neg2=dp.isNegated();
716 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
717 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
718 op2=Opcode.translateOpcode(neg2,op2);
720 if (((op2==Opcode.EQ)&&(size2==0))||
726 if ((des==dp.getPredicate().getDescriptor())&&
728 (dp.getPredicate() instanceof InclusionPredicate)&&
729 (dp.isNegated()==false))
730 return false; /* Could only satisfy this predicate */
732 if ((des==dp.getPredicate().getDescriptor())&&
734 (dp.getPredicate() instanceof InclusionPredicate)&&
735 (dp.isNegated()==true))
736 return false; /* Could only satisfy this predicate */
741 /** This method test whether satisfying (or falsifying depending
742 * on the flag satisfy) a rule that adds an object(or tuple) to
743 * the set(or relation) descriptor may increase (or decrease
744 * depending on the flag satisfyrule) the scope of a constraint or
745 * model defintion rule r. */
747 static private boolean interferesquantifier(Descriptor des, boolean satisfy, Quantifiers r, boolean satisfyrule) {
748 for(int i=0;i<r.numQuantifiers();i++) {
749 Quantifier q=r.getQuantifier(i);
750 if (q instanceof RelationQuantifier||q instanceof SetQuantifier) {
751 if (q.getRequiredDescriptors().contains(des)&&(satisfy==satisfyrule))
753 } else if (q instanceof ForQuantifier) {
754 if (q.getRequiredDescriptors().contains(des))
756 } else throw new Error("Unrecognized Quantifier");
761 static public boolean interferesquantifier(AbstractRepair ar, Quantifiers q) {
762 if (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)
763 return interferesquantifier(ar.getDescriptor(),true,q,true);
767 static public boolean interfereswithquantifier(Descriptor des, boolean satisfy, Quantifiers q) {
768 return interferesquantifier(des, satisfy, q,true);
771 static public boolean interfereswithrule(Descriptor des, boolean satisfy, Rule r, boolean satisfyrule) {
772 if (interferesquantifier(des,satisfy,r,satisfyrule))
775 DNFRule drule=r.getDNFGuardExpr();
776 for(int i=0;i<drule.size();i++) {
777 RuleConjunction rconj=drule.get(i);
778 for(int j=0;j<rconj.size();j++) {
779 DNFExpr dexpr=rconj.get(j);
780 Expr expr=dexpr.getExpr();
781 boolean negated=dexpr.getNegation();
789 boolean satisfiesrule=(satisfy^negated);/*XOR of these */
790 if (satisfiesrule==satisfyrule) {
791 /* Effect is the one being tested for */
792 /* Only expr's to be concerned with are TupleOfExpr and
794 if (expr.getRequiredDescriptors().contains(des)) {
795 if (((expr instanceof ElementOfExpr)||
796 (expr instanceof TupleOfExpr))&&
797 (expr.getRequiredDescriptors().size()==1))
800 throw new Error("Unrecognized EXPR");