+ // increment through this set
+ int[] count=new int[possiblerules.size()];
+ while(remains(count,possiblerules,false)) {
+ MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.MODIFY);
+ TermNode tn=new TermNode(mun);
+ GraphNode gn2=new GraphNode("UpdateMod"+modifycount,tn);
+ gn2.setOption(updateoption);
+
+ boolean goodflag=true;
+ for(int i=0;i<possiblerules.size();i++) {
+ Rule r=(Rule)possiblerules.get(i);
+ UpdateNode un=new UpdateNode(r);
+
+ int c=count[i];
+ if (!processconjunction(un,r.getDNFGuardExpr().get(c),null)) {
+ goodflag=false;break;
+ }
+ RelationInclusion ri=(RelationInclusion)r.getInclusion();
+ if (!(ri.getLeftExpr() instanceof VarExpr)) {
+ if (ri.getLeftExpr().isValue(ri.getRelation().getDomain().getType())) {
+ Updates up=new Updates(ri.getLeftExpr(),leftindex,ri.getRelation().getDomain().getType());
+ un.addUpdate(up);
+ } else {
+ if (inverted)
+ goodflag=false;
+ else un.addInvariant(ri.getLeftExpr());
+ }
+ } else {
+ VarDescriptor vd=((VarExpr)ri.getLeftExpr()).getVar();
+ if (vd.isGlobal()) {
+ Updates up=new Updates(ri.getLeftExpr(),leftindex,null);
+ un.addUpdate(up);
+ } else if (inverted)
+ goodflag=false;
+ }
+ if (!(ri.getRightExpr() instanceof VarExpr)) {
+ if (ri.getRightExpr().isValue(ri.getRelation().getRange().getType())) {
+ Updates up=new Updates(ri.getRightExpr(),rightindex,ri.getRelation().getRange().getType());
+ un.addUpdate(up);
+ } else {
+ if (!inverted)
+ goodflag=false;
+ else
+ un.addInvariant(ri.getLeftExpr());
+ }
+ } else {
+ VarDescriptor vd=((VarExpr)ri.getRightExpr()).getVar();
+ if (vd.isGlobal()) {
+ Updates up=new Updates(ri.getRightExpr(),rightindex,null);
+ un.addUpdate(up);
+ } else if (!inverted)
+ goodflag=false;
+ }
+
+ if (!un.checkupdates()) {
+ goodflag=false;
+ break;
+ }
+ mun.addUpdate(un);
+ }
+ if (goodflag) {
+ GraphNode.Edge e=new GraphNode.Edge("abstract"+modifycount,gn2);
+ modifycount++;
+ gn.addEdge(e);
+ updatenodes.add(gn2);
+ }
+ increment(count,possiblerules,false);
+ }
+ }
+
+ /** Generate concrete data structure update to add an object(or
+ * tuple) to a set (or relation). */
+
+ static int addtocount=0;
+ void generateaddtosetrelation(GraphNode gn, AbstractRepair ar) {
+ for(int i=0;i<state.vRules.size();i++) {
+ Rule r=(Rule) state.vRules.get(i);
+
+
+ /* See if this is a good rule*/
+ if ((r.getInclusion() instanceof SetInclusion&&
+ ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet())||
+ (r.getInclusion() instanceof RelationInclusion&&
+ ar.getDescriptor()==((RelationInclusion)r.getInclusion()).getRelation())) {
+
+ /* First solve for quantifiers */
+ Vector bindings=new Vector();
+ /* Construct bindings */
+
+ Hashtable setmapping=new Hashtable();
+ System.out.println("Attempting to construct bindings");
+
+ if (!constructbindings(bindings,r,ar,setmapping,false))
+ continue;
+ System.out.println("Bindings constructed");
+ //Generate add instruction
+ DNFRule dnfrule=r.getDNFGuardExpr();
+ endloop:
+ for(int j=0;j<dnfrule.size();j++) {
+ Inclusion inc=r.getInclusion();
+ UpdateNode un=new UpdateNode(r);
+ un.addBindings(bindings);
+ /* Now build update for tuple/set inclusion condition */
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+ Expr e=si.elementexpr;
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=si.getSet().getType())
+ continue endloop;
+ e=ce.getExpr();
+ }
+
+ if (!(e instanceof VarExpr)) {
+ if (e.isValue(si.getSet().getType())) {
+ Updates up=new Updates(e,0,si.getSet().getType());
+ un.addUpdate(up);
+ } else {
+ /* We're an add to set*/
+ ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
+ SetDescriptor set=sources.setSource(si.getSet())?
+ sources.getSourceSet(si.getSet()):null;
+ if (set==null)
+ continue;
+ ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
+ if (rap==ArrayAnalysis.AccessPath.NONE)
+ continue;
+ if (!rap.equal(ap))
+ continue;
+ if (!constructarrayupdate(un, e, rap, 0))
+ continue;
+ }
+ } else {
+ VarDescriptor vd=((VarExpr)e).getVar();
+ if (vd.isGlobal()) {
+ Updates up=new Updates(e,0,null);
+ un.addUpdate(up);
+ }
+ }
+ } else if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+
+ Expr e=ri.getLeftExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getDomain().getType())
+ continue endloop;
+ e=ce.getExpr();
+ }
+ if (!(e instanceof VarExpr)) {
+ if (e.isValue(ri.getRelation().getDomain().getType())) {
+ Updates up=new Updates(e,0,ri.getRelation().getDomain().getType());
+ if (ar.getDomainSet()!=null)
+ setmapping.put(e,ar.getDomainSet());
+ un.addUpdate(up);
+ } else {
+ /* We don't handly relation modifies */
+ if (ar.getType()==AbstractRepair.MODIFYRELATION)
+ continue;
+ /* We're an add to relation*/
+ ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
+ SetDescriptor set=sources.relsetSource(ri.getRelation(),true /* Domain*/)?
+ sources.relgetSourceSet(ri.getRelation(),true):null;
+ if (set==null)
+ continue;
+ ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
+ if (rap==ArrayAnalysis.AccessPath.NONE||
+ !rap.equal(ap)||
+ !constructarrayupdate(un, e, rap, 0))
+ continue;
+ if (ar.getDomainSet()!=null)
+ setmapping.put(e,ar.getDomainSet());
+
+ }
+ } else {
+ VarDescriptor vd=((VarExpr)e).getVar();
+ if (vd.isGlobal()) {
+ Updates up=new Updates(e,0,null);
+ if (ar.getDomainSet()!=null)
+ setmapping.put(e,ar.getDomainSet());
+ un.addUpdate(up);
+ }
+ }
+
+ e=ri.getRightExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getRange().getType())
+ continue endloop;
+ e=ce.getExpr();
+ }
+ if (!(e instanceof VarExpr)) {
+ if (e.isValue(ri.getRelation().getRange().getType())) {
+ Updates up=new Updates(e,1,ri.getRelation().getRange().getType());
+ un.addUpdate(up);
+ } else {
+ /* We don't handly relation modifies */
+ if (ar.getType()==AbstractRepair.MODIFYRELATION)
+ continue;
+ /* We're an add to relation*/
+ ArrayAnalysis.AccessPath rap=arrayanalysis.analyzeExpr(r,e);
+ SetDescriptor set=sources.relsetSource(ri.getRelation(),false /* Range*/)?
+ sources.relgetSourceSet(ri.getRelation(),false):null;
+ if (set==null)
+ continue;
+ ArrayAnalysis.AccessPath ap=arrayanalysis.getSet(set);
+
+ if (rap==ArrayAnalysis.AccessPath.NONE||
+ !rap.equal(ap)||
+ !constructarrayupdate(un, e, rap, 1))
+ continue;
+ if (ar.getRangeSet()!=null)
+ setmapping.put(e,ar.getRangeSet());
+ }
+ } else {
+ VarDescriptor vd=((VarExpr)e).getVar();
+ if (vd.isGlobal()) {
+ Updates up=new Updates(e,1,null);
+ if (ar.getRangeSet()!=null)
+ setmapping.put(e,ar.getRangeSet());
+ un.addUpdate(up);
+ }
+ }
+ }
+ System.out.println("Built inclusion condition updates.");
+ //Finally build necessary updates to satisfy conjunction
+ RuleConjunction ruleconj=dnfrule.get(j);
+
+ /* Add in updates for quantifiers */
+ MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.ADD);
+ TermNode tn=new TermNode(mun);
+ GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
+ gn2.setOption(updateoption);
+
+ if (debugmsg("Start processing quantifiers")&&
+ processquantifiers(gn2,un, r,setmapping)&&
+ debugmsg("Finished processing quantifiers")&&
+ processconjunction(un,ruleconj,setmapping)&&
+ debugmsg("Finished processing conjunction")&&
+ un.checkupdates()&&
+ debugmsg("Updates checked")) {
+ mun.addUpdate(un);
+ GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
+ addtocount++;
+ gn.addEdge(e);
+ updatenodes.add(gn2);
+ }
+ }
+ }
+ }
+ }
+
+ boolean debugmsg(String st) {
+ System.out.println(st);
+ return true;
+ }
+
+ boolean constructarrayupdate(UpdateNode un, Expr lexpr, ArrayAnalysis.AccessPath ap, int slotnumber) {
+ System.out.println("Constructing array update");
+ Expr e=null;
+ for (int i=ap.numFields()-1;i>=0;i--) {
+ if (e==null)
+ e=lexpr;
+ else
+ e=((DotExpr)e).getExpr();
+
+ while (e instanceof CastExpr)
+ e=((CastExpr)e).getExpr();
+
+ DotExpr de=(DotExpr)e;
+ FieldDescriptor fd=ap.getField(i);
+ if (fd instanceof ArrayDescriptor) {
+ // We have an ArrayDescriptor!
+ Expr index=de.getIndex();
+ if (!index.isValue(null)) {/* Not assignable */
+ System.out.println("ERROR:Index isn't assignable");
+ return false;
+ }
+ Updates updates=new Updates(index,i,ap,lexpr,slotnumber);
+ un.addUpdate(updates);
+ }
+ }
+ return true;
+ }
+
+ /** This method constructs bindings for an update using rule
+ * r. The boolean flag isremoval indicates that the update
+ * performs a removal. The function returns true if it is able to
+ * generate a valid set of bindings and false otherwise. */
+
+ boolean constructbindings(Vector bindings, Rule r, AbstractRepair ar, Hashtable setmapping, boolean isremoval) {
+ boolean goodupdate=true;
+ Inclusion inc=r.getInclusion();
+
+ for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
+ Quantifier q=(Quantifier)iterator.next();
+ if ((q instanceof SetQuantifier)||(q instanceof ForQuantifier)) {
+ VarDescriptor vd=null;
+ SetDescriptor set=null;
+ if (q instanceof SetQuantifier) {
+ vd=((SetQuantifier)q).getVar();
+ set=((SetQuantifier)q).getSet();
+ } else {
+ vd=((ForQuantifier)q).getVar();
+ }
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+ Expr tmpe=si.elementexpr;
+ Expr e=si.elementexpr;
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=si.getSet().getType())
+ return false;
+ e=ce.getExpr();
+ }
+
+ if ((e instanceof VarExpr)&&
+ (((VarExpr)e).getVar()==vd)) {
+ /* Can solve for v */
+ if (set==null||!si.getSet().getType().isSubtypeOf(set.getType()))
+ return false;
+ Binding binding=new Binding(vd,0);
+ bindings.add(binding);
+ } else {
+ goodupdate=false;
+ }
+ } else if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+ boolean f1=true;
+ boolean f2=true;
+
+ Expr e=ri.getLeftExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getDomain().getType())
+ return false;
+ e=ce.getExpr();
+ }
+
+ if ((e instanceof VarExpr)&&
+ (((VarExpr)e).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ if (!ri.getRelation().getDomain().getType().isSubtypeOf(set.getType()))
+ return false;
+ if (ar.getDomainSet()!=null)
+ setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
+ bindings.add(binding);
+ } else f1=false;
+
+
+ e=ri.getRightExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getRange().getType())
+ return false;
+ e=ce.getExpr();
+ }
+
+ if ((e instanceof VarExpr)&&
+ (((VarExpr)e).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,1);
+ if (!ri.getRelation().getRange().getType().isSubtypeOf(set.getType()))
+ return false;
+ if (ar.getRangeSet()!=null)
+ setmapping.put(ri.getRightExpr(),ar.getRangeSet());
+ bindings.add(binding);
+ } else f2=false;
+ if (!(f1||f2))
+ goodupdate=false;
+ } else throw new Error("Inclusion not recognized");
+ if (!goodupdate)
+ if (isremoval) {
+ /* Removals don't need bindings anymore
+ Binding binding=new Binding(vd);
+ bindings.add(binding);*/
+ goodupdate=true;
+ } else if (q instanceof SetQuantifier) {
+ /* Create new element to bind to */
+ // search if the set 'set' has a size
+ Binding binding=new Binding(vd,set,exactsize.getsize(set)==1);
+ bindings.add(binding);
+ goodupdate=true;
+
+ } else
+ goodupdate=false;
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier)q;
+ for(int k=0;k<2;k++) {
+ VarDescriptor vd=(k==0)?rq.x:rq.y;
+ TypeDescriptor td=(k==0)?rq.getRelation().getDomain().getType():rq.getRelation().getRange().getType();
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+
+ Expr e=si.elementexpr;
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=td)
+ return false;
+ e=ce.getExpr();
+ }
+
+ if ((e instanceof VarExpr)&&
+ (((VarExpr)e).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+
+ if (!si.getSet().getType().isSubtypeOf(td))
+ return false;
+ bindings.add(binding);
+ } else
+ goodupdate=false;
+ } else if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+ boolean f1=true;
+ boolean f2=true;
+
+
+ Expr e=ri.getLeftExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getDomain().getType())
+ return false;
+ e=ce.getExpr();
+ }
+ if ((ri.getLeftExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ if (!ri.getRelation().getDomain().getType().isSubtypeOf(td))
+ return false;
+ if (ar.getDomainSet()!=null)
+ setmapping.put(ri.getLeftExpr(),ar.getDomainSet());
+ bindings.add(binding);
+ } else f1=false;
+
+
+ e=ri.getRightExpr();
+
+ while(e instanceof CastExpr) {
+ CastExpr ce=(CastExpr)e;
+ if (ce.getType()!=ri.getRelation().getRange().getType())
+ return false;
+ e=ce.getExpr();
+ }
+ if ((ri.getRightExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,1);
+ if (!ri.getRelation().getRange().getType().isSubtypeOf(td))
+ return false;
+ if (ar.getRangeSet()!=null)
+ setmapping.put(ri.getRightExpr(),ar.getRangeSet());
+ bindings.add(binding);
+ } else f2=false;
+ if (!(f1||f2))
+ goodupdate=false;
+ } else throw new Error("Inclusion not recognized");
+ if (!goodupdate)
+ if (isremoval) {
+ /* Removals don't need bindings anymore
+ Binding binding=new Binding(vd);
+ bindings.add(binding);*/
+ goodupdate=true;
+ } else
+ break;
+ }
+ if (!goodupdate)
+ break;
+ } else throw new Error("Quantifier not recognized");
+ }
+ return goodupdate;
+ }
+
+ /** Adds updates that add an item to the appropriate set or
+ * relation quantified over by the model definition rule.. */
+
+ boolean processquantifiers(GraphNode gn,UpdateNode un, Rule r,Hashtable setmapping) {
+ Inclusion inc=r.getInclusion();
+ for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
+ Quantifier q=(Quantifier)iterator.next();
+ /* Add quantifier */
+ if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier)q;
+ TupleOfExpr toe=new TupleOfExpr(new VarExpr(rq.x),new VarExpr(rq.y),rq.relation);
+ toe.td=ReservedTypeDescriptor.INT;
+ Updates u=new Updates(toe,false);
+ un.addUpdate(u);
+ if (abstractadd.containsKey(rq.relation)) {
+ GraphNode agn=(GraphNode)abstractadd.get(rq.relation);
+ GraphNode.Edge e=new GraphNode.Edge("requires",agn);
+ gn.addEdge(e);
+ } else {
+ return false;
+ }
+ } else if (q instanceof SetQuantifier) {
+ SetQuantifier sq=(SetQuantifier)q;
+ if (un.getBinding(sq.var).getType()==Binding.SEARCH) {
+ Binding b=un.getBinding(sq.var);
+ Constraint reqc=exactsize.getConstraint(b.getSet());
+ constraintdependence.requiresConstraint(gn,reqc);
+ continue; /* Don't need to ensure addition for search */
+ }
+ VarExpr ve=new VarExpr(sq.var);
+ SetDescriptor sd=findExpr(setmapping, ve);
+ if (sd!=null&&sd.isSubset(sq.set))
+ continue; /* this update is trivially true */
+
+ ElementOfExpr eoe=new ElementOfExpr(ve,sq.set);
+ eoe.td=ReservedTypeDescriptor.INT;
+ Updates u=new Updates(eoe,false);
+ un.addUpdate(u);
+ if (abstractadd.containsKey(sq.set)) {
+ GraphNode agn=(GraphNode)abstractadd.get(sq.set);
+ GraphNode.Edge e=new GraphNode.Edge("requires",agn);
+ gn.addEdge(e);
+ } else {
+ return false;
+ }
+ } else return false;
+ }
+ return true;
+ }
+
+ static SetDescriptor findExpr(Hashtable setmapping, Expr e) {
+ if (setmapping==null)
+ return null;
+ Set kset=setmapping.keySet();
+ for(Iterator it=kset.iterator();it.hasNext();) {
+ Expr expr=(Expr)it.next();
+ if (expr.equals(null,e)) {
+ return (SetDescriptor)setmapping.get(expr);
+ }
+ }
+ return null;
+ }
+
+ /** This method generates the necessary updates to satisfy the
+ * conjunction ruleconj. */
+
+ boolean processconjunction(UpdateNode un,RuleConjunction ruleconj,Hashtable setmapping) {
+ boolean okay=true;
+ for(int k=0;k<ruleconj.size();k++) {
+ DNFExpr de=ruleconj.get(k);
+ Expr e=de.getExpr();
+ if (e instanceof OpExpr) {
+ OpExpr ex=(OpExpr)de.getExpr();
+ Opcode op=ex.getOpcode();
+ Updates up=new Updates(ex.left,ex.right,op, de.getNegation());
+ un.addUpdate(up);
+ } else if (e instanceof ElementOfExpr) {
+ SetDescriptor sd=findExpr(setmapping, ((ElementOfExpr)e).element);
+ if (sd!=null&&sd.isSubset(((ElementOfExpr)e).set))
+ continue; /* this update is trivially true */
+ Updates up=new Updates(e,de.getNegation());
+ un.addUpdate(up);
+ } else if (e instanceof TupleOfExpr) {
+ Updates up=new Updates(e,de.getNegation());
+ un.addUpdate(up);
+ } else if (e instanceof BooleanLiteralExpr) {
+ boolean truth=((BooleanLiteralExpr)e).getValue();
+ if (de.getNegation())
+ truth=!truth;
+ if (!truth) {
+ okay=false;
+ break;
+ }
+ } else {
+ System.out.println(e.getClass().getName());
+ throw new Error("Unrecognized Expr");
+ }
+ }
+ return okay;
+ }
+
+ /** This method sees if when the quantifiers listed in set are
+ * fixed, whether there can be more than one unique binding for
+ * the constraint or model definition rule qs.*/
+ public boolean analyzeQuantifiers(Quantifiers qs,Set set) {
+ for(int i=0;i<qs.numQuantifiers();i++) {
+ Quantifier q=qs.getQuantifier(i);
+ if (set.contains(q))
+ continue;
+ if (q instanceof SetQuantifier) {
+ SetDescriptor sd=((SetQuantifier)q).getSet();
+ if (maxsize.getsize(sd)<=1&&
+ maxsize.getsize(sd)>=0)
+ continue;
+ } else if (q instanceof RelationQuantifier) {
+ RelationDescriptor rd=((RelationQuantifier)q).getRelation();
+ if (maxsize.getsize(rd)<=1&&
+ maxsize.getsize(rd)>=0)
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public boolean mutuallyexclusive(SetDescriptor sd1, SetDescriptor sd2) {
+ if (mutualexclusive(sd1,sd2)||
+ mutualexclusive(sd2,sd1))
+ return true;
+ else
+ return false;
+ }
+
+ private boolean mutualexclusive(SetDescriptor sd1, SetDescriptor sd2) {
+ Vector rules=state.vRules;
+ for(int i=0;i<rules.size();i++) {
+ Rule r=(Rule)rules.get(i);
+ if (r.getInclusion().getTargetDescriptors().contains(sd1)) {
+ /* Rule may add items to sd1 */
+ SetInclusion si=(SetInclusion)r.getInclusion();
+ Expr ve=si.getExpr();
+ DNFRule drule=r.getDNFGuardExpr();
+ for(int j=0;j<drule.size();j++) {
+ RuleConjunction rconj=drule.get(j);
+ boolean containsexclusion=false;
+ for (int k=0;k<rconj.size();k++) {
+ DNFExpr dexpr=rconj.get(k);
+ if (dexpr.getNegation()&&
+ dexpr.getExpr() instanceof ElementOfExpr&&
+ ((ElementOfExpr)dexpr.getExpr()).element.equals(null,ve)) {
+ SetDescriptor sd=((ElementOfExpr)dexpr.getExpr()).set;
+ if (sd.isSubset(sd2))
+ containsexclusion=true;
+ }
+ }
+ if (!containsexclusion)
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ boolean equivalent(SetExpr se, RelationExpr re) {
+ if (!(se instanceof ImageSetExpr))
+ return false;
+ ImageSetExpr ise=(ImageSetExpr)se;
+ while(re!=null&&ise!=null) {
+ if (re.getRelation()!=ise.getRelation())
+ return false;
+ if (re.inverted()!=ise.inverted())
+ return false;
+ if (ise.isimageset) {
+ ise=ise.getImageSetExpr();
+ if (!(re.getExpr() instanceof RelationExpr))
+ return false;
+ re=(RelationExpr)re.getExpr();
+ } else {
+ if (!(re.getExpr() instanceof VarExpr))
+ return false;
+ if (((VarExpr)re.getExpr()).getVar()==ise.getVar())
+ return true; //everything matches
+ return false;
+ }