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);
70 debugmsg("Generating scope nodes");
72 debugmsg("Generating repair nodes");
73 generaterepairnodes();
74 debugmsg("Generating data structure nodes");
75 generatedatastructureupdatenodes();
76 debugmsg("Generating compensation nodes");
77 generatecompensationnodes();
78 debugmsg("Generating abstract edges");
79 generateabstractedges();
80 debugmsg("Generating scope edges");
82 debugmsg("Generating update edges");
83 generateupdateedges();
86 HashSet superset=new HashSet();
87 superset.addAll(conjunctions);
88 HashSet closureset=new HashSet();
89 debugmsg("Computing closure");
90 GraphNode.computeclosure(superset,closureset);
92 GraphNode.DOTVisitor.visit(new FileOutputStream("graph.dot"),superset);
93 } catch (Exception e) {
98 generatedebuggraphs();
100 for(Iterator it=updatenodes.iterator();it.hasNext();) {
101 GraphNode gn=(GraphNode)it.next();
102 TermNode tn=(TermNode)gn.getOwner();
103 MultUpdateNode mun=tn.getUpdate();
104 System.out.println(gn.getTextLabel());
105 System.out.println(mun.toString());
107 GraphAnalysis ga=new GraphAnalysis(this);
108 removedset=ga.doAnalysis();
109 if (removedset==null) {
110 System.out.println("Can't generate terminating repair algorithm!");
114 System.out.println("Removing:");
115 for(Iterator it=removedset.iterator();it.hasNext();) {
116 GraphNode gn=(GraphNode)it.next();
117 System.out.println(gn.getTextLabel());
120 superset=new HashSet();
121 superset.addAll(conjunctions);
122 superset.removeAll(removedset);
123 GraphNode.computeclosure(superset,removedset);
125 GraphNode.DOTVisitor.visit(new FileOutputStream("graphfinal.dot"),superset);
126 } catch (Exception e) {
130 constraintdependence.traversedependences(this);
133 void generatedebuggraphs() {
134 for (int i=0;i<Compiler.debuggraphs.size();i++) {
135 DebugItem di=(DebugItem) Compiler.debuggraphs.get(i);
136 HashSet superset=new HashSet();
137 Constraint constr=(Constraint)state.vConstraints.get(di.constraintnum);
139 if (di.conjunctionnum==-1) {
140 superset.addAll((Set)conjunctionmap.get(constr));
142 DNFConstraint dnf=constr.dnfconstraint;
143 superset.add(conjtonodemap.get(dnf.get(di.conjunctionnum)));
146 GraphNode.boundedcomputeclosure(superset,null,di.depth);
148 GraphNode.DOTVisitor.visit(new FileOutputStream("graph"+di.constraintnum+"-"+di.depth+(di.conjunctionnum==-1?"":"-"+di.conjunctionnum)+".dot"),superset);
149 } catch (Exception e) {
157 /** This method generates a node for each conjunction in the DNF
158 * form of each constraint. It also converts the quantifiers into
159 * conjunctions also - constraints can be satisfied by removing
160 * items from the sets and relations they are quantified over */
162 void generateconjunctionnodes() {
163 Vector constraints=state.vConstraints;
164 // Constructs conjunction nodes
165 for(int i=0;i<constraints.size();i++) {
166 Constraint c=(Constraint)constraints.get(i);
167 DNFConstraint dnf=c.dnfconstraint;
168 for(int j=0;j<dnf.size();j++) {
169 TermNode tn=new TermNode(c,dnf.get(j));
170 GraphNode gn=new GraphNode("Conj"+i+"A"+j,
171 "Conj ("+i+","+j+") "+dnf.get(j).name()
173 conjunctions.add(gn);
174 if (!conjunctionmap.containsKey(c))
175 conjunctionmap.put(c,new HashSet());
176 ((Set)conjunctionmap.get(c)).add(gn);
177 conjtonodemap.put(dnf.get(j),gn);
179 // Construct quantifier "conjunction" nodes
180 for(int j=0;j<c.numQuantifiers();j++) {
181 Quantifier q=c.getQuantifier(j);
182 if (q instanceof SetQuantifier) {
183 SetQuantifier sq=(SetQuantifier)q;
184 VarExpr ve=new VarExpr(sq.getVar());
185 InclusionPredicate ip=new InclusionPredicate(ve,new SetExpr(sq.getSet()));
186 DNFConstraint dconst=new DNFConstraint(ip);
188 TermNode tn=new TermNode(c,dconst.get(0));
189 tn.setquantifiernode();
190 GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
191 "Conj ("+i+","+j+") "+dconst.get(0).name()
193 conjunctions.add(gn);
194 if (!conjunctionmap.containsKey(c))
195 conjunctionmap.put(c,new HashSet());
196 ((Set)conjunctionmap.get(c)).add(gn);
197 conjtonodemap.put(dconst.get(0),gn);
199 } else if (q instanceof RelationQuantifier) {
200 RelationQuantifier rq=(RelationQuantifier)q;
201 VarExpr ve=new VarExpr(rq.y);
202 InclusionPredicate ip=new InclusionPredicate(ve,new ImageSetExpr(rq.x,rq.getRelation()));
203 DNFConstraint dconst=new DNFConstraint(ip);
205 TermNode tn=new TermNode(c,dconst.get(0));
206 tn.setquantifiernode();
207 GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
208 "Conj ("+i+","+j+") "+dconst.get(0).name()
210 conjunctions.add(gn);
211 if (!conjunctionmap.containsKey(c))
212 conjunctionmap.put(c,new HashSet());
213 ((Set)conjunctionmap.get(c)).add(gn);
214 conjtonodemap.put(dconst.get(0),gn);
220 void generateupdateedges() {
221 for(Iterator updateiterator=updatenodes.iterator();updateiterator.hasNext();) {
222 GraphNode gn=(GraphNode)updateiterator.next();
223 TermNode tn=(TermNode)gn.getOwner();
224 MultUpdateNode mun=tn.getUpdate();
225 for(int i=0;i<mun.numUpdates();i++) {
226 UpdateNode un=mun.getUpdate(i);
227 for(int j=0;j<un.numUpdates();j++) {
228 Updates u=un.getUpdate(j);
229 if (u.getType()==Updates.ABSTRACT) {
230 Expr e=u.getLeftExpr();
231 boolean negated=u.negate;
232 if (e instanceof TupleOfExpr) {
233 TupleOfExpr toe=(TupleOfExpr)e;
235 GraphNode agn=(GraphNode)abstractremove.get(toe.relation);
236 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
239 GraphNode agn=(GraphNode)abstractadd.get(toe.relation);
240 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
243 } else if (e instanceof ElementOfExpr) {
244 ElementOfExpr eoe=(ElementOfExpr)e;
246 GraphNode agn=(GraphNode)abstractremove.get(eoe.set);
247 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
250 GraphNode agn=(GraphNode)abstractadd.get(eoe.set);
251 GraphNode.Edge edge=new GraphNode.Edge("requires",agn);
254 } else throw new Error("Unrecognized Abstract Update");
258 /* Cycle through the rules to look for possible conflicts */
259 for(int i=0;i<state.vRules.size();i++) {
260 Rule r=(Rule) state.vRules.get(i);
261 if (concreteinterferes.interferes(mun,r,true)) {
262 GraphNode scopenode=(GraphNode)scopesatisfy.get(r);
263 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
266 if (concreteinterferes.interferes(mun,r,false)) {
267 GraphNode scopenode=(GraphNode)scopefalsify.get(r);
268 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
275 void generateabstractedges() {
276 for(Iterator absiterator=abstractrepair.iterator();absiterator.hasNext();) {
277 GraphNode gn=(GraphNode)absiterator.next();
278 TermNode tn=(TermNode)gn.getOwner();
279 AbstractRepair ar=(AbstractRepair)tn.getAbstract();
281 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
282 GraphNode gn2=(GraphNode)conjiterator.next();
283 TermNode tn2=(TermNode)gn2.getOwner();
284 Conjunction conj=tn2.getConjunction();
285 Constraint cons=tn2.getConstraint();
286 /* See if this is a relation wellformedness constraint
287 that is trivially satisfied. */
288 if (abstractinterferes.checkrelationconstraint(ar, cons))
290 if (AbstractInterferes.interferesquantifier(ar,cons)) {
291 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
294 for(int i=0;i<conj.size();i++) {
295 DNFPredicate dp=conj.get(i);
297 if (!abstractinterferes.interfereswithpredicate(ar,dp))
299 if (getConstraint(gn)==null||
300 !abstractinterferes.interferemodifies(ar,getConstraint(gn),dp,cons)) {
301 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
308 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
309 GraphNode gn2=(GraphNode)scopeiterator.next();
310 TermNode tn2=(TermNode)gn2.getOwner();
311 ScopeNode sn2=tn2.getScope();
312 if (AbstractInterferes.interfereswithrule(ar,sn2.getRule(),sn2.getSatisfy())) {
313 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
320 Constraint getConstraint(GraphNode gn) {
321 for(Iterator it=gn.inedges();it.hasNext();) {
322 GraphNode.Edge e=(GraphNode.Edge)it.next();
323 GraphNode gnsource=e.getSource();
324 TermNode tnsource=(TermNode)gnsource.getOwner();
325 if (tnsource.getType()==TermNode.CONJUNCTION) {
326 return tnsource.getConstraint();
332 void generatescopenodes() {
333 for(int i=0;i<state.vRules.size();i++) {
334 Rule r=(Rule) state.vRules.get(i);
335 ScopeNode satisfy=new ScopeNode(r,true);
336 TermNode tnsatisfy=new TermNode(satisfy);
337 GraphNode gnsatisfy=new GraphNode("SatisfyRule"+i,tnsatisfy);
338 ConsequenceNode cnsatisfy=new ConsequenceNode();
339 TermNode ctnsatisfy=new TermNode(cnsatisfy);
340 GraphNode cgnsatisfy=new GraphNode("ConseqSatisfyRule"+i,ctnsatisfy);
341 consequence.put(satisfy,cgnsatisfy);
342 GraphNode.Edge esat=new GraphNode.Edge("consequencesatisfy"+i,cgnsatisfy);
343 gnsatisfy.addEdge(esat);
344 consequencenodes.add(cgnsatisfy);
345 scopesatisfy.put(r,gnsatisfy);
346 scopenodes.add(gnsatisfy);
348 ScopeNode falsify=new ScopeNode(r,false);
349 TermNode tnfalsify=new TermNode(falsify);
350 GraphNode gnfalsify=new GraphNode("FalsifyRule"+i,tnfalsify);
351 ConsequenceNode cnfalsify=new ConsequenceNode();
352 TermNode ctnfalsify=new TermNode(cnfalsify);
353 GraphNode cgnfalsify=new GraphNode("ConseqFalsifyRule"+i,ctnfalsify);
354 consequence.put(falsify,cgnfalsify);
355 GraphNode.Edge efals=new GraphNode.Edge("consequencefalsify"+i,cgnfalsify);
356 gnfalsify.addEdge(efals);
357 consequencenodes.add(cgnfalsify);
358 scopefalsify.put(r,gnfalsify);
359 scopenodes.add(gnfalsify);
363 void generatescopeedges() {
364 for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
365 GraphNode gn=(GraphNode)scopeiterator.next();
366 TermNode tn=(TermNode)gn.getOwner();
367 ScopeNode sn=tn.getScope();
369 /* Interference edges with conjunctions */
370 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
371 GraphNode gn2=(GraphNode)conjiterator.next();
372 TermNode tn2=(TermNode)gn2.getOwner();
373 Conjunction conj=tn2.getConjunction();
374 Constraint constr=tn2.getConstraint();
375 for(int i=0;i<conj.size();i++) {
376 DNFPredicate dp=conj.get(i);
377 if (abstractinterferes.scopeinterfereswithpredicate(sn,dp)||
378 AbstractInterferes.interfereswithquantifier(sn.getDescriptor(),sn.getSatisfy(),constr)) {
379 GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
380 GraphNode gnconseq=(GraphNode)consequence.get(sn);
387 /* Now see if this could effect other model defintion rules */
388 for(int i=0;i<state.vRules.size();i++) {
389 Rule r=(Rule) state.vRules.get(i);
390 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,true)) {
391 GraphNode scopenode=(GraphNode)scopesatisfy.get(r);
392 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
393 GraphNode gnconseq=(GraphNode)consequence.get(sn);
396 if (AbstractInterferes.interfereswithrule(sn.getDescriptor(),sn.getSatisfy(),r,false)) {
397 GraphNode scopenode=(GraphNode)scopefalsify.get(r);
398 GraphNode.Edge e=new GraphNode.Edge("interferes",scopenode);
399 GraphNode gnconseq=(GraphNode)consequence.get(sn);
406 /** This method generates the abstract repair nodes. */
407 void generaterepairnodes() {
408 /* Generate repairs of conjunctions */
409 for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
410 GraphNode gn=(GraphNode)conjiterator.next();
411 TermNode tn=(TermNode)gn.getOwner();
412 Conjunction conj=tn.getConjunction();
414 for(int i=0;i<conj.size();i++) {
415 DNFPredicate dp=conj.get(i);
416 int[] array=dp.getPredicate().getRepairs(dp.isNegated(),this);
417 Descriptor d=dp.getPredicate().getDescriptor();
418 if ((dp.getPredicate() instanceof ExprPredicate)&&
419 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
420 boolean neg=dp.isNegated();
421 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
422 int size=((ExprPredicate)dp.getPredicate()).rightSize();
423 op=Opcode.translateOpcode(neg,op);
424 if (((size==1)&&(op==Opcode.EQ))||
425 ((size!=1)&&(op==Opcode.NE))||
426 ((size<=1)&&(op==Opcode.GE))||
427 ((size<1)&&(op==Opcode.GT))||
428 ((size>1)&&(op==Opcode.LT))||
429 ((size>=1)&&(op==Opcode.LE))) {
430 for(int i2=0;i2<conj.size();i2++) {
431 DNFPredicate dp2=conj.get(i2);
432 if ((dp2.getPredicate() instanceof ExprPredicate)&&
433 (((ExprPredicate)dp2.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
434 if (equivalent(((SizeofExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).left).setexpr,
435 (RelationExpr)((OpExpr)((ExprPredicate)dp2.getPredicate()).expr).left))
436 continue loop; // comparison predicate ensure that size expr is true - no need to generate abstract repairs...
442 for(int j=0;j<array.length;j++) {
443 AbstractRepair ar=new AbstractRepair(dp,array[j],d,sources);
444 TermNode tn2=new TermNode(ar);
445 GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
446 GraphNode.Edge e=new GraphNode.Edge("abstract",gn2);
448 if (!predtoabstractmap.containsKey(dp))
449 predtoabstractmap.put(dp,new HashSet());
450 ((Set)predtoabstractmap.get(dp)).add(gn2);
451 abstractrepair.add(gn2);
455 /* Generate additional abstract repairs */
456 Vector setdescriptors=state.stSets.getAllDescriptors();
457 for(int i=0;i<setdescriptors.size();i++) {
458 SetDescriptor sd=(SetDescriptor)setdescriptors.get(i);
460 VarExpr ve=new VarExpr("DUMMY");
461 InclusionPredicate ip=new InclusionPredicate(ve,new SetExpr(sd));
462 DNFPredicate tp=new DNFPredicate(false,ip);
463 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTOSET, sd,sources);
464 TermNode tn=new TermNode(ar);
465 GraphNode gn=new GraphNode("AbstractAddSetRule"+i,tn);
466 if (!predtoabstractmap.containsKey(tp))
467 predtoabstractmap.put(tp,new HashSet());
468 ((Set)predtoabstractmap.get(tp)).add(gn);
469 abstractrepair.add(gn);
470 abstractrepairadd.add(gn);
471 abstractadd.put(sd,gn);
473 DNFPredicate tp2=new DNFPredicate(true,ip);
474 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMSET, sd,sources);
475 TermNode tn2=new TermNode(ar2);
476 GraphNode gn2=new GraphNode("AbstractRemSetRule"+i,tn2);
477 if (!predtoabstractmap.containsKey(tp2))
478 predtoabstractmap.put(tp2,new HashSet());
479 ((Set)predtoabstractmap.get(tp2)).add(gn2);
480 abstractrepair.add(gn2);
481 abstractrepairadd.add(gn2);
482 abstractremove.put(sd,gn2);
485 Vector relationdescriptors=state.stRelations.getAllDescriptors();
486 for(int i=0;i<relationdescriptors.size();i++) {
487 RelationDescriptor rd=(RelationDescriptor)relationdescriptors.get(i);
488 VarDescriptor vd1=new VarDescriptor("DUMMY1");
489 VarExpr ve2=new VarExpr("DUMMY2");
491 InclusionPredicate ip=new InclusionPredicate(ve2,new ImageSetExpr(vd1, rd));
493 DNFPredicate tp=new DNFPredicate(false,ip);
494 AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTORELATION, rd,sources);
495 TermNode tn=new TermNode(ar);
496 GraphNode gn=new GraphNode("AbstractAddRelRule"+i,tn);
497 if (!predtoabstractmap.containsKey(tp))
498 predtoabstractmap.put(tp,new HashSet());
499 ((Set)predtoabstractmap.get(tp)).add(gn);
500 abstractrepair.add(gn);
501 abstractrepairadd.add(gn);
502 abstractadd.put(rd,gn);
504 DNFPredicate tp2=new DNFPredicate(true,ip);
505 AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMRELATION, rd,sources);
506 TermNode tn2=new TermNode(ar2);
507 GraphNode gn2=new GraphNode("AbstractRemRelRule"+i,tn2);
508 if (!predtoabstractmap.containsKey(tp2))
509 predtoabstractmap.put(tp2,new HashSet());
510 ((Set)predtoabstractmap.get(tp2)).add(gn2);
511 abstractrepair.add(gn2);
512 abstractrepairadd.add(gn2);
513 abstractremove.put(rd,gn2);
517 int compensationcount=0;
518 void generatecompensationnodes() {
519 for(int i=0;i<state.vRules.size();i++) {
520 Rule r=(Rule) state.vRules.get(i);
521 Vector possiblerules=new Vector();
523 for(int j=0;j<(r.numQuantifiers()+r.getDNFNegGuardExpr().size());j++) {
524 GraphNode gn=(GraphNode)scopesatisfy.get(r);
525 TermNode tn=(TermNode) gn.getOwner();
526 ScopeNode sn=tn.getScope();
527 MultUpdateNode mun=new MultUpdateNode(sn);
528 TermNode tn2=new TermNode(mun);
529 GraphNode gn2=new GraphNode("CompRem"+compensationcount,tn2);
530 UpdateNode un=new UpdateNode(r);
532 if (j<r.numQuantifiers()) {
533 /* Remove quantifier */
534 Quantifier q=r.getQuantifier(j);
535 if (q instanceof RelationQuantifier) {
536 RelationQuantifier rq=(RelationQuantifier)q;
537 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
538 toe.td=ReservedTypeDescriptor.INT;
539 Updates u=new Updates(toe,true);
541 if (abstractremove.containsKey(rq.relation)) {
542 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
543 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
546 continue; /* Abstract repair doesn't exist */
548 } else if (q instanceof SetQuantifier) {
549 SetQuantifier sq=(SetQuantifier)q;
550 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
551 eoe.td=ReservedTypeDescriptor.INT;
552 Updates u=new Updates(eoe,true);
554 if (abstractremove.containsKey(sq.set)) {
555 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
556 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
559 continue; /* Abstract repair doesn't exist */
565 /* Negate conjunction */
566 int c=j-r.numQuantifiers();
567 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
571 if (!un.checkupdates()) /* Make sure we have a good update */
575 GraphNode.Edge e=new GraphNode.Edge("abstract"+compensationcount,gn2);
578 updatenodes.add(gn2);
583 void generatedatastructureupdatenodes() {
584 for(Iterator absiterator=abstractrepair.iterator();absiterator.hasNext();) {
585 GraphNode gn=(GraphNode)absiterator.next();
586 System.out.println("Analysing: "+gn.getTextLabel());
587 TermNode tn=(TermNode) gn.getOwner();
588 AbstractRepair ar=tn.getAbstract();
589 if (ar.getType()==AbstractRepair.ADDTOSET) {
590 generateaddtosetrelation(gn,ar);
591 } else if (ar.getType()==AbstractRepair.REMOVEFROMSET) {
592 generateremovefromsetrelation(gn,ar);
593 } else if (ar.getType()==AbstractRepair.ADDTORELATION) {
594 generateaddtosetrelation(gn,ar);
595 } else if (ar.getType()==AbstractRepair.REMOVEFROMRELATION) {
596 generateremovefromsetrelation(gn,ar);
597 } else if (ar.getType()==AbstractRepair.MODIFYRELATION) {
598 /* Generate remove/add pairs */
599 if (ar.needsRemoves(state))
600 generateremovefromsetrelation(gn,ar);
601 generateaddtosetrelation(gn,ar);
602 /* Generate atomic modify */
603 generatemodifyrelation(gn,ar);
609 /** This method generates concrete data structure updates which
610 * remove an object (or tuple) from a set (or relation).*/
612 int removefromcount=0;
613 void generateremovefromsetrelation(GraphNode gn,AbstractRepair ar) {
614 /* Construct the set of all rules which could add something to the given set or relation */
616 Vector possiblerules=new Vector();
617 for(int i=0;i<state.vRules.size();i++) {
618 Rule r=(Rule) state.vRules.get(i);
619 if ((r.getInclusion() instanceof SetInclusion)&&
620 (ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet()))
621 possiblerules.add(r);
622 if ((r.getInclusion() instanceof RelationInclusion)&&
623 (ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation()))
624 possiblerules.add(r);
626 if (possiblerules.size()==0)
629 /* Loop through different ways of falsifying each of these rules */
630 int[] count=new int[possiblerules.size()];
631 while(remains(count,possiblerules,true)) {
632 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.REMOVE);
633 TermNode tn=new TermNode(mun);
634 GraphNode gn2=new GraphNode("UpdateRem"+removefromcount,tn);
636 boolean goodflag=true;
637 for(int i=0;i<possiblerules.size();i++) {
638 Rule r=(Rule)possiblerules.get(i);
639 UpdateNode un=new UpdateNode(r);
641 if (count[i]<r.numQuantifiers()) {
642 /* Remove quantifier */
643 Quantifier q=r.getQuantifier(count[i]);
644 if (q instanceof RelationQuantifier) {
645 RelationQuantifier rq=(RelationQuantifier)q;
646 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
647 toe.td=ReservedTypeDescriptor.INT;
648 Updates u=new Updates(toe,true);
650 if (abstractremove.containsKey(rq.relation)) {
651 GraphNode agn=(GraphNode)abstractremove.get(rq.relation);
652 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
655 goodflag=false;break; /* Abstract repair doesn't exist */
657 } else if (q instanceof SetQuantifier) {
658 SetQuantifier sq=(SetQuantifier)q;
659 ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
660 eoe.td=ReservedTypeDescriptor.INT;
661 Updates u=new Updates(eoe,true);
663 if (abstractremove.containsKey(sq.set)) {
664 GraphNode agn=(GraphNode)abstractremove.get(sq.set);
665 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
668 goodflag=false;break; /* Abstract repair doesn't exist */
670 } else {goodflag=false;break;}
672 int c=count[i]-r.numQuantifiers();
673 if (!processconjunction(un,r.getDNFNegGuardExpr().get(c),null)) {
674 goodflag=false;break;
677 if (!un.checkupdates()) {
684 GraphNode.Edge e=new GraphNode.Edge("abstract"+(removefromcount++),gn2);
686 updatenodes.add(gn2);
688 increment(count,possiblerules,true);
692 /** This method increments to the next possibility. */
694 static private void increment(int count[], Vector rules,boolean isremove) {
696 for(int i=0;i<(rules.size()-1);i++) {
697 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
706 /** This method test if there remain any possibilities to loop
708 static private boolean remains(int count[], Vector rules, boolean isremove) {
709 for(int i=0;i<rules.size();i++) {
710 int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
718 /** This method generates data structure updates to implement the
719 * abstract atomic modification specified by ar. */
722 void generatemodifyrelation(GraphNode gn, AbstractRepair ar) {
723 RelationDescriptor rd=(RelationDescriptor)ar.getDescriptor();
724 ExprPredicate exprPredicate=(ExprPredicate)ar.getPredicate().getPredicate();
725 boolean inverted=exprPredicate.inverted();
733 // construct set of possible rules
734 Vector possiblerules=new Vector();
735 for(int i=0;i<state.vRules.size();i++) {
736 Rule r=(Rule) state.vRules.get(i);
737 if ((r.getInclusion() instanceof RelationInclusion)&&
738 (rd==((RelationInclusion)r.getInclusion()).getRelation()))
739 possiblerules.add(r);
741 if (possiblerules.size()==0)
744 // increment through this set
745 int[] count=new int[possiblerules.size()];
746 while(remains(count,possiblerules,false)) {
747 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.MODIFY);
748 TermNode tn=new TermNode(mun);
749 GraphNode gn2=new GraphNode("UpdateMod"+modifycount,tn);
751 boolean goodflag=true;
752 for(int i=0;i<possiblerules.size();i++) {
753 Rule r=(Rule)possiblerules.get(i);
754 UpdateNode un=new UpdateNode(r);
757 if (!processconjunction(un,r.getDNFGuardExpr().get(c),null)) {
758 goodflag=false;break;
760 RelationInclusion ri=(RelationInclusion)r.getInclusion();
761 if (!(ri.getLeftExpr() instanceof VarExpr)) {
762 if (ri.getLeftExpr().isValue(ri.getRelation().getDomain().getType())) {
763 Updates up=new Updates(ri.getLeftExpr(),leftindex,ri.getRelation().getDomain().getType());
768 else un.addInvariant(ri.getLeftExpr());
771 VarDescriptor vd=((VarExpr)ri.getLeftExpr()).getVar();
773 Updates up=new Updates(ri.getLeftExpr(),leftindex,null);
778 if (!(ri.getRightExpr() instanceof VarExpr)) {
779 if (ri.getRightExpr().isValue(ri.getRelation().getRange().getType())) {
780 Updates up=new Updates(ri.getRightExpr(),rightindex,ri.getRelation().getRange().getType());
786 un.addInvariant(ri.getLeftExpr());
789 VarDescriptor vd=((VarExpr)ri.getRightExpr()).getVar();
791 Updates up=new Updates(ri.getRightExpr(),rightindex,null);
793 } else if (!inverted)
797 if (!un.checkupdates()) {
804 GraphNode.Edge e=new GraphNode.Edge("abstract"+modifycount,gn2);
807 updatenodes.add(gn2);
809 increment(count,possiblerules,false);
813 /** Generate concrete data structure update to add an object(or
814 * tuple) to a set (or relation). */
816 static int addtocount=0;
817 void generateaddtosetrelation(GraphNode gn, AbstractRepair ar) {
818 for(int i=0;i<state.vRules.size();i++) {
819 Rule r=(Rule) state.vRules.get(i);
822 /* See if this is a good rule*/
823 if ((r.getInclusion() instanceof SetInclusion&&
824 ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet())||
825 (r.getInclusion() instanceof RelationInclusion&&
826 ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation())) {
828 /* First solve for quantifiers */
829 Vector bindings=new Vector();
830 /* Construct bindings */
832 Hashtable setmapping=new Hashtable();
833 System.out.println("Attempting to construct bindings");
835 if (!constructbindings(bindings,r,ar,setmapping,false))
837 System.out.println("Bindings constructed");
838 //Generate add instruction
839 DNFRule dnfrule=r.getDNFGuardExpr();
841 for(int j=0;j<dnfrule.size();j++) {
842 Inclusion inc=r.getInclusion();
843 UpdateNode un=new UpdateNode(r);
844 un.addBindings(bindings);
845 /* Now build update for tuple/set inclusion condition */
846 if(inc instanceof SetInclusion) {
847 SetInclusion si=(SetInclusion)inc;
848 Expr e=si.elementexpr;
850 while(e instanceof CastExpr) {
851 CastExpr ce=(CastExpr)e;
852 if (ce.getType()!=si.getSet().getType())
857 if (!(e instanceof VarExpr)) {
858 if (e.isValue(si.getSet().getType())) {
859 Updates up=new Updates(e,0,si.getSet().getType());
862 /* We're an add to set*/
863 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
864 SetDescriptor set=sources.setSource(si.getSet())?
865 sources.getSourceSet(si.getSet()):null;
868 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
869 if (rap==ArrayAnalysis.AccessPath.NONE)
873 if (!constructarrayupdate(un, e, rap, 0))
877 VarDescriptor vd=((VarExpr)e).getVar();
879 Updates up=new Updates(e,0,null);
883 } else if (inc instanceof RelationInclusion) {
884 RelationInclusion ri=(RelationInclusion)inc;
886 Expr e=ri.getLeftExpr();
888 while(e instanceof CastExpr) {
889 CastExpr ce=(CastExpr)e;
890 if (ce.getType()!=ri.getRelation().getDomain().getType())
894 if (!(e instanceof VarExpr)) {
895 if (e.isValue(ri.getRelation().getDomain().getType())) {
896 Updates up=new Updates(e,0,ri.getRelation().getDomain().getType());
897 if (ar.getDomainSet()!=null)
898 setmapping.put(e,ar.getDomainSet());
901 /* We don't handly relation modifies */
902 if (ar.getType()==AbstractRepair.MODIFYRELATION)
904 /* We're an add to relation*/
905 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
906 SetDescriptor set=sources.relsetSource(ri.getRelation(),true /* Domain*/)?
907 sources.relgetSourceSet(ri.getRelation(),true):null;
910 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
911 if (rap==ArrayAnalysis.AccessPath.NONE||
913 !constructarrayupdate(un, e, rap, 0))
915 if (ar.getDomainSet()!=null)
916 setmapping.put(e,ar.getDomainSet());
920 VarDescriptor vd=((VarExpr)e).getVar();
922 Updates up=new Updates(e,0,null);
923 if (ar.getDomainSet()!=null)
924 setmapping.put(e,ar.getDomainSet());
931 while(e instanceof CastExpr) {
932 CastExpr ce=(CastExpr)e;
933 if (ce.getType()!=ri.getRelation().getRange().getType())
937 if (!(e instanceof VarExpr)) {
938 if (e.isValue(ri.getRelation().getRange().getType())) {
939 Updates up=new Updates(e,1,ri.getRelation().getRange().getType());
942 /* We don't handly relation modifies */
943 if (ar.getType()==AbstractRepair.MODIFYRELATION)
945 /* We're an add to relation*/
946 ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
947 SetDescriptor set=sources.relsetSource(ri.getRelation(),false /* Range*/)?
948 sources.relgetSourceSet(ri.getRelation(),false):null;
951 ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
953 if (rap==ArrayAnalysis.AccessPath.NONE||
955 !constructarrayupdate(un, e, rap, 1))
957 if (ar.getRangeSet()!=null)
958 setmapping.put(e,ar.getRangeSet());
961 VarDescriptor vd=((VarExpr)e).getVar();
963 Updates up=new Updates(e,1,null);
964 if (ar.getRangeSet()!=null)
965 setmapping.put(e,ar.getRangeSet());
970 System.out.println("Built inclusion condition updates.");
971 //Finally build necessary updates to satisfy conjunction
972 RuleConjunction ruleconj=dnfrule.get(j);
974 /* Add in updates for quantifiers */
975 MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.ADD);
976 TermNode tn=new TermNode(mun);
977 GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
979 if (debugmsg("Start processing quantifiers")&&
980 processquantifiers(gn2,un, r,setmapping)&&
981 debugmsg("Finished processing quantifiers")&&
982 processconjunction(un,ruleconj,setmapping)&&
983 debugmsg("Finished processing conjunction")&&
985 debugmsg("Updates checked")) {
987 GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
990 updatenodes.add(gn2);
997 boolean debugmsg(String st) {
998 System.out.println(st);
1002 boolean constructarrayupdate(UpdateNode un, Expr lexpr, ArrayAnalysis.AccessPath ap, int slotnumber) {
1003 System.out.println("Constructing array update");
1005 for (int i=ap.numFields()-1;i>=0;i--) {
1009 e=((DotExpr)e).getExpr();
1011 while (e instanceof CastExpr)
1012 e=((CastExpr)e).getExpr();
1014 DotExpr de=(DotExpr)e;
1015 FieldDescriptor fd=ap.getField(i);
1016 if (fd instanceof ArrayDescriptor) {
1017 // We have an ArrayDescriptor!
1018 Expr index=de.getIndex();
1019 if (!index.isValue(null)) {/* Not assignable */
1020 System.out.println("ERROR:Index isn't assignable");
1023 Updates updates=new Updates(index,i,ap,lexpr,slotnumber);
1024 un.addUpdate(updates);
1030 /** This method constructs bindings for an update using rule
1031 * r. The boolean flag isremoval indicates that the update
1032 * performs a removal. The function returns true if it is able to
1033 * generate a valid set of bindings and false otherwise. */
1035 boolean constructbindings(Vector bindings, Rule r, AbstractRepair ar, Hashtable setmapping, boolean isremoval) {
1036 boolean goodupdate=true;
1037 Inclusion inc=r.getInclusion();
1039 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1040 Quantifier q=(Quantifier)iterator.next();
1041 if ((q instanceof SetQuantifier)||(q instanceof ForQuantifier)) {
1042 VarDescriptor vd=null;
1043 SetDescriptor set=null;
1044 if (q instanceof SetQuantifier) {
1045 vd=((SetQuantifier)q).getVar();
1046 set=((SetQuantifier)q).getSet();
1048 vd=((ForQuantifier)q).getVar();
1050 if(inc instanceof SetInclusion) {
1051 SetInclusion si=(SetInclusion)inc;
1052 Expr tmpe=si.elementexpr;
1053 Expr e=si.elementexpr;
1055 while(e instanceof CastExpr) {
1056 CastExpr ce=(CastExpr)e;
1057 if (ce.getType()!=si.getSet().getType())
1062 if ((e instanceof VarExpr)&&
1063 (((VarExpr)e).getVar()==vd)) {
1064 /* Can solve for v */
1065 if (!si.getSet().getType().isSubtypeOf(set.getType()))
1067 Binding binding=new Binding(vd,0);
1068 bindings.add(binding);
1072 } else if (inc instanceof RelationInclusion) {
1073 RelationInclusion ri=(RelationInclusion)inc;
1077 Expr e=ri.getLeftExpr();
1079 while(e instanceof CastExpr) {
1080 CastExpr ce=(CastExpr)e;
1081 if (ce.getType()!=ri.getRelation().getDomain().getType())
1086 if ((e instanceof VarExpr)&&
1087 (((VarExpr)e).getVar()==vd)) {
1088 /* Can solve for v */
1089 Binding binding=new Binding(vd,0);
1090 if (!ri.getRelation().getDomain().getType().isSubtypeOf(set.getType()))
1092 if (ar.getDomainSet()!=null)
1093 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1094 bindings.add(binding);
1098 e=ri.getRightExpr();
1100 while(e instanceof CastExpr) {
1101 CastExpr ce=(CastExpr)e;
1102 if (ce.getType()!=ri.getRelation().getRange().getType())
1107 if ((e instanceof VarExpr)&&
1108 (((VarExpr)e).getVar()==vd)) {
1109 /* Can solve for v */
1110 Binding binding=new Binding(vd,1);
1111 if (!ri.getRelation().getRange().getType().isSubtypeOf(set.getType()))
1113 if (ar.getRangeSet()!=null)
1114 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1115 bindings.add(binding);
1119 } else throw new Error("Inclusion not recognized");
1122 /* Removals don't need bindings anymore
1123 Binding binding=new Binding(vd);
1124 bindings.add(binding);*/
1126 } else if (q instanceof SetQuantifier) {
1127 /* Create new element to bind to */
1128 // search if the set 'set' has a size
1129 Binding binding=new Binding(vd,set,exactsize.getsize(set)==1);
1130 bindings.add(binding);
1135 } else if (q instanceof RelationQuantifier) {
1136 RelationQuantifier rq=(RelationQuantifier)q;
1137 for(int k=0;k<2;k++) {
1138 VarDescriptor vd=(k==0)?rq.x:rq.y;
1139 TypeDescriptor td=(k==0)?rq.getRelation().getDomain().getType():rq.getRelation().getRange().getType();
1140 if(inc instanceof SetInclusion) {
1141 SetInclusion si=(SetInclusion)inc;
1143 Expr e=si.elementexpr;
1145 while(e instanceof CastExpr) {
1146 CastExpr ce=(CastExpr)e;
1147 if (ce.getType()!=td)
1152 if ((e instanceof VarExpr)&&
1153 (((VarExpr)e).getVar()==vd)) {
1154 /* Can solve for v */
1155 Binding binding=new Binding(vd,0);
1157 if (!si.getSet().getType().isSubtypeOf(td))
1159 bindings.add(binding);
1162 } else if (inc instanceof RelationInclusion) {
1163 RelationInclusion ri=(RelationInclusion)inc;
1168 Expr e=ri.getLeftExpr();
1170 while(e instanceof CastExpr) {
1171 CastExpr ce=(CastExpr)e;
1172 if (ce.getType()!=ri.getRelation().getDomain().getType())
1176 if ((ri.getLeftExpr() instanceof VarExpr)&&
1177 (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
1178 /* Can solve for v */
1179 Binding binding=new Binding(vd,0);
1180 if (!ri.getRelation().getDomain().getType().isSubtypeOf(td))
1182 if (ar.getDomainSet()!=null)
1183 setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
1184 bindings.add(binding);
1188 e=ri.getRightExpr();
1190 while(e instanceof CastExpr) {
1191 CastExpr ce=(CastExpr)e;
1192 if (ce.getType()!=ri.getRelation().getRange().getType())
1196 if ((ri.getRightExpr() instanceof VarExpr)&&
1197 (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
1198 /* Can solve for v */
1199 Binding binding=new Binding(vd,1);
1200 if (!ri.getRelation().getRange().getType().isSubtypeOf(td))
1202 if (ar.getRangeSet()!=null)
1203 setmapping.put(ri.getRightExpr(),ar.getRangeSet());
1204 bindings.add(binding);
1208 } else throw new Error("Inclusion not recognized");
1211 /* Removals don't need bindings anymore
1212 Binding binding=new Binding(vd);
1213 bindings.add(binding);*/
1220 } else throw new Error("Quantifier not recognized");
1225 /** Adds updates that add an item to the appropriate set or
1226 * relation quantified over by the model definition rule.. */
1228 boolean processquantifiers(GraphNode gn,UpdateNode un, Rule r,Hashtable setmapping) {
1229 Inclusion inc=r.getInclusion();
1230 for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
1231 Quantifier q=(Quantifier)iterator.next();
1232 /* Add quantifier */
1233 if (q instanceof RelationQuantifier) {
1234 RelationQuantifier rq=(RelationQuantifier)q;
1235 TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
1236 toe.td=ReservedTypeDescriptor.INT;
1237 Updates u=new Updates(toe,false);
1239 if (abstractadd.containsKey(rq.relation)) {
1240 GraphNode agn=(GraphNode)abstractadd.get(rq.relation);
1241 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1246 } else if (q instanceof SetQuantifier) {
1247 SetQuantifier sq=(SetQuantifier)q;
1248 if (un.getBinding(sq.var).getType()==Binding.SEARCH) {
1249 Binding b=un.getBinding(sq.var);
1250 Constraint reqc=exactsize.getConstraint(b.getSet());
1251 constraintdependence.requiresConstraint(gn,reqc);
1252 continue; /* Don't need to ensure addition for search */
1254 VarExpr ve=new VarExpr(sq.var);
1255 SetDescriptor sd=findExpr(setmapping, ve);
1256 if (sd!=null&&sd.isSubset(sq.set))
1257 continue; /* this update is trivially true */
1259 ElementOfExpr eoe=new ElementOfExpr(ve,sq.set);
1260 eoe.td=ReservedTypeDescriptor.INT;
1261 Updates u=new Updates(eoe,false);
1263 if (abstractadd.containsKey(sq.set)) {
1264 GraphNode agn=(GraphNode)abstractadd.get(sq.set);
1265 GraphNode.Edge e=new GraphNode.Edge("requires",agn);
1270 } else return false;
1275 static SetDescriptor findExpr(Hashtable setmapping, Expr e) {
1276 if (setmapping==null)
1278 Set kset=setmapping.keySet();
1279 for(Iterator it=kset.iterator();it.hasNext();) {
1280 Expr expr=(Expr)it.next();
1281 if (expr.equals(null,e)) {
1282 return (SetDescriptor)setmapping.get(expr);
1288 /** This method generates the necessary updates to satisfy the
1289 * conjunction ruleconj. */
1291 boolean processconjunction(UpdateNode un,RuleConjunction ruleconj,Hashtable setmapping) {
1293 for(int k=0;k<ruleconj.size();k++) {
1294 DNFExpr de=ruleconj.get(k);
1295 Expr e=de.getExpr();
1296 if (e instanceof OpExpr) {
1297 OpExpr ex=(OpExpr)de.getExpr();
1298 Opcode op=ex.getOpcode();
1299 Updates up=new Updates(ex.left,ex.right,op, de.getNegation());
1301 } else if (e instanceof ElementOfExpr) {
1302 SetDescriptor sd=findExpr(setmapping, ((ElementOfExpr)e).element);
1303 if (sd!=null&&sd.isSubset(((ElementOfExpr)e).set))
1304 continue; /* this update is trivially true */
1305 Updates up=new Updates(e,de.getNegation());
1307 } else if (e instanceof TupleOfExpr) {
1308 Updates up=new Updates(e,de.getNegation());
1310 } else if (e instanceof BooleanLiteralExpr) {
1311 boolean truth=((BooleanLiteralExpr)e).getValue();
1312 if (de.getNegation())
1319 System.out.println(e.getClass().getName());
1320 throw new Error("Unrecognized Expr");
1326 /** This method sees if when the quantifiers listed in set are
1327 * fixed, whether there can be more than one unique binding for
1328 * the constraint or model definition rule qs.*/
1329 public boolean analyzeQuantifiers(Quantifiers qs,Set set) {
1330 for(int i=0;i<qs.numQuantifiers();i++) {
1331 Quantifier q=qs.getQuantifier(i);
1332 if (set.contains(q))
1334 if (q instanceof SetQuantifier) {
1335 SetDescriptor sd=((SetQuantifier)q).getSet();
1336 if (maxsize.getsize(sd)<=1&&
1337 maxsize.getsize(sd)>=0)
1339 } else if (q instanceof RelationQuantifier) {
1340 RelationDescriptor rd=((RelationQuantifier)q).getRelation();
1341 if (maxsize.getsize(rd)<=1&&
1342 maxsize.getsize(rd)>=0)
1350 public boolean mutuallyexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1351 if (mutualexclusive(sd1,sd2)||
1352 mutualexclusive(sd2,sd1))
1358 private boolean mutualexclusive(SetDescriptor sd1, SetDescriptor sd2) {
1359 Vector rules=state.vRules;
1360 for(int i=0;i<rules.size();i++) {
1361 Rule r=(Rule)rules.get(i);
1362 if (r.getInclusion().getTargetDescriptors().contains(sd1)) {
1363 /* Rule may add items to sd1 */
1364 SetInclusion si=(SetInclusion)r.getInclusion();
1365 Expr ve=si.getExpr();
1366 DNFRule drule=r.getDNFGuardExpr();
1367 for(int j=0;j<drule.size();j++) {
1368 RuleConjunction rconj=drule.get(j);
1369 boolean containsexclusion=false;
1370 for (int k=0;k<rconj.size();k++) {
1371 DNFExpr dexpr=rconj.get(k);
1372 if (dexpr.getNegation()&&
1373 dexpr.getExpr() instanceof ElementOfExpr&&
1374 ((ElementOfExpr)dexpr.getExpr()).element.equals(null,ve)) {
1375 SetDescriptor sd=((ElementOfExpr)dexpr.getExpr()).set;
1376 if (sd.isSubset(sd2))
1377 containsexclusion=true;
1380 if (!containsexclusion)
1388 boolean equivalent(SetExpr se, RelationExpr re) {
1389 if (!(se instanceof ImageSetExpr))
1391 ImageSetExpr ise=(ImageSetExpr)se;
1392 while(re!=null&&ise!=null) {
1393 if (re.getRelation()!=ise.getRelation())
1395 if (re.inverted()!=ise.inverted())
1397 if (ise.isimageset) {
1398 ise=ise.getImageSetExpr();
1399 if (!(re.getExpr() instanceof RelationExpr))
1401 re=(RelationExpr)re.getExpr();
1403 if (!(re.getExpr() instanceof VarExpr))
1405 if (((VarExpr)re.getExpr()).getVar()==ise.getVar())
1406 return true; //everything matches