7 public class Termination {
9 Hashtable conjunctionmap;
11 HashSet abstractrepair;
12 HashSet abstractrepairadd;
15 HashSet consequencenodes;
18 Hashtable scopesatisfy;
19 Hashtable scopefalsify;
20 Hashtable consequence;
21 Hashtable abstractadd;
22 Hashtable abstractremove;
23 Hashtable conjtonodemap;
24 Hashtable predtoabstractmap;
26 ComputeMaxSize maxsize;
28 AbstractInterferes abstractinterferes;
29 ConcreteInterferes concreteinterferes;
30 ConstraintDependence constraintdependence;
32 ArrayAnalysis arrayanalysis;
35 public Termination(State state) {
37 conjunctions=new HashSet();
38 conjunctionmap=new Hashtable();
39 abstractrepair=new HashSet();
40 abstractrepairadd=new HashSet();
41 scopenodes=new HashSet();
42 scopesatisfy=new Hashtable();
43 scopefalsify=new Hashtable();
44 consequence=new Hashtable();
45 updatenodes=new HashSet();
46 consequencenodes=new HashSet();
47 abstractadd=new Hashtable();
48 abstractremove=new Hashtable();
49 conjtonodemap=new Hashtable();
50 predtoabstractmap=new Hashtable();
55 for(int i=0;i<state.vRules.size();i++)
56 System.out.println(state.vRules.get(i));
57 for(int i=0;i<state.vConstraints.size();i++)
58 System.out.println(state.vConstraints.get(i));
60 sources=new Sources(state);
61 maxsize=new ComputeMaxSize(state);
62 exactsize=new ExactSize(state);
63 arrayanalysis=new ArrayAnalysis(state,this);
65 abstractinterferes=new AbstractInterferes(this);
66 concreteinterferes=new ConcreteInterferes(this);
67 generateconjunctionnodes();
68 constraintdependence=new ConstraintDependence(state,this);
71 generaterepairnodes();
72 generatedatastructureupdatenodes();
73 generatecompensationnodes();
75 generateabstractedges();
77 generateupdateedges();
80 HashSet superset=new HashSet();
81 superset.addAll(conjunctions);
82 HashSet closureset=new HashSet();
84 GraphNode.computeclosure(superset,closureset);
86 GraphNode.DOTVisitor.visit(new FileOutputStream("graph.dot"),superset);
87 } catch (Exception e) {
92 generatedebuggraphs();
94 for(Iterator it=updatenodes.iterator();it.hasNext();) {
95 GraphNode gn=(GraphNode)it.next();
96 TermNode tn=(TermNode)gn.getOwner();
97 MultUpdateNode mun=tn.getUpdate();
98 System.out.println(gn.getTextLabel());
99 System.out.println(mun.toString());
101 GraphAnalysis ga=new GraphAnalysis(this);
102 removedset=ga.doAnalysis();
103 if (removedset==null) {
104 System.out.println("Can't generate terminating repair algorithm!");
108 System.out.println("Removing:");
109 for(Iterator it=removedset.iterator();it.hasNext();) {
110 GraphNode gn=(GraphNode)it.next();
111 System.out.println(gn.getTextLabel());
114 superset=new HashSet();
115 superset.addAll(conjunctions);
116 superset.removeAll(removedset);
117 GraphNode.computeclosure(superset,removedset);
119 GraphNode.DOTVisitor.visit(new FileOutputStream("graphfinal.dot"),superset);
120 } catch (Exception e) {
124 constraintdependence.traversedependences(this);
127 void generatedebuggraphs() {
128 for (int i=0;i<Compiler.debuggraphs.size();i++) {
129 DebugItem di=(DebugItem) Compiler.debuggraphs.get(i);
130 HashSet superset=new HashSet();
131 Constraint constr=(Constraint)state.vConstraints.get(di.constraintnum);
133 if (di.conjunctionnum==-1) {
134 superset.addAll((Set)conjunctionmap.get(constr));
136 DNFConstraint dnf=constr.dnfconstraint;
137 superset.add(conjtonodemap.get(dnf.get(di.conjunctionnum)));
140 GraphNode.boundedcomputeclosure(superset,null,di.depth);
142 GraphNode.DOTVisitor.visit(new FileOutputStream("graph"+di.constraintnum+"-"+di.depth+(di.conjunctionnum==-1?"":"-"+di.conjunctionnum)+".dot"),superset);
143 } catch (Exception e) {
151 /** This method generates a node for each conjunction in the DNF
152 * form of each constraint. It also converts the quantifiers into
153 * conjunctions also - constraints can be satisfied by removing
154 * items from the sets and relations they are quantified over */
156 void generateconjunctionnodes() {
157 Vector constraints=state.vConstraints;
158 // Constructs conjunction nodes
159 for(int i=0;i<constraints.size();i++) {
160 Constraint c=(Constraint)constraints.get(i);
161 DNFConstraint dnf=c.dnfconstraint;
162 for(int j=0;j<dnf.size();j++) {
163 TermNode tn=new TermNode(c,dnf.get(j));
164 GraphNode gn=new GraphNode("Conj"+i+"A"+j,
165 "Conj ("+i+","+j+") "+dnf.get(j).name()
167 conjunctions.add(gn);
168 if (!conjunctionmap.containsKey(c))
169 conjunctionmap.put(c,new HashSet());
170 ((Set)conjunctionmap.get(c)).add(gn);
171 conjtonodemap.put(dnf.get(j),gn);
173 // Construct quantifier "conjunction" nodes
174 for(int j=0;j<c.numQuantifiers();j++) {
175 Quantifier q=c.getQuantifier(j);
176 if (q instanceof SetQuantifier) {
177 SetQuantifier sq=(SetQuantifier)q;
178 VarExpr ve=new VarExpr(sq.getVar());
179 InclusionPredicate ip=new InclusionPredicate(ve,new SetExpr(sq.getSet()));
180 DNFConstraint dconst=new DNFConstraint(ip);
182 TermNode tn=new TermNode(c,dconst.get(0));
183 tn.setquantifiernode();
184 GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
185 "Conj ("+i+","+j+") "+dconst.get(0).name()
187 conjunctions.add(gn);
188 if (!conjunctionmap.containsKey(c))
189 conjunctionmap.put(c,new HashSet());
190 ((Set)conjunctionmap.get(c)).add(gn);
191 conjtonodemap.put(dconst.get(0),gn);
193 } else if (q instanceof RelationQuantifier) {
194 RelationQuantifier rq=(RelationQuantifier)q;
195 VarExpr ve=new VarExpr(rq.y);
196 InclusionPredicate ip=new InclusionPredicate(ve,new ImageSetExpr(rq.x,rq.getRelation()));
197 DNFConstraint dconst=new DNFConstraint(ip);
199 TermNode tn=new TermNode(c,dconst.get(0));
200 tn.setquantifiernode();
201 GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
202 "Conj ("+i+","+j+") "+dconst.get(0).name()
204 conjunctions.add(gn);
205 if (!conjunctionmap.containsKey(c))
206 conjunctionmap.put(c,new HashSet());
207 ((Set)conjunctionmap.get(c)).add(gn);
208 conjtonodemap.put(dconst.get(0),gn);
214 void generateupdateedges() {
215 for(Iterator updateiterator=updatenodes.iterator();updateiterator.hasNext();) {
216 GraphNode gn=(GraphNode)updateiterator.next();
217 TermNode tn=(TermNode)gn.getOwner();
218 MultUpdateNode mun=tn.getUpdate();
219 for(int i=0;i<mun.numUpdates();i++) {
220 UpdateNode un=mun.getUpdate(i);
221 for(int j=0;j<un.numUpdates();j++) {
222 Updates u=un.getUpdate(j);
223 if (u.getType()==Updates.ABSTRACT) {
224 Expr e=u.getLeftExpr();
225 boolean negated=u.negate;
226 if (e instanceof TupleOfExpr) {
227 TupleOfExpr toe=(TupleOfExpr)e;
229 GraphNode agn=(GraphNode)abstractremove.get(toe.relation);
230 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
233 GraphNode agn=(GraphNode)abstractadd.get(toe.relation);
234 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
237 } else if (e instanceof ElementOfExpr) {
238 ElementOfExpr eoe=(ElementOfExpr)e;
240 GraphNode agn=(GraphNode)abstractremove.get(eoe.set);
241 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
244 GraphNode agn=(GraphNode)abstractadd.get(eoe.set);
245 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
248 } else throw new Error("Unrecognized Abstract Update");
252 /* Cycle through the rules to look for possible conflicts */
253 for(int i=0;i<state.vRules.size();i++) {
254 Rule r=(Rule) state.vRules.get(i);
255 if (concreteinterferes.interferes(mun,r,true)) {
256 GraphNode scopenode=(GraphNode)scopesatisfy.get(r);
257 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
260 if (concreteinterferes.interferes(mun,r,false)) {
261 GraphNode scopenode=(GraphNode)scopefalsify.get(r);
262 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
269 void generateabstractedges() {
270 for(Iterator absiterator=abstractrepair.iterator();absiterator.hasNext();) {
271 GraphNode gn=(GraphNode)absiterator.next();
272 TermNode tn=(TermNode)gn.getOwner();
273 AbstractRepair ar=(AbstractRepair)tn.getAbstract();
275 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
276 GraphNode gn2=(GraphNode)conjiterator.next();
277 TermNode tn2=(TermNode)gn2.getOwner();
278 Conjunction conj=tn2.getConjunction();
279 Constraint cons=tn2.getConstraint();
280 /* See if this is a relation wellformedness constraint
281 that is trivially satisfied. */
282 if (abstractinterferes.checkrelationconstraint(ar, cons))
284 if (AbstractInterferes.interferesquantifier(ar,cons)) {
285 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
288 for(int i=0;i<conj.size();i++) {
289 DNFPredicate dp=conj.get(i);
290 if (getConstraint(gn)!=null&&
291 abstractinterferes.interferemodifies(ar,getConstraint(gn),dp,cons))
294 if (abstractinterferes.interfereswithpredicate(ar,dp)) {
295 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
302 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
303 GraphNode gn2=(GraphNode)scopeiterator.next();
304 TermNode tn2=(TermNode)gn2.getOwner();
305 ScopeNode sn2=tn2.getScope();
306 if (AbstractInterferes.interfereswithrule(ar,sn2.getRule(),sn2.getSatisfy())) {
307 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
314 Constraint getConstraint(GraphNode gn) {
315 for(Iterator it=gn.inedges();it.hasNext();) {
316 GraphNode.Edge e=(GraphNode.Edge)it.next();
317 GraphNode gnsource=e.getSource();
318 TermNode tnsource=(TermNode)gnsource.getOwner();
319 if (tnsource.getType()==TermNode.CONJUNCTION) {
320 return tnsource.getConstraint();
326 void generatescopenodes() {
327 for(int i=0;i<state.vRules.size();i++) {
328 Rule r=(Rule) state.vRules.get(i);
329 ScopeNode satisfy=new ScopeNode(r,true);
330 TermNode tnsatisfy=new TermNode(satisfy);
331 GraphNode gnsatisfy=new GraphNode("SatisfyRule"+i,tnsatisfy);
332 ConsequenceNode cnsatisfy=new ConsequenceNode();
333 TermNode ctnsatisfy=new TermNode(cnsatisfy);
334 GraphNode cgnsatisfy=new GraphNode("ConseqSatisfyRule"+i,ctnsatisfy);
335 consequence.put(satisfy,cgnsatisfy);
336 GraphNode.Edge esat=new GraphNode.Edge("consequencesatisfy"+i,cgnsatisfy);
337 gnsatisfy.addEdge(esat);
338 consequencenodes.add(cgnsatisfy);
339 scopesatisfy.put(r,gnsatisfy);
340 scopenodes.add(gnsatisfy);
342 ScopeNode falsify=new ScopeNode(r,false);
343 TermNode tnfalsify=new TermNode(falsify);
344 GraphNode gnfalsify=new GraphNode("FalsifyRule"+i,tnfalsify);
345 ConsequenceNode cnfalsify=new ConsequenceNode();
346 TermNode ctnfalsify=new TermNode(cnfalsify);
347 GraphNode cgnfalsify=new GraphNode("ConseqFalsifyRule"+i,ctnfalsify);
348 consequence.put(falsify,cgnfalsify);
349 GraphNode.Edge efals=new GraphNode.Edge("consequencefalsify"+i,cgnfalsify);
350 gnfalsify.addEdge(efals);
351 consequencenodes.add(cgnfalsify);
352 scopefalsify.put(r,gnfalsify);
353 scopenodes.add(gnfalsify);
357 void generatescopeedges() {
358 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
359 GraphNode gn=(GraphNode)scopeiterator.next();
360 TermNode tn=(TermNode)gn.getOwner();
361 ScopeNode sn=tn.getScope();
363 /* Interference edges with conjunctions */
364 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
365 GraphNode gn2=(GraphNode)conjiterator.next();
366 TermNode tn2=(TermNode)gn2.getOwner();
367 Conjunction conj=tn2.getConjunction();
368 Constraint constr=tn2.getConstraint();
369 for(int i=0;i<conj.size();i++) {
370 DNFPredicate dp=conj.get(i);
371 if (abstractinterferes.scopeinterfereswithpredicate(sn,dp)||
372 AbstractInterferes.interfereswithquantifier(sn.getDescriptor(),sn.getSatisfy(),constr)) {
373 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
374 GraphNode gnconseq=(GraphNode)consequence.get(sn);
381 /* Now see if this could effect other model defintion rules */
382 for(int i=0;i<state.vRules.size();i++) {
383 Rule r=(Rule) state.vRules.get(i);
384 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,true)) {
385 GraphNode scopenode=(GraphNode)scopesatisfy.get(r);
386 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
387 GraphNode gnconseq=(GraphNode)consequence.get(sn);
390 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,false)) {
391 GraphNode scopenode=(GraphNode)scopefalsify.get(r);
392 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
393 GraphNode gnconseq=(GraphNode)consequence.get(sn);
400 /** This method generates the abstract repair nodes. */
401 void generaterepairnodes() {
402 /* Generate repairs of conjunctions */
403 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
404 GraphNode gn=(GraphNode)conjiterator.next();
405 TermNode tn=(TermNode)gn.getOwner();
406 Conjunction conj=tn.getConjunction();
408 for(int i=0;i<conj.size();i++) {
409 DNFPredicate dp=conj.get(i);
410 int[] array=dp.getPredicate().getRepairs(dp.isNegated(),this);
411 Descriptor d=dp.getPredicate().getDescriptor();
412 if ((dp.getPredicate() instanceof ExprPredicate)&&
413 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
414 boolean neg=dp.isNegated();
415 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
416 int size=((ExprPredicate)dp.getPredicate()).rightSize();
417 op=Opcode.translateOpcode(neg,op);
418 if (((size==1)&&(op==Opcode.EQ))||
419 ((size!=1)&&(op==Opcode.NE))||
420 ((size<=1)&&(op==Opcode.GE))||
421 ((size<1)&&(op==Opcode.GT))||
422 ((size>1)&&(op==Opcode.LT))||
423 ((size>=1)&&(op==Opcode.LE))) {
424 for(int i2=0;i2<conj.size();i2++) {
425 DNFPredicate dp2=conj.get(i2);
426 if ((dp2.getPredicate() instanceof ExprPredicate)&&
427 (((ExprPredicate)dp2.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
428 if (equivalent(((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr,
429 (RelationExpr)((OpExpr)((ExprPredicate)dp2.getPredicate()).expr).left))
430 continue loop; // comparison predicate ensure that size expr is true - no need to generate abstract repairs...
436 for(int j=0;j<array.length;j++) {
437 AbstractRepair ar=new AbstractRepair(dp,array[j],d,sources);
438 TermNode tn2=new TermNode(ar);
439 GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
440 GraphNode.Edge e=new GraphNode.Edge("abstract",gn2);
442 if (!predtoabstractmap.containsKey(dp))
443 predtoabstractmap.put(dp,new HashSet());
444 ((Set)predtoabstractmap.get(dp)).add(gn2);
445 abstractrepair.add(gn2);
449 /* Generate additional abstract repairs */
450 Vector setdescriptors=state.stSets.getAllDescriptors();
451 for(int i=0;i<setdescriptors.size();i++) {
452 SetDescriptor sd=(SetDescriptor)setdescriptors.get(i);
454 VarExpr ve=new VarExpr("DUMMY");
455 InclusionPredicate ip=new InclusionPredicate(ve,new SetExpr(sd));
456 DNFPredicate tp=new DNFPredicate(false,ip);
457 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTOSET, sd,sources);
458 TermNode tn=new TermNode(ar);
459 GraphNode gn=new GraphNode("AbstractAddSetRule"+i,tn);
460 if (!predtoabstractmap.containsKey(tp))
461 predtoabstractmap.put(tp,new HashSet());
462 ((Set)predtoabstractmap.get(tp)).add(gn);
463 abstractrepair.add(gn);
464 abstractrepairadd.add(gn);
465 abstractadd.put(sd,gn);
467 DNFPredicate tp2=new DNFPredicate(true,ip);
468 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMSET, sd,sources);
469 TermNode tn2=new TermNode(ar2);
470 GraphNode gn2=new GraphNode("AbstractRemSetRule"+i,tn2);
471 if (!predtoabstractmap.containsKey(tp2))
472 predtoabstractmap.put(tp2,new HashSet());
473 ((Set)predtoabstractmap.get(tp2)).add(gn2);
474 abstractrepair.add(gn2);
475 abstractrepairadd.add(gn2);
476 abstractremove.put(sd,gn2);
479 Vector relationdescriptors=state.stRelations.getAllDescriptors();
480 for(int i=0;i<relationdescriptors.size();i++) {
481 RelationDescriptor rd=(RelationDescriptor)relationdescriptors.get(i);
482 VarDescriptor vd1=new VarDescriptor("DUMMY1");
483 VarExpr ve2=new VarExpr("DUMMY2");
485 InclusionPredicate ip=new InclusionPredicate(ve2,new ImageSetExpr(vd1, rd));
487 DNFPredicate tp=new DNFPredicate(false,ip);
488 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTORELATION, rd,sources);
489 TermNode tn=new TermNode(ar);
490 GraphNode gn=new GraphNode("AbstractAddRelRule"+i,tn);
491 if (!predtoabstractmap.containsKey(tp))
492 predtoabstractmap.put(tp,new HashSet());
493 ((Set)predtoabstractmap.get(tp)).add(gn);
494 abstractrepair.add(gn);
495 abstractrepairadd.add(gn);
496 abstractadd.put(rd,gn);
498 DNFPredicate tp2=new DNFPredicate(true,ip);
499 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMRELATION, rd,sources);
500 TermNode tn2=new TermNode(ar2);
501 GraphNode gn2=new GraphNode("AbstractRemRelRule"+i,tn2);
502 if (!predtoabstractmap.containsKey(tp2))
503 predtoabstractmap.put(tp2,new HashSet());
504 ((Set)predtoabstractmap.get(tp2)).add(gn2);
505 abstractrepair.add(gn2);
506 abstractrepairadd.add(gn2);
507 abstractremove.put(rd,gn2);
511 int compensationcount=0;
512 void generatecompensationnodes() {
513 for(int i=0;i<state.vRules.size();i++) {
514 Rule r=(Rule) state.vRules.get(i);
515 Vector possiblerules=new Vector();
517 for(int j=0;j<(r.numQuantifiers()+r.getDNFNegGuardExpr().size());j++) {
518 GraphNode gn=(GraphNode)scopesatisfy.get(r);
519 TermNode tn=(TermNode) gn.getOwner();
520 ScopeNode sn=tn.getScope();
521 MultUpdateNode mun=new MultUpdateNode(sn);
522 TermNode tn2=new TermNode(mun);
523 GraphNode gn2=new GraphNode("CompRem"+compensationcount,tn2);
524 UpdateNode un=new UpdateNode(r);
526 if (j<r.numQuantifiers()) {
527 /* Remove quantifier */
528 Quantifier q=r.getQuantifier(j);
529 if (q instanceof RelationQuantifier) {
530 RelationQuantifier rq=(RelationQuantifier)q;
531 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
532 toe.td=ReservedTypeDescriptor.INT;
533 Updates u=new Updates(toe,true);
535 if (abstractremove.containsKey(rq.relation)) {
536 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
537 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
540 continue; /* Abstract repair doesn't exist */
542 } else if (q instanceof SetQuantifier) {
543 SetQuantifier sq=(SetQuantifier)q;
544 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
545 eoe.td=ReservedTypeDescriptor.INT;
546 Updates u=new Updates(eoe,true);
548 if (abstractremove.containsKey(sq.set)) {
549 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
550 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
553 continue; /* Abstract repair doesn't exist */
559 /* Negate conjunction */
560 int c=j-r.numQuantifiers();
561 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
565 if (!un.checkupdates()) /* Make sure we have a good update */
569 GraphNode.Edge e=new GraphNode.Edge("abstract"+compensationcount,gn2);
572 updatenodes.add(gn2);
577 void generatedatastructureupdatenodes() {
578 for(Iterator absiterator=abstractrepair.iterator();absiterator.hasNext();) {
579 GraphNode gn=(GraphNode)absiterator.next();
580 System.out.println("Analysing: "+gn.getTextLabel());
581 TermNode tn=(TermNode) gn.getOwner();
582 AbstractRepair ar=tn.getAbstract();
583 if (ar.getType()==AbstractRepair.ADDTOSET) {
584 generateaddtosetrelation(gn,ar);
585 } else if (ar.getType()==AbstractRepair.REMOVEFROMSET) {
586 generateremovefromsetrelation(gn,ar);
587 } else if (ar.getType()==AbstractRepair.ADDTORELATION) {
588 generateaddtosetrelation(gn,ar);
589 } else if (ar.getType()==AbstractRepair.REMOVEFROMRELATION) {
590 generateremovefromsetrelation(gn,ar);
591 } else if (ar.getType()==AbstractRepair.MODIFYRELATION) {
592 /* Generate remove/add pairs */
593 if (ar.needsRemoves(state))
594 generateremovefromsetrelation(gn,ar);
595 generateaddtosetrelation(gn,ar);
596 /* Generate atomic modify */
597 generatemodifyrelation(gn,ar);
603 /** This method generates concrete data structure updates which
604 * remove an object (or tuple) from a set (or relation).*/
606 int removefromcount=0;
607 void generateremovefromsetrelation(GraphNode gn,AbstractRepair ar) {
608 /* Construct the set of all rules which could add something to the given set or relation */
610 Vector possiblerules=new Vector();
611 for(int i=0;i<state.vRules.size();i++) {
612 Rule r=(Rule) state.vRules.get(i);
613 if ((r.getInclusion() instanceof SetInclusion)&&
614 (ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet()))
615 possiblerules.add(r);
616 if ((r.getInclusion() instanceof RelationInclusion)&&
617 (ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation()))
618 possiblerules.add(r);
620 if (possiblerules.size()==0)
623 /* Loop through different ways of falsifying each of these rules */
624 int[] count=new int[possiblerules.size()];
625 while(remains(count,possiblerules,true)) {
626 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.REMOVE);
627 TermNode tn=new TermNode(mun);
628 GraphNode gn2=new GraphNode("UpdateRem"+removefromcount,tn);
630 boolean goodflag=true;
631 for(int i=0;i<possiblerules.size();i++) {
632 Rule r=(Rule)possiblerules.get(i);
633 UpdateNode un=new UpdateNode(r);
635 if (count[i]<r.numQuantifiers()) {
636 /* Remove quantifier */
637 Quantifier q=r.getQuantifier(count[i]);
638 if (q instanceof RelationQuantifier) {
639 RelationQuantifier rq=(RelationQuantifier)q;
640 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
641 toe.td=ReservedTypeDescriptor.INT;
642 Updates u=new Updates(toe,true);
644 if (abstractremove.containsKey(rq.relation)) {
645 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
646 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
649 goodflag=false;break; /* Abstract repair doesn't exist */
651 } else if (q instanceof SetQuantifier) {
652 SetQuantifier sq=(SetQuantifier)q;
653 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
654 eoe.td=ReservedTypeDescriptor.INT;
655 Updates u=new Updates(eoe,true);
657 if (abstractremove.containsKey(sq.set)) {
658 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
659 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
662 goodflag=false;break; /* Abstract repair doesn't exist */
664 } else {goodflag=false;break;}
666 int c=count[i]-r.numQuantifiers();
667 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
668 goodflag=false;break;
671 if (!un.checkupdates()) {
678 GraphNode.Edge e=new GraphNode.Edge("abstract"+(removefromcount++),gn2);
680 updatenodes.add(gn2);
682 increment(count,possiblerules,true);
686 /** This method increments to the next possibility. */
688 static private void increment(int count[], Vector rules,boolean isremove) {
690 for(int i=0;i<(rules.size()-1);i++) {
691 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
700 /** This method test if there remain any possibilities to loop
702 static private boolean remains(int count[], Vector rules, boolean isremove) {
703 for(int i=0;i<rules.size();i++) {
704 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
712 /** This method generates data structure updates to implement the
713 * abstract atomic modification specified by ar. */
716 void generatemodifyrelation(GraphNode gn, AbstractRepair ar) {
717 RelationDescriptor rd=(RelationDescriptor)ar.getDescriptor();
718 ExprPredicate exprPredicate=(ExprPredicate)ar.getPredicate().getPredicate();
719 boolean inverted=exprPredicate.inverted();
727 // construct set of possible rules
728 Vector possiblerules=new Vector();
729 for(int i=0;i<state.vRules.size();i++) {
730 Rule r=(Rule) state.vRules.get(i);
731 if ((r.getInclusion() instanceof RelationInclusion)&&
732 (rd==((RelationInclusion)r.getInclusion()).getRelation()))
733 possiblerules.add(r);
735 if (possiblerules.size()==0)
738 // increment through this set
739 int[] count=new int[possiblerules.size()];
740 while(remains(count,possiblerules,false)) {
741 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.MODIFY);
742 TermNode tn=new TermNode(mun);
743 GraphNode gn2=new GraphNode("UpdateMod"+modifycount,tn);
745 boolean goodflag=true;
746 for(int i=0;i<possiblerules.size();i++) {
747 Rule r=(Rule)possiblerules.get(i);
748 UpdateNode un=new UpdateNode(r);
751 if (!processconjunction(un,r.getDNFGuardExpr().get(c),null)) {
752 goodflag=false;break;
754 RelationInclusion ri=(RelationInclusion)r.getInclusion();
755 if (!(ri.getLeftExpr() instanceof VarExpr)) {
756 if (ri.getLeftExpr().isValue(ri.getRelation().getDomain().getType())) {
757 Updates up=new Updates(ri.getLeftExpr(),leftindex,ri.getRelation().getDomain().getType());
762 else un.addInvariant(ri.getLeftExpr());
765 VarDescriptor vd=((VarExpr)ri.getLeftExpr()).getVar();
767 Updates up=new Updates(ri.getLeftExpr(),leftindex,null);
772 if (!(ri.getRightExpr() instanceof VarExpr)) {
773 if (ri.getRightExpr().isValue(ri.getRelation().getRange().getType())) {
774 Updates up=new Updates(ri.getRightExpr(),rightindex,ri.getRelation().getRange().getType());
780 un.addInvariant(ri.getLeftExpr());
783 VarDescriptor vd=((VarExpr)ri.getRightExpr()).getVar();
785 Updates up=new Updates(ri.getRightExpr(),rightindex,null);
787 } else if (!inverted)
791 if (!un.checkupdates()) {
798 GraphNode.Edge e=new GraphNode.Edge("abstract"+modifycount,gn2);
801 updatenodes.add(gn2);
803 increment(count,possiblerules,false);
807 /** Generate concrete data structure update to add an object(or
808 * tuple) to a set (or relation). */
810 static int addtocount=0;
811 void generateaddtosetrelation(GraphNode gn, AbstractRepair ar) {
812 for(int i=0;i<state.vRules.size();i++) {
813 Rule r=(Rule) state.vRules.get(i);
816 /* See if this is a good rule*/
817 if ((r.getInclusion() instanceof SetInclusion&&
818 ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet())||
819 (r.getInclusion() instanceof RelationInclusion&&
820 ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation())) {
822 /* First solve for quantifiers */
823 Vector bindings=new Vector();
824 /* Construct bindings */
826 Hashtable setmapping=new Hashtable();
827 System.out.println("Attempting to construct bindings");
829 if (!constructbindings(bindings,r,ar,setmapping,false))
831 System.out.println("Bindings constructed");
832 //Generate add instruction
833 DNFRule dnfrule=r.getDNFGuardExpr();
835 for(int j=0;j<dnfrule.size();j++) {
836 Inclusion inc=r.getInclusion();
837 UpdateNode un=new UpdateNode(r);
838 un.addBindings(bindings);
839 /* Now build update for tuple/set inclusion condition */
840 if(inc instanceof SetInclusion) {
841 SetInclusion si=(SetInclusion)inc;
842 Expr e=si.elementexpr;
844 while(e instanceof CastExpr) {
845 CastExpr ce=(CastExpr)e;
846 if (ce.getType()!=si.getSet().getType())
851 if (!(e instanceof VarExpr)) {
852 if (e.isValue(si.getSet().getType())) {
853 Updates up=new Updates(e,0,si.getSet().getType());
856 /* We're an add to set*/
857 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
858 SetDescriptor set=sources.setSource(si.getSet())?
859 sources.getSourceSet(si.getSet()):null;
862 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
863 if (rap==ArrayAnalysis.AccessPath.NONE)
867 if (!constructarrayupdate(un, e, rap, 0))
871 VarDescriptor vd=((VarExpr)e).getVar();
873 Updates up=new Updates(e,0,null);
877 } else if (inc instanceof RelationInclusion) {
878 RelationInclusion ri=(RelationInclusion)inc;
880 Expr e=ri.getLeftExpr();
882 while(e instanceof CastExpr) {
883 CastExpr ce=(CastExpr)e;
884 if (ce.getType()!=ri.getRelation().getDomain().getType())
888 if (!(e instanceof VarExpr)) {
889 if (e.isValue(ri.getRelation().getDomain().getType())) {
890 Updates up=new Updates(e,0,ri.getRelation().getDomain().getType());
891 if (ar.getDomainSet()!=null)
892 setmapping.put(e,ar.getDomainSet());
895 /* We don't handly relation modifies */
896 if (ar.getType()==AbstractRepair.MODIFYRELATION)
898 /* We're an add to relation*/
899 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
900 SetDescriptor set=sources.relsetSource(ri.getRelation(),true /* Domain*/)?
901 sources.relgetSourceSet(ri.getRelation(),true):null;
904 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
905 if (rap==ArrayAnalysis.AccessPath.NONE||
907 !constructarrayupdate(un, e, rap, 0))
909 if (ar.getDomainSet()!=null)
910 setmapping.put(e,ar.getDomainSet());
914 VarDescriptor vd=((VarExpr)e).getVar();
916 Updates up=new Updates(e,0,null);
917 if (ar.getDomainSet()!=null)
918 setmapping.put(e,ar.getDomainSet());
925 while(e instanceof CastExpr) {
926 CastExpr ce=(CastExpr)e;
927 if (ce.getType()!=ri.getRelation().getRange().getType())
931 if (!(e instanceof VarExpr)) {
932 if (e.isValue(ri.getRelation().getRange().getType())) {
933 Updates up=new Updates(e,1,ri.getRelation().getRange().getType());
936 /* We don't handly relation modifies */
937 if (ar.getType()==AbstractRepair.MODIFYRELATION)
939 /* We're an add to relation*/
940 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
941 SetDescriptor set=sources.relsetSource(ri.getRelation(),false /* Range*/)?
942 sources.relgetSourceSet(ri.getRelation(),false):null;
945 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
947 if (rap==ArrayAnalysis.AccessPath.NONE||
949 !constructarrayupdate(un, e, rap, 1))
951 if (ar.getRangeSet()!=null)
952 setmapping.put(e,ar.getRangeSet());
955 VarDescriptor vd=((VarExpr)e).getVar();
957 Updates up=new Updates(e,1,null);
958 if (ar.getRangeSet()!=null)
959 setmapping.put(e,ar.getRangeSet());
964 System.out.println("Built inclusion condition updates.");
965 //Finally build necessary updates to satisfy conjunction
966 RuleConjunction ruleconj=dnfrule.get(j);
968 /* Add in updates for quantifiers */
969 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.ADD);
970 TermNode tn=new TermNode(mun);
971 GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
973 if (debugmsg("Start processing quantifiers")&&
974 processquantifiers(gn2,un, r,setmapping)&&
975 debugmsg("Finished processing quantifiers")&&
976 processconjunction(un,ruleconj,setmapping)&&
977 debugmsg("Finished processing conjunction")&&
979 debugmsg("Updates checked")) {
981 GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
984 updatenodes.add(gn2);
991 boolean debugmsg(String st) {
992 System.out.println(st);
996 boolean constructarrayupdate(UpdateNode un, Expr lexpr, ArrayAnalysis.AccessPath ap, int slotnumber) {
997 System.out.println("Constructing array update");
999 for (int i=ap.numFields()-1;i>=0;i--) {
1003 e=((DotExpr)e).getExpr();
1005 while (e instanceof CastExpr)
1006 e=((CastExpr)e).getExpr();
1008 DotExpr de=(DotExpr)e;
1009 FieldDescriptor fd=ap.getField(i);
1010 if (fd instanceof ArrayDescriptor) {
1011 // We have an ArrayDescriptor!
1012 Expr index=de.getIndex();
1013 if (!index.isValue(null)) {/* Not assignable */
1014 System.out.println("ERROR:Index isn't assignable");
1017 Updates updates=new Updates(index,i,ap,lexpr,slotnumber);
1018 un.addUpdate(updates);
1024 /** This method constructs bindings for an update using rule
1025 * r. The boolean flag isremoval indicates that the update
1026 * performs a removal. The function returns true if it is able to
1027 * generate a valid set of bindings and false otherwise. */
1029 boolean constructbindings(Vector bindings, Rule r, AbstractRepair ar, Hashtable setmapping, boolean isremoval) {
1030 boolean goodupdate=true;
1031 Inclusion inc=r.getInclusion();
1033 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1034 Quantifier q=(Quantifier)iterator.next();
1035 if ((q instanceof SetQuantifier)||(q instanceof ForQuantifier)) {
1036 VarDescriptor vd=null;
1037 SetDescriptor set=null;
1038 if (q instanceof SetQuantifier) {
1039 vd=((SetQuantifier)q).getVar();
1040 set=((SetQuantifier)q).getSet();
1042 vd=((ForQuantifier)q).getVar();
1044 if(inc instanceof SetInclusion) {
1045 SetInclusion si=(SetInclusion)inc;
1046 Expr tmpe=si.elementexpr;
1047 Expr e=si.elementexpr;
1049 while(e instanceof CastExpr) {
1050 CastExpr ce=(CastExpr)e;
1051 if (ce.getType()!=si.getSet().getType())
1056 if ((e instanceof VarExpr)&&
1057 (((VarExpr)e).getVar()==vd)) {
1058 /* Can solve for v */
1059 if (!si.getSet().getType().isSubtypeOf(set.getType()))
1061 Binding binding=new Binding(vd,0);
1062 bindings.add(binding);
1066 } else if (inc instanceof RelationInclusion) {
1067 RelationInclusion ri=(RelationInclusion)inc;
1071 Expr e=ri.getLeftExpr();
1073 while(e instanceof CastExpr) {
1074 CastExpr ce=(CastExpr)e;
1075 if (ce.getType()!=ri.getRelation().getDomain().getType())
1080 if ((e instanceof VarExpr)&&
1081 (((VarExpr)e).getVar()==vd)) {
1082 /* Can solve for v */
1083 Binding binding=new Binding(vd,0);
1084 if (!ri.getRelation().getDomain().getType().isSubtypeOf(set.getType()))
1086 if (ar.getDomainSet()!=null)
1087 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1088 bindings.add(binding);
1092 e=ri.getRightExpr();
1094 while(e instanceof CastExpr) {
1095 CastExpr ce=(CastExpr)e;
1096 if (ce.getType()!=ri.getRelation().getRange().getType())
1101 if ((e instanceof VarExpr)&&
1102 (((VarExpr)e).getVar()==vd)) {
1103 /* Can solve for v */
1104 Binding binding=new Binding(vd,1);
1105 if (!ri.getRelation().getRange().getType().isSubtypeOf(set.getType()))
1107 if (ar.getRangeSet()!=null)
1108 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1109 bindings.add(binding);
1113 } else throw new Error("Inclusion not recognized");
1116 /* Removals don't need bindings anymore
1117 Binding binding=new Binding(vd);
1118 bindings.add(binding);*/
1120 } else if (q instanceof SetQuantifier) {
1121 /* Create new element to bind to */
1122 // search if the set 'set' has a size
1123 Binding binding=new Binding(vd,set,exactsize.getsize(set)==1);
1124 bindings.add(binding);
1129 } else if (q instanceof RelationQuantifier) {
1130 RelationQuantifier rq=(RelationQuantifier)q;
1131 for(int k=0;k<2;k++) {
1132 VarDescriptor vd=(k==0)?rq.x:rq.y;
1133 TypeDescriptor td=(k==0)?rq.getRelation().getDomain().getType():rq.getRelation().getRange().getType();
1134 if(inc instanceof SetInclusion) {
1135 SetInclusion si=(SetInclusion)inc;
1137 Expr e=si.elementexpr;
1139 while(e instanceof CastExpr) {
1140 CastExpr ce=(CastExpr)e;
1141 if (ce.getType()!=td)
1146 if ((e instanceof VarExpr)&&
1147 (((VarExpr)e).getVar()==vd)) {
1148 /* Can solve for v */
1149 Binding binding=new Binding(vd,0);
1151 if (!si.getSet().getType().isSubtypeOf(td))
1153 bindings.add(binding);
1156 } else if (inc instanceof RelationInclusion) {
1157 RelationInclusion ri=(RelationInclusion)inc;
1162 Expr e=ri.getLeftExpr();
1164 while(e instanceof CastExpr) {
1165 CastExpr ce=(CastExpr)e;
1166 if (ce.getType()!=ri.getRelation().getDomain().getType())
1170 if ((ri.getLeftExpr() instanceof VarExpr)&&
1171 (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
1172 /* Can solve for v */
1173 Binding binding=new Binding(vd,0);
1174 if (!ri.getRelation().getDomain().getType().isSubtypeOf(td))
1176 if (ar.getDomainSet()!=null)
1177 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1178 bindings.add(binding);
1182 e=ri.getRightExpr();
1184 while(e instanceof CastExpr) {
1185 CastExpr ce=(CastExpr)e;
1186 if (ce.getType()!=ri.getRelation().getRange().getType())
1190 if ((ri.getRightExpr() instanceof VarExpr)&&
1191 (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
1192 /* Can solve for v */
1193 Binding binding=new Binding(vd,1);
1194 if (!ri.getRelation().getRange().getType().isSubtypeOf(td))
1196 if (ar.getRangeSet()!=null)
1197 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1198 bindings.add(binding);
1202 } else throw new Error("Inclusion not recognized");
1205 /* Removals don't need bindings anymore
1206 Binding binding=new Binding(vd);
1207 bindings.add(binding);*/
1214 } else throw new Error("Quantifier not recognized");
1219 /** Adds updates that add an item to the appropriate set or
1220 * relation quantified over by the model definition rule.. */
1222 boolean processquantifiers(GraphNode gn,UpdateNode un, Rule r,Hashtable setmapping) {
1223 Inclusion inc=r.getInclusion();
1224 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1225 Quantifier q=(Quantifier)iterator.next();
1226 /* Add quantifier */
1227 if (q instanceof RelationQuantifier) {
1228 RelationQuantifier rq=(RelationQuantifier)q;
1229 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
1230 toe.td=ReservedTypeDescriptor.INT;
1231 Updates u=new Updates(toe,false);
1233 if (abstractadd.containsKey(rq.relation)) {
1234 GraphNode agn=(GraphNode)abstractadd.get(rq.relation);
1235 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1240 } else if (q instanceof SetQuantifier) {
1241 SetQuantifier sq=(SetQuantifier)q;
1242 if (un.getBinding(sq.var).getType()==Binding.SEARCH) {
1243 Binding b=un.getBinding(sq.var);
1244 Constraint reqc=exactsize.getConstraint(b.getSet());
1245 constraintdependence.requiresConstraint(gn,reqc);
1246 continue; /* Don't need to ensure addition for search */
1248 VarExpr ve=new VarExpr(sq.var);
1249 SetDescriptor sd=findExpr(setmapping, ve);
1250 if (sd!=null&&sd.isSubset(sq.set))
1251 continue; /* this update is trivially true */
1253 ElementOfExpr eoe=new ElementOfExpr(ve,sq.set);
1254 eoe.td=ReservedTypeDescriptor.INT;
1255 Updates u=new Updates(eoe,false);
1257 if (abstractadd.containsKey(sq.set)) {
1258 GraphNode agn=(GraphNode)abstractadd.get(sq.set);
1259 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1264 } else return false;
1269 static SetDescriptor findExpr(Hashtable setmapping, Expr e) {
1270 if (setmapping==null)
1272 Set kset=setmapping.keySet();
1273 for(Iterator it=kset.iterator();it.hasNext();) {
1274 Expr expr=(Expr)it.next();
1275 if (expr.equals(null,e)) {
1276 return (SetDescriptor)setmapping.get(expr);
1282 /** This method generates the necessary updates to satisfy the
1283 * conjunction ruleconj. */
1285 boolean processconjunction(UpdateNode un,RuleConjunction ruleconj,Hashtable setmapping) {
1287 for(int k=0;k<ruleconj.size();k++) {
1288 DNFExpr de=ruleconj.get(k);
1289 Expr e=de.getExpr();
1290 if (e instanceof OpExpr) {
1291 OpExpr ex=(OpExpr)de.getExpr();
1292 Opcode op=ex.getOpcode();
1293 Updates up=new Updates(ex.left,ex.right,op, de.getNegation());
1295 } else if (e instanceof ElementOfExpr) {
1296 SetDescriptor sd=findExpr(setmapping, ((ElementOfExpr)e).element);
1297 if (sd!=null&&sd.isSubset(((ElementOfExpr)e).set))
1298 continue; /* this update is trivially true */
1299 Updates up=new Updates(e,de.getNegation());
1301 } else if (e instanceof TupleOfExpr) {
1302 Updates up=new Updates(e,de.getNegation());
1304 } else if (e instanceof BooleanLiteralExpr) {
1305 boolean truth=((BooleanLiteralExpr)e).getValue();
1306 if (de.getNegation())
1313 System.out.println(e.getClass().getName());
1314 throw new Error("Unrecognized Expr");
1320 /** This method sees if when the quantifiers listed in set are
1321 * fixed, whether there can be more than one unique binding for
1322 * the constraint or model definition rule qs.*/
1323 public boolean analyzeQuantifiers(Quantifiers qs,Set set) {
1324 for(int i=0;i<qs.numQuantifiers();i++) {
1325 Quantifier q=qs.getQuantifier(i);
1326 if (set.contains(q))
1328 if (q instanceof SetQuantifier) {
1329 SetDescriptor sd=((SetQuantifier)q).getSet();
1330 if (maxsize.getsize(sd)<=1&&
1331 maxsize.getsize(sd)>=0)
1333 } else if (q instanceof RelationQuantifier) {
1334 RelationDescriptor rd=((RelationQuantifier)q).getRelation();
1335 if (maxsize.getsize(rd)<=1&&
1336 maxsize.getsize(rd)>=0)
1344 public boolean mutuallyexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1345 if (mutualexclusive(sd1,sd2)||
1346 mutualexclusive(sd2,sd1))
1352 private boolean mutualexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1353 Vector rules=state.vRules;
1354 for(int i=0;i<rules.size();i++) {
1355 Rule r=(Rule)rules.get(i);
1356 if (r.getInclusion().getTargetDescriptors().contains(sd1)) {
1357 /* Rule may add items to sd1 */
1358 SetInclusion si=(SetInclusion)r.getInclusion();
1359 Expr ve=si.getExpr();
1360 DNFRule drule=r.getDNFGuardExpr();
1361 for(int j=0;j<drule.size();j++) {
1362 RuleConjunction rconj=drule.get(j);
1363 boolean containsexclusion=false;
1364 for (int k=0;k<rconj.size();k++) {
1365 DNFExpr dexpr=rconj.get(k);
1366 if (dexpr.getNegation()&&
1367 dexpr.getExpr() instanceof ElementOfExpr&&
1368 ((ElementOfExpr)dexpr.getExpr()).element.equals(null,ve)) {
1369 SetDescriptor sd=((ElementOfExpr)dexpr.getExpr()).set;
1370 if (sd.isSubset(sd2))
1371 containsexclusion=true;
1374 if (!containsexclusion)
1382 boolean equivalent(SetExpr se, RelationExpr re) {
1383 if (!(se instanceof ImageSetExpr))
1385 ImageSetExpr ise=(ImageSetExpr)se;
1386 while(re!=null&&ise!=null) {
1387 if (re.getRelation()!=ise.getRelation())
1389 if (re.inverted()!=ise.inverted())
1391 if (ise.isimageset) {
1392 ise=ise.getImageSetExpr();
1393 if (!(re.getExpr() instanceof RelationExpr))
1395 re=(RelationExpr)re.getExpr();
1397 if (!(re.getExpr() instanceof VarExpr))
1399 if (((VarExpr)re.getExpr()).getVar()==ise.getVar())
1400 return true; //everything matches