+ DNFRule dnfrule=r.getDNFGuardExpr();
+ for(int j=0;j<dnfrule.size();j++) {
+ Inclusion inc=r.getInclusion();
+ UpdateNode un=new UpdateNode();
+ /* First solve for quantifiers */
+ boolean goodupdate=true;
+ for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
+ Quantifier q=(Quantifier)iterator.next();
+ boolean foundall=true;
+ if ((q instanceof SetQuantifier)||(q instanceof ForQuantifier)) {
+ VarDescriptor vd=null;
+ if (q instanceof SetQuantifier)
+ vd=((SetQuantifier)q).getVar();
+ else
+ vd=((ForQuantifier)q).getVar();
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+ if ((si.elementexpr instanceof VarExpr)&&
+ (((VarExpr)si.elementexpr).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else
+ foundall=false;
+ } else if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+ boolean f1=true;
+ boolean f2=true;
+ if ((ri.getLeftExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else f1=false;
+ if ((ri.getRightExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else f2=false;
+ if (!(f1||f2))
+ foundall=false;
+ } else throw new Error("Inclusion not recognized");
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier)q;
+ for(int k=0;k<2;k++) {
+ VarDescriptor vd=(k==0)?rq.x:rq.y;
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+ if ((si.elementexpr instanceof VarExpr)&&
+ (((VarExpr)si.elementexpr).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else
+ foundall=false;
+ } else if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+ boolean f1=true;
+ boolean f2=true;
+ if ((ri.getLeftExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getLeftExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else f1=false;
+ if ((ri.getRightExpr() instanceof VarExpr)&&
+ (((VarExpr)ri.getRightExpr()).getVar()==vd)) {
+ /* Can solve for v */
+ Binding binding=new Binding(vd,0);
+ un.addBinding(binding);
+ } else f2=false;
+ if (!(f1||f2))
+ foundall=false;
+ } else throw new Error("Inclusion not recognized");
+ }
+ } else throw new Error("Quantifier not recognized");
+ if (!foundall) {
+ goodupdate=false;
+ break;
+ }
+ /* Now build update for tuple/set inclusion condition */
+ if(inc instanceof SetInclusion) {
+ SetInclusion si=(SetInclusion)inc;
+ if (!(si.elementexpr instanceof VarExpr)) {
+ Updates up=new Updates(si.elementexpr,0);
+ un.addUpdate(up);
+ }
+ }
+ if (inc instanceof RelationInclusion) {
+ RelationInclusion ri=(RelationInclusion)inc;
+ if (!(ri.getLeftExpr() instanceof VarExpr)) {
+ Updates up=new Updates(ri.getLeftExpr(),0);
+ un.addUpdate(up);
+ }
+ if (!(ri.getRightExpr() instanceof VarExpr)) {
+ Updates up=new Updates(ri.getRightExpr(),0);
+ un.addUpdate(up);
+ }
+ }
+ //Finally build necessary updates to satisfy conjunction
+ RuleConjunction ruleconj=dnfrule.get(j);
+ 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();
+ if (de.getNegation()) {
+ /* remove negation through opcode translation */
+ if (op==Opcode.GT)
+ op=Opcode.LE;
+ else if (op==Opcode.GE)
+ op=Opcode.LT;
+ else if (op==Opcode.EQ)
+ op=Opcode.NE;
+ else if (op==Opcode.NE)
+ op=Opcode.EQ;
+ else if (op==Opcode.LT)
+ op=Opcode.GE;
+ else if (op==Opcode.LE)
+ op=Opcode.GT;
+ }
+ Updates up=new Updates(ex.left,ex.right,op);
+ un.addUpdate(up);
+ } else if (e instanceof ElementOfExpr) {
+ 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 throw new Error("Error #213");
+ }
+ }
+ MultUpdateNode mun=new MultUpdateNode(ar);
+ mun.addUpdate(un);
+ TermNode tn=new TermNode(mun);
+ GraphNode gn2=new GraphNode("Update"+addtocount,tn);
+ GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
+ addtocount++;
+ gn.addEdge(e);
+ updatenodes.add(gn2);
+ }