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 System.out.println(gn.getTextLabel()+"---"+gn2.getTextLabel());
283 if (abstractinterferes.checkrelationconstraint(ar, cons))
286 for(int i=0;i<conj.size();i++) {
287 DNFPredicate dp=conj.get(i);
288 if (AbstractInterferes.interferesquantifier(ar,cons)||
289 abstractinterferes.interfereswithpredicate(ar,dp)) {
290 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
296 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
297 GraphNode gn2=(GraphNode)scopeiterator.next();
298 TermNode tn2=(TermNode)gn2.getOwner();
299 ScopeNode sn2=tn2.getScope();
300 if (AbstractInterferes.interfereswithrule(ar,sn2.getRule(),sn2.getSatisfy())) {
301 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
308 void generatescopenodes() {
309 for(int i=0;i<state.vRules.size();i++) {
310 Rule r=(Rule) state.vRules.get(i);
311 ScopeNode satisfy=new ScopeNode(r,true);
312 TermNode tnsatisfy=new TermNode(satisfy);
313 GraphNode gnsatisfy=new GraphNode("SatisfyRule"+i,tnsatisfy);
314 ConsequenceNode cnsatisfy=new ConsequenceNode();
315 TermNode ctnsatisfy=new TermNode(cnsatisfy);
316 GraphNode cgnsatisfy=new GraphNode("ConseqSatisfyRule"+i,ctnsatisfy);
317 consequence.put(satisfy,cgnsatisfy);
318 GraphNode.Edge esat=new GraphNode.Edge("consequencesatisfy"+i,cgnsatisfy);
319 gnsatisfy.addEdge(esat);
320 consequencenodes.add(cgnsatisfy);
321 scopesatisfy.put(r,gnsatisfy);
322 scopenodes.add(gnsatisfy);
324 ScopeNode falsify=new ScopeNode(r,false);
325 TermNode tnfalsify=new TermNode(falsify);
326 GraphNode gnfalsify=new GraphNode("FalsifyRule"+i,tnfalsify);
327 ConsequenceNode cnfalsify=new ConsequenceNode();
328 TermNode ctnfalsify=new TermNode(cnfalsify);
329 GraphNode cgnfalsify=new GraphNode("ConseqFalsifyRule"+i,ctnfalsify);
330 consequence.put(falsify,cgnfalsify);
331 GraphNode.Edge efals=new GraphNode.Edge("consequencefalsify"+i,cgnfalsify);
332 gnfalsify.addEdge(efals);
333 consequencenodes.add(cgnfalsify);
334 scopefalsify.put(r,gnfalsify);
335 scopenodes.add(gnfalsify);
339 void generatescopeedges() {
340 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
341 GraphNode gn=(GraphNode)scopeiterator.next();
342 TermNode tn=(TermNode)gn.getOwner();
343 ScopeNode sn=tn.getScope();
345 /* Interference edges with conjunctions */
346 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
347 GraphNode gn2=(GraphNode)conjiterator.next();
348 TermNode tn2=(TermNode)gn2.getOwner();
349 Conjunction conj=tn2.getConjunction();
350 Constraint constr=tn2.getConstraint();
351 for(int i=0;i<conj.size();i++) {
352 DNFPredicate dp=conj.get(i);
353 if (abstractinterferes.scopeinterfereswithpredicate(sn,dp)||
354 AbstractInterferes.interfereswithquantifier(sn.getDescriptor(),sn.getSatisfy(),constr)) {
355 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
356 GraphNode gnconseq=(GraphNode)consequence.get(sn);
363 /* Now see if this could effect other model defintion rules */
364 for(int i=0;i<state.vRules.size();i++) {
365 Rule r=(Rule) state.vRules.get(i);
366 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,true)) {
367 GraphNode scopenode=(GraphNode)scopesatisfy.get(r);
368 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
369 GraphNode gnconseq=(GraphNode)consequence.get(sn);
372 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,false)) {
373 GraphNode scopenode=(GraphNode)scopefalsify.get(r);
374 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
375 GraphNode gnconseq=(GraphNode)consequence.get(sn);
382 /** This method generates the abstract repair nodes. */
383 void generaterepairnodes() {
384 /* Generate repairs of conjunctions */
385 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
386 GraphNode gn=(GraphNode)conjiterator.next();
387 TermNode tn=(TermNode)gn.getOwner();
388 Conjunction conj=tn.getConjunction();
390 for(int i=0;i<conj.size();i++) {
391 DNFPredicate dp=conj.get(i);
392 int[] array=dp.getPredicate().getRepairs(dp.isNegated(),this);
393 Descriptor d=dp.getPredicate().getDescriptor();
394 if ((dp.getPredicate() instanceof ExprPredicate)&&
395 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
396 boolean neg=dp.isNegated();
397 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
398 int size=((ExprPredicate)dp.getPredicate()).rightSize();
399 op=Opcode.translateOpcode(neg,op);
400 if (((size==1)&&(op==Opcode.EQ))||
401 ((size!=1)&&(op==Opcode.NE))||
402 ((size<=1)&&(op==Opcode.GE))||
403 ((size<1)&&(op==Opcode.GT))||
404 ((size>1)&&(op==Opcode.LT))||
405 ((size>=1)&&(op==Opcode.LE))) {
406 for(int i2=0;i2<conj.size();i2++) {
407 DNFPredicate dp2=conj.get(i2);
408 if ((dp2.getPredicate() instanceof ExprPredicate)&&
409 (((ExprPredicate)dp2.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
410 if (equivalent(((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr,
411 (RelationExpr)((OpExpr)((ExprPredicate)dp2.getPredicate()).expr).left))
412 continue loop; // comparison predicate ensure that size expr is true - no need to generate abstract repairs...
418 for(int j=0;j<array.length;j++) {
419 AbstractRepair ar=new AbstractRepair(dp,array[j],d,sources);
420 TermNode tn2=new TermNode(ar);
421 GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
422 GraphNode.Edge e=new GraphNode.Edge("abstract",gn2);
424 if (!predtoabstractmap.containsKey(dp))
425 predtoabstractmap.put(dp,new HashSet());
426 ((Set)predtoabstractmap.get(dp)).add(gn2);
427 abstractrepair.add(gn2);
431 /* Generate additional abstract repairs */
432 Vector setdescriptors=state.stSets.getAllDescriptors();
433 for(int i=0;i<setdescriptors.size();i++) {
434 SetDescriptor sd=(SetDescriptor)setdescriptors.get(i);
436 VarExpr ve=new VarExpr("DUMMY");
437 InclusionPredicate ip=new InclusionPredicate(ve,new SetExpr(sd));
438 DNFPredicate tp=new DNFPredicate(false,ip);
439 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTOSET, sd,sources);
440 TermNode tn=new TermNode(ar);
441 GraphNode gn=new GraphNode("AbstractAddSetRule"+i,tn);
442 if (!predtoabstractmap.containsKey(tp))
443 predtoabstractmap.put(tp,new HashSet());
444 ((Set)predtoabstractmap.get(tp)).add(gn);
445 abstractrepair.add(gn);
446 abstractrepairadd.add(gn);
447 abstractadd.put(sd,gn);
449 DNFPredicate tp2=new DNFPredicate(true,ip);
450 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMSET, sd,sources);
451 TermNode tn2=new TermNode(ar2);
452 GraphNode gn2=new GraphNode("AbstractRemSetRule"+i,tn2);
453 if (!predtoabstractmap.containsKey(tp2))
454 predtoabstractmap.put(tp2,new HashSet());
455 ((Set)predtoabstractmap.get(tp2)).add(gn2);
456 abstractrepair.add(gn2);
457 abstractrepairadd.add(gn2);
458 abstractremove.put(sd,gn2);
461 Vector relationdescriptors=state.stRelations.getAllDescriptors();
462 for(int i=0;i<relationdescriptors.size();i++) {
463 RelationDescriptor rd=(RelationDescriptor)relationdescriptors.get(i);
464 VarDescriptor vd1=new VarDescriptor("DUMMY1");
465 VarExpr ve2=new VarExpr("DUMMY2");
467 InclusionPredicate ip=new InclusionPredicate(ve2,new ImageSetExpr(vd1, rd));
469 DNFPredicate tp=new DNFPredicate(false,ip);
470 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTORELATION, rd,sources);
471 TermNode tn=new TermNode(ar);
472 GraphNode gn=new GraphNode("AbstractAddRelRule"+i,tn);
473 if (!predtoabstractmap.containsKey(tp))
474 predtoabstractmap.put(tp,new HashSet());
475 ((Set)predtoabstractmap.get(tp)).add(gn);
476 abstractrepair.add(gn);
477 abstractrepairadd.add(gn);
478 abstractadd.put(rd,gn);
480 DNFPredicate tp2=new DNFPredicate(true,ip);
481 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMRELATION, rd,sources);
482 TermNode tn2=new TermNode(ar2);
483 GraphNode gn2=new GraphNode("AbstractRemRelRule"+i,tn2);
484 if (!predtoabstractmap.containsKey(tp2))
485 predtoabstractmap.put(tp2,new HashSet());
486 ((Set)predtoabstractmap.get(tp2)).add(gn2);
487 abstractrepair.add(gn2);
488 abstractrepairadd.add(gn2);
489 abstractremove.put(rd,gn2);
493 int compensationcount=0;
494 void generatecompensationnodes() {
495 for(int i=0;i<state.vRules.size();i++) {
496 Rule r=(Rule) state.vRules.get(i);
497 Vector possiblerules=new Vector();
499 for(int j=0;j<(r.numQuantifiers()+r.getDNFNegGuardExpr().size());j++) {
500 GraphNode gn=(GraphNode)scopesatisfy.get(r);
501 TermNode tn=(TermNode) gn.getOwner();
502 ScopeNode sn=tn.getScope();
503 MultUpdateNode mun=new MultUpdateNode(sn);
504 TermNode tn2=new TermNode(mun);
505 GraphNode gn2=new GraphNode("CompRem"+compensationcount,tn2);
506 UpdateNode un=new UpdateNode(r);
508 if (j<r.numQuantifiers()) {
509 /* Remove quantifier */
510 Quantifier q=r.getQuantifier(j);
511 if (q instanceof RelationQuantifier) {
512 RelationQuantifier rq=(RelationQuantifier)q;
513 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
514 toe.td=ReservedTypeDescriptor.INT;
515 Updates u=new Updates(toe,true);
517 if (abstractremove.containsKey(rq.relation)) {
518 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
519 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
522 continue; /* Abstract repair doesn't exist */
524 } else if (q instanceof SetQuantifier) {
525 SetQuantifier sq=(SetQuantifier)q;
526 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
527 eoe.td=ReservedTypeDescriptor.INT;
528 Updates u=new Updates(eoe,true);
530 if (abstractremove.containsKey(sq.set)) {
531 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
532 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
535 continue; /* Abstract repair doesn't exist */
541 /* Negate conjunction */
542 int c=j-r.numQuantifiers();
543 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
547 if (!un.checkupdates()) /* Make sure we have a good update */
551 GraphNode.Edge e=new GraphNode.Edge("abstract"+compensationcount,gn2);
554 updatenodes.add(gn2);
559 void generatedatastructureupdatenodes() {
560 for(Iterator absiterator=abstractrepair.iterator();absiterator.hasNext();) {
561 GraphNode gn=(GraphNode)absiterator.next();
562 System.out.println("Analysing: "+gn.getTextLabel());
563 TermNode tn=(TermNode) gn.getOwner();
564 AbstractRepair ar=tn.getAbstract();
565 if (ar.getType()==AbstractRepair.ADDTOSET) {
566 generateaddtosetrelation(gn,ar);
567 } else if (ar.getType()==AbstractRepair.REMOVEFROMSET) {
568 generateremovefromsetrelation(gn,ar);
569 } else if (ar.getType()==AbstractRepair.ADDTORELATION) {
570 generateaddtosetrelation(gn,ar);
571 } else if (ar.getType()==AbstractRepair.REMOVEFROMRELATION) {
572 generateremovefromsetrelation(gn,ar);
573 } else if (ar.getType()==AbstractRepair.MODIFYRELATION) {
574 /* Generate remove/add pairs */
575 if (ar.needsRemoves(state))
576 generateremovefromsetrelation(gn,ar);
577 generateaddtosetrelation(gn,ar);
578 /* Generate atomic modify */
579 generatemodifyrelation(gn,ar);
585 /** This method generates concrete data structure updates which
586 * remove an object (or tuple) from a set (or relation).*/
588 int removefromcount=0;
589 void generateremovefromsetrelation(GraphNode gn,AbstractRepair ar) {
590 /* Construct the set of all rules which could add something to the given set or relation */
592 Vector possiblerules=new Vector();
593 for(int i=0;i<state.vRules.size();i++) {
594 Rule r=(Rule) state.vRules.get(i);
595 if ((r.getInclusion() instanceof SetInclusion)&&
596 (ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet()))
597 possiblerules.add(r);
598 if ((r.getInclusion() instanceof RelationInclusion)&&
599 (ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation()))
600 possiblerules.add(r);
602 if (possiblerules.size()==0)
605 /* Loop through different ways of falsifying each of these rules */
606 int[] count=new int[possiblerules.size()];
607 while(remains(count,possiblerules,true)) {
608 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.REMOVE);
609 TermNode tn=new TermNode(mun);
610 GraphNode gn2=new GraphNode("UpdateRem"+removefromcount,tn);
612 boolean goodflag=true;
613 for(int i=0;i<possiblerules.size();i++) {
614 Rule r=(Rule)possiblerules.get(i);
615 UpdateNode un=new UpdateNode(r);
617 if (count[i]<r.numQuantifiers()) {
618 /* Remove quantifier */
619 Quantifier q=r.getQuantifier(count[i]);
620 if (q instanceof RelationQuantifier) {
621 RelationQuantifier rq=(RelationQuantifier)q;
622 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
623 toe.td=ReservedTypeDescriptor.INT;
624 Updates u=new Updates(toe,true);
626 if (abstractremove.containsKey(rq.relation)) {
627 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
628 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
631 goodflag=false;break; /* Abstract repair doesn't exist */
633 } else if (q instanceof SetQuantifier) {
634 SetQuantifier sq=(SetQuantifier)q;
635 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
636 eoe.td=ReservedTypeDescriptor.INT;
637 Updates u=new Updates(eoe,true);
639 if (abstractremove.containsKey(sq.set)) {
640 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
641 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
644 goodflag=false;break; /* Abstract repair doesn't exist */
646 } else {goodflag=false;break;}
648 int c=count[i]-r.numQuantifiers();
649 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
650 goodflag=false;break;
653 if (!un.checkupdates()) {
660 GraphNode.Edge e=new GraphNode.Edge("abstract"+removefromcount,gn2);
663 updatenodes.add(gn2);
665 increment(count,possiblerules,true);
669 /** This method increments to the next possibility. */
671 static private void increment(int count[], Vector rules,boolean isremove) {
673 for(int i=0;i<(rules.size()-1);i++) {
674 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
683 /** This method test if there remain any possibilities to loop
685 static private boolean remains(int count[], Vector rules, boolean isremove) {
686 for(int i=0;i<rules.size();i++) {
687 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
695 /** This method generates data structure updates to implement the
696 * abstract atomic modification specified by ar. */
699 void generatemodifyrelation(GraphNode gn, AbstractRepair ar) {
700 RelationDescriptor rd=(RelationDescriptor)ar.getDescriptor();
701 ExprPredicate exprPredicate=(ExprPredicate)ar.getPredicate().getPredicate();
702 boolean inverted=exprPredicate.inverted();
710 // construct set of possible rules
711 Vector possiblerules=new Vector();
712 for(int i=0;i<state.vRules.size();i++) {
713 Rule r=(Rule) state.vRules.get(i);
714 if ((r.getInclusion() instanceof RelationInclusion)&&
715 (rd==((RelationInclusion)r.getInclusion()).getRelation()))
716 possiblerules.add(r);
718 if (possiblerules.size()==0)
721 // increment through this set
722 int[] count=new int[possiblerules.size()];
723 while(remains(count,possiblerules,false)) {
724 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.MODIFY);
725 TermNode tn=new TermNode(mun);
726 GraphNode gn2=new GraphNode("UpdateMod"+removefromcount,tn);
728 boolean goodflag=true;
729 for(int i=0;i<possiblerules.size();i++) {
730 Rule r=(Rule)possiblerules.get(i);
731 UpdateNode un=new UpdateNode(r);
734 if (!processconjunction(un,r.getDNFGuardExpr().get(c),null)) {
735 goodflag=false;break;
737 RelationInclusion ri=(RelationInclusion)r.getInclusion();
738 if (!(ri.getLeftExpr() instanceof VarExpr)) {
739 if (ri.getLeftExpr().isValue(ri.getRelation().getDomain().getType())) {
740 Updates up=new Updates(ri.getLeftExpr(),leftindex,ri.getRelation().getDomain().getType());
745 else un.addInvariant(ri.getLeftExpr());
748 VarDescriptor vd=((VarExpr)ri.getLeftExpr()).getVar();
750 Updates up=new Updates(ri.getLeftExpr(),leftindex,null);
755 if (!(ri.getRightExpr() instanceof VarExpr)) {
756 if (ri.getRightExpr().isValue(ri.getRelation().getRange().getType())) {
757 Updates up=new Updates(ri.getRightExpr(),rightindex,ri.getRelation().getRange().getType());
763 un.addInvariant(ri.getLeftExpr());
766 VarDescriptor vd=((VarExpr)ri.getRightExpr()).getVar();
768 Updates up=new Updates(ri.getRightExpr(),rightindex,null);
770 } else if (!inverted)
774 if (!un.checkupdates()) {
781 GraphNode.Edge e=new GraphNode.Edge("abstract"+modifycount,gn2);
784 updatenodes.add(gn2);
786 increment(count,possiblerules,false);
790 /** Generate concrete data structure update to add an object(or
791 * tuple) to a set (or relation). */
793 static int addtocount=0;
794 void generateaddtosetrelation(GraphNode gn, AbstractRepair ar) {
795 for(int i=0;i<state.vRules.size();i++) {
796 Rule r=(Rule) state.vRules.get(i);
799 /* See if this is a good rule*/
800 if ((r.getInclusion() instanceof SetInclusion&&
801 ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet())||
802 (r.getInclusion() instanceof RelationInclusion&&
803 ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation())) {
805 /* First solve for quantifiers */
806 Vector bindings=new Vector();
807 /* Construct bindings */
809 Hashtable setmapping=new Hashtable();
810 System.out.println("Attempting to construct bindings");
812 if (!constructbindings(bindings,r,ar,setmapping,false))
814 System.out.println("Bindings constructed");
815 //Generate add instruction
816 DNFRule dnfrule=r.getDNFGuardExpr();
818 for(int j=0;j<dnfrule.size();j++) {
819 Inclusion inc=r.getInclusion();
820 UpdateNode un=new UpdateNode(r);
821 un.addBindings(bindings);
822 /* Now build update for tuple/set inclusion condition */
823 if(inc instanceof SetInclusion) {
824 SetInclusion si=(SetInclusion)inc;
825 Expr e=si.elementexpr;
827 while(e instanceof CastExpr) {
828 CastExpr ce=(CastExpr)e;
829 if (ce.getType()!=si.getSet().getType())
834 if (!(e instanceof VarExpr)) {
835 if (e.isValue(si.getSet().getType())) {
836 Updates up=new Updates(e,0,si.getSet().getType());
839 /* We're an add to set*/
840 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
841 SetDescriptor set=sources.setSource(si.getSet())?
842 sources.getSourceSet(si.getSet()):null;
845 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
846 if (rap==ArrayAnalysis.AccessPath.NONE)
850 if (!constructarrayupdate(un, e, rap, 0))
854 VarDescriptor vd=((VarExpr)e).getVar();
856 Updates up=new Updates(e,0,null);
860 } else if (inc instanceof RelationInclusion) {
861 RelationInclusion ri=(RelationInclusion)inc;
863 Expr e=ri.getLeftExpr();
865 while(e instanceof CastExpr) {
866 CastExpr ce=(CastExpr)e;
867 if (ce.getType()!=ri.getRelation().getDomain().getType())
871 if (!(e instanceof VarExpr)) {
872 if (e.isValue(ri.getRelation().getDomain().getType())) {
873 Updates up=new Updates(e,0,ri.getRelation().getDomain().getType());
874 if (ar.getDomainSet()!=null)
875 setmapping.put(e,ar.getDomainSet());
878 /* We don't handly relation modifies */
879 if (ar.getType()==AbstractRepair.MODIFYRELATION)
881 /* We're an add to relation*/
882 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
883 SetDescriptor set=sources.relsetSource(ri.getRelation(),true /* Domain*/)?
884 sources.relgetSourceSet(ri.getRelation(),true):null;
887 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
888 if (rap==ArrayAnalysis.AccessPath.NONE||
890 !constructarrayupdate(un, e, rap, 0))
892 if (ar.getDomainSet()!=null)
893 setmapping.put(e,ar.getDomainSet());
897 VarDescriptor vd=((VarExpr)e).getVar();
899 Updates up=new Updates(e,0,null);
900 if (ar.getDomainSet()!=null)
901 setmapping.put(e,ar.getDomainSet());
908 while(e instanceof CastExpr) {
909 CastExpr ce=(CastExpr)e;
910 if (ce.getType()!=ri.getRelation().getRange().getType())
914 if (!(e instanceof VarExpr)) {
915 if (e.isValue(ri.getRelation().getRange().getType())) {
916 Updates up=new Updates(e,1,ri.getRelation().getRange().getType());
919 /* We don't handly relation modifies */
920 if (ar.getType()==AbstractRepair.MODIFYRELATION)
922 /* We're an add to relation*/
923 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
924 SetDescriptor set=sources.relsetSource(ri.getRelation(),false /* Range*/)?
925 sources.relgetSourceSet(ri.getRelation(),false):null;
928 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
930 if (rap==ArrayAnalysis.AccessPath.NONE||
932 !constructarrayupdate(un, e, rap, 1))
934 if (ar.getRangeSet()!=null)
935 setmapping.put(e,ar.getRangeSet());
938 VarDescriptor vd=((VarExpr)e).getVar();
940 Updates up=new Updates(e,1,null);
941 if (ar.getRangeSet()!=null)
942 setmapping.put(e,ar.getRangeSet());
947 System.out.println("Built inclusion condition updates.");
948 //Finally build necessary updates to satisfy conjunction
949 RuleConjunction ruleconj=dnfrule.get(j);
951 /* Add in updates for quantifiers */
952 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.ADD);
953 TermNode tn=new TermNode(mun);
954 GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
956 if (debugmsg("Start processing quantifiers")&&
957 processquantifiers(gn2,un, r,setmapping)&&
958 debugmsg("Finished processing quantifiers")&&
959 processconjunction(un,ruleconj,setmapping)&&
960 debugmsg("Finished processing conjunction")&&
962 debugmsg("Updates checked")) {
964 GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
967 updatenodes.add(gn2);
974 boolean debugmsg(String st) {
975 System.out.println(st);
979 boolean constructarrayupdate(UpdateNode un, Expr lexpr, ArrayAnalysis.AccessPath ap, int slotnumber) {
980 System.out.println("Constructing array update");
982 for (int i=ap.numFields()-1;i>=0;i--) {
986 e=((DotExpr)e).getExpr();
988 while (e instanceof CastExpr)
989 e=((CastExpr)e).getExpr();
991 DotExpr de=(DotExpr)e;
992 FieldDescriptor fd=ap.getField(i);
993 if (fd instanceof ArrayDescriptor) {
994 // We have an ArrayDescriptor!
995 Expr index=de.getIndex();
996 if (!index.isValue(null)) {/* Not assignable */
997 System.out.println("ERROR:Index isn't assignable");
1000 Updates updates=new Updates(index,i,ap,lexpr,slotnumber);
1001 un.addUpdate(updates);
1007 /** This method constructs bindings for an update using rule
1008 * r. The boolean flag isremoval indicates that the update
1009 * performs a removal. The function returns true if it is able to
1010 * generate a valid set of bindings and false otherwise. */
1012 boolean constructbindings(Vector bindings, Rule r, AbstractRepair ar, Hashtable setmapping, boolean isremoval) {
1013 boolean goodupdate=true;
1014 Inclusion inc=r.getInclusion();
1016 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1017 Quantifier q=(Quantifier)iterator.next();
1018 if ((q instanceof SetQuantifier)||(q instanceof ForQuantifier)) {
1019 VarDescriptor vd=null;
1020 SetDescriptor set=null;
1021 if (q instanceof SetQuantifier) {
1022 vd=((SetQuantifier)q).getVar();
1023 set=((SetQuantifier)q).getSet();
1025 vd=((ForQuantifier)q).getVar();
1027 if(inc instanceof SetInclusion) {
1028 SetInclusion si=(SetInclusion)inc;
1029 Expr tmpe=si.elementexpr;
1030 Expr e=si.elementexpr;
1032 while(e instanceof CastExpr) {
1033 CastExpr ce=(CastExpr)e;
1034 if (ce.getType()!=si.getSet().getType())
1039 if ((e instanceof VarExpr)&&
1040 (((VarExpr)e).getVar()==vd)) {
1041 /* Can solve for v */
1042 if (!si.getSet().getType().isSubtypeOf(set.getType()))
1044 Binding binding=new Binding(vd,0);
1045 bindings.add(binding);
1049 } else if (inc instanceof RelationInclusion) {
1050 RelationInclusion ri=(RelationInclusion)inc;
1054 Expr e=ri.getLeftExpr();
1056 while(e instanceof CastExpr) {
1057 CastExpr ce=(CastExpr)e;
1058 if (ce.getType()!=ri.getRelation().getDomain().getType())
1063 if ((e instanceof VarExpr)&&
1064 (((VarExpr)e).getVar()==vd)) {
1065 /* Can solve for v */
1066 Binding binding=new Binding(vd,0);
1067 if (!ri.getRelation().getDomain().getType().isSubtypeOf(set.getType()))
1069 if (ar.getDomainSet()!=null)
1070 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1071 bindings.add(binding);
1075 e=ri.getRightExpr();
1077 while(e instanceof CastExpr) {
1078 CastExpr ce=(CastExpr)e;
1079 if (ce.getType()!=ri.getRelation().getRange().getType())
1084 if ((e instanceof VarExpr)&&
1085 (((VarExpr)e).getVar()==vd)) {
1086 /* Can solve for v */
1087 Binding binding=new Binding(vd,1);
1088 if (!ri.getRelation().getRange().getType().isSubtypeOf(set.getType()))
1090 if (ar.getRangeSet()!=null)
1091 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1092 bindings.add(binding);
1096 } else throw new Error("Inclusion not recognized");
1099 /* Removals don't need bindings anymore
1100 Binding binding=new Binding(vd);
1101 bindings.add(binding);*/
1103 } else if (q instanceof SetQuantifier) {
1104 /* Create new element to bind to */
1105 // search if the set 'set' has a size
1106 Binding binding=new Binding(vd,set,exactsize.getsize(set)==1);
1107 bindings.add(binding);
1112 } else if (q instanceof RelationQuantifier) {
1113 RelationQuantifier rq=(RelationQuantifier)q;
1114 for(int k=0;k<2;k++) {
1115 VarDescriptor vd=(k==0)?rq.x:rq.y;
1116 TypeDescriptor td=(k==0)?rq.getRelation().getDomain().getType():rq.getRelation().getRange().getType();
1117 if(inc instanceof SetInclusion) {
1118 SetInclusion si=(SetInclusion)inc;
1120 Expr e=si.elementexpr;
1122 while(e instanceof CastExpr) {
1123 CastExpr ce=(CastExpr)e;
1124 if (ce.getType()!=td)
1129 if ((e instanceof VarExpr)&&
1130 (((VarExpr)e).getVar()==vd)) {
1131 /* Can solve for v */
1132 Binding binding=new Binding(vd,0);
1134 if (!si.getSet().getType().isSubtypeOf(td))
1136 bindings.add(binding);
1139 } else if (inc instanceof RelationInclusion) {
1140 RelationInclusion ri=(RelationInclusion)inc;
1145 Expr e=ri.getLeftExpr();
1147 while(e instanceof CastExpr) {
1148 CastExpr ce=(CastExpr)e;
1149 if (ce.getType()!=ri.getRelation().getDomain().getType())
1153 if ((ri.getLeftExpr() instanceof VarExpr)&&
1154 (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
1155 /* Can solve for v */
1156 Binding binding=new Binding(vd,0);
1157 if (!ri.getRelation().getDomain().getType().isSubtypeOf(td))
1159 if (ar.getDomainSet()!=null)
1160 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1161 bindings.add(binding);
1165 e=ri.getRightExpr();
1167 while(e instanceof CastExpr) {
1168 CastExpr ce=(CastExpr)e;
1169 if (ce.getType()!=ri.getRelation().getRange().getType())
1173 if ((ri.getRightExpr() instanceof VarExpr)&&
1174 (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
1175 /* Can solve for v */
1176 Binding binding=new Binding(vd,1);
1177 if (!ri.getRelation().getRange().getType().isSubtypeOf(td))
1179 if (ar.getRangeSet()!=null)
1180 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1181 bindings.add(binding);
1185 } else throw new Error("Inclusion not recognized");
1188 /* Removals don't need bindings anymore
1189 Binding binding=new Binding(vd);
1190 bindings.add(binding);*/
1197 } else throw new Error("Quantifier not recognized");
1202 /** Adds updates that add an item to the appropriate set or
1203 * relation quantified over by the model definition rule.. */
1205 boolean processquantifiers(GraphNode gn,UpdateNode un, Rule r,Hashtable setmapping) {
1206 Inclusion inc=r.getInclusion();
1207 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1208 Quantifier q=(Quantifier)iterator.next();
1209 /* Add quantifier */
1210 if (q instanceof RelationQuantifier) {
1211 RelationQuantifier rq=(RelationQuantifier)q;
1212 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
1213 toe.td=ReservedTypeDescriptor.INT;
1214 Updates u=new Updates(toe,false);
1216 if (abstractadd.containsKey(rq.relation)) {
1217 GraphNode agn=(GraphNode)abstractadd.get(rq.relation);
1218 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1223 } else if (q instanceof SetQuantifier) {
1224 SetQuantifier sq=(SetQuantifier)q;
1225 if (un.getBinding(sq.var).getType()==Binding.SEARCH) {
1226 Binding b=un.getBinding(sq.var);
1227 Constraint reqc=exactsize.getConstraint(b.getSet());
1228 constraintdependence.requiresConstraint(gn,reqc);
1229 continue; /* Don't need to ensure addition for search */
1231 VarExpr ve=new VarExpr(sq.var);
1232 SetDescriptor sd=findExpr(setmapping, ve);
1233 if (sd!=null&&sd.isSubset(sq.set))
1234 continue; /* this update is trivially true */
1236 ElementOfExpr eoe=new ElementOfExpr(ve,sq.set);
1237 eoe.td=ReservedTypeDescriptor.INT;
1238 Updates u=new Updates(eoe,false);
1240 if (abstractadd.containsKey(sq.set)) {
1241 GraphNode agn=(GraphNode)abstractadd.get(sq.set);
1242 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1247 } else return false;
1252 static SetDescriptor findExpr(Hashtable setmapping, Expr e) {
1253 if (setmapping==null)
1255 Set kset=setmapping.keySet();
1256 for(Iterator it=kset.iterator();it.hasNext();) {
1257 Expr expr=(Expr)it.next();
1258 if (expr.equals(null,e)) {
1259 return (SetDescriptor)setmapping.get(expr);
1265 /** This method generates the necessary updates to satisfy the
1266 * conjunction ruleconj. */
1268 boolean processconjunction(UpdateNode un,RuleConjunction ruleconj,Hashtable setmapping) {
1270 for(int k=0;k<ruleconj.size();k++) {
1271 DNFExpr de=ruleconj.get(k);
1272 Expr e=de.getExpr();
1273 if (e instanceof OpExpr) {
1274 OpExpr ex=(OpExpr)de.getExpr();
1275 Opcode op=ex.getOpcode();
1276 Updates up=new Updates(ex.left,ex.right,op, de.getNegation());
1278 } else if (e instanceof ElementOfExpr) {
1279 SetDescriptor sd=findExpr(setmapping, ((ElementOfExpr)e).element);
1280 if (sd!=null&&sd.isSubset(((ElementOfExpr)e).set))
1281 continue; /* this update is trivially true */
1282 Updates up=new Updates(e,de.getNegation());
1284 } else if (e instanceof TupleOfExpr) {
1285 Updates up=new Updates(e,de.getNegation());
1287 } else if (e instanceof BooleanLiteralExpr) {
1288 boolean truth=((BooleanLiteralExpr)e).getValue();
1289 if (de.getNegation())
1296 System.out.println(e.getClass().getName());
1297 throw new Error("Unrecognized Expr");
1303 /** This method sees if when the quantifiers listed in set are
1304 * fixed, whether there can be more than one unique binding for
1305 * the constraint or model definition rule qs.*/
1306 public boolean analyzeQuantifiers(Quantifiers qs,Set set) {
1307 for(int i=0;i<qs.numQuantifiers();i++) {
1308 Quantifier q=qs.getQuantifier(i);
1309 if (set.contains(q))
1311 if (q instanceof SetQuantifier) {
1312 SetDescriptor sd=((SetQuantifier)q).getSet();
1313 if (maxsize.getsize(sd)<=1&&
1314 maxsize.getsize(sd)>=0)
1316 } else if (q instanceof RelationQuantifier) {
1317 RelationDescriptor rd=((RelationQuantifier)q).getRelation();
1318 if (maxsize.getsize(rd)<=1&&
1319 maxsize.getsize(rd)>=0)
1327 public boolean mutuallyexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1328 if (mutualexclusive(sd1,sd2)||
1329 mutualexclusive(sd2,sd1))
1335 private boolean mutualexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1336 Vector rules=state.vRules;
1337 for(int i=0;i<rules.size();i++) {
1338 Rule r=(Rule)rules.get(i);
1339 if (r.getInclusion().getTargetDescriptors().contains(sd1)) {
1340 /* Rule may add items to sd1 */
1341 SetInclusion si=(SetInclusion)r.getInclusion();
1342 Expr ve=si.getExpr();
1343 DNFRule drule=r.getDNFGuardExpr();
1344 for(int j=0;j<drule.size();j++) {
1345 RuleConjunction rconj=drule.get(j);
1346 boolean containsexclusion=false;
1347 for (int k=0;k<rconj.size();k++) {
1348 DNFExpr dexpr=rconj.get(k);
1349 if (dexpr.getNegation()&&
1350 dexpr.getExpr() instanceof ElementOfExpr&&
1351 ((ElementOfExpr)dexpr.getExpr()).element.equals(null,ve)) {
1352 SetDescriptor sd=((ElementOfExpr)dexpr.getExpr()).set;
1353 if (sd.isSubset(sd2))
1354 containsexclusion=true;
1357 if (!containsexclusion)
1365 boolean equivalent(SetExpr se, RelationExpr re) {
1366 if (!(se instanceof ImageSetExpr))
1368 ImageSetExpr ise=(ImageSetExpr)se;
1369 while(re!=null&&ise!=null) {
1370 if (re.getRelation()!=ise.getRelation())
1372 if (re.inverted()!=ise.inverted())
1374 if (ise.isimageset) {
1375 ise=ise.getImageSetExpr();
1376 if (!(re.getExpr() instanceof RelationExpr))
1378 re=(RelationExpr)re.getExpr();
1380 if (!(re.getExpr() instanceof VarExpr))
1382 if (((VarExpr)re.getExpr()).getVar()==ise.getVar())
1383 return true; //everything matches