Update:
authorbdemsky <bdemsky>
Mon, 19 Apr 2004 21:48:08 +0000 (21:48 +0000)
committerbdemsky <bdemsky>
Mon, 19 Apr 2004 21:48:08 +0000 (21:48 +0000)
1. Removes some old debugging code
2. Simplifies some complex case statements
3. Uses maxsize calculations for set additions
4. Starts to support create/search new element type bindings.

Repair/RepairCompiler/MCC/IR/AbstractInterferes.java
Repair/RepairCompiler/MCC/IR/Binding.java
Repair/RepairCompiler/MCC/IR/ComputeMaxSize.java
Repair/RepairCompiler/MCC/IR/ConcreteInterferes.java
Repair/RepairCompiler/MCC/IR/ForQuantifier.java
Repair/RepairCompiler/MCC/IR/Opcode.java
Repair/RepairCompiler/MCC/IR/Termination.java
Repair/RepairCompiler/MCC/IR/UpdateNode.java
Repair/RepairCompiler/MCC/IR/Updates.java

index ea024cdb22bf699d4474cdd40e2f6edc13836a3f..affa0354239bd36d432d88bc34465bbdd832f27d 100755 (executable)
@@ -2,6 +2,11 @@ package MCC.IR;
 import java.util.*;
 
 class AbstractInterferes {
+    Termination termination;
+
+    public AbstractInterferes(Termination t) {
+       termination=t;
+    }
 
     /** Does performing the AbstractRepair ar satisfy (or falsify if satisfy=false)
      * Rule r */
@@ -55,7 +60,7 @@ class AbstractInterferes {
 
     /** Does performing the AbstractRepair ar falsify the predicate dp */
 
-    static public boolean interferes(AbstractRepair ar, DNFPredicate dp) {
+    public boolean interferes(AbstractRepair ar, DNFPredicate dp) {
        if ((ar.getDescriptor()!=dp.getPredicate().getDescriptor()) &&
            ((ar.getDescriptor() instanceof SetDescriptor)||
             !dp.getPredicate().usesDescriptor((RelationDescriptor)ar.getDescriptor())))
@@ -74,35 +79,24 @@ class AbstractInterferes {
            boolean neg2=dp.isNegated();
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
-           if ((!neg1&&((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE))||
-               (neg1&&((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.LT)||op1==Opcode.LE))) {
+           op1=Opcode.translateOpcode(neg1,op1);
+           op2=Opcode.translateOpcode(neg2,op2);
+
+           if ((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE) {
                int size1a=0;
-               if (!neg1) {
-                   if((op1==Opcode.EQ)||(op1==Opcode.GE))
-                       size1a=size1;
-                   if((op1==Opcode.GT)||(op1==Opcode.NE))
-                       size1a=size1+1;
-               }
-               if (neg1) {
-                   if((op1==Opcode.EQ)||(op1==Opcode.LE))
-                       size1a=size1+1;
-                   if((op1==Opcode.LT)||(op1==Opcode.NE))
-                       size1a=size1;
-               }
-               if ((!neg2&&(op2==Opcode.EQ)&&(size1a==size2))||
-                   (neg2&&(op2==Opcode.EQ)&&(size1a!=size2))||
-                   (!neg2&&(op2==Opcode.NE)&&(size1a!=size2))||
-                   (neg2&&(op2==Opcode.NE)&&(size1a==size2))||
-                   (!neg2&&(op2==Opcode.GE))||
-                   (!neg2&&(op2==Opcode.GT))||
-                   (neg2&&(op2==Opcode.LE))||
-                   (neg2&&(op2==Opcode.LT))||
-                   (neg2&&(op2==Opcode.GE)&&(size1a<size2))||
-                   (neg2&&(op2==Opcode.GT)&&(size1a<=size2))||
-                   (!neg2&&(op2==Opcode.LE)&&(size1a<=size2))||
-                   (!neg2&&(op2==Opcode.LT)&&(size1a<size2)))
+               if((op1==Opcode.EQ)||(op1==Opcode.GE))
+                   size1a=size1;
+               if((op1==Opcode.GT)||(op1==Opcode.NE))
+                   size1a=size1+1;
+
+               if (((op2==Opcode.EQ)&&(size1a==size2))||
+                   ((op2==Opcode.NE)&&(size1a!=size2))||
+                   (op2==Opcode.GE)||
+                   (op2==Opcode.GT)||
+                   ((op2==Opcode.LE)&&(size1a<=size2))||
+                   ((op2==Opcode.LT)&&(size1a<size2)))
                    return false;
-           } 
+           }
        }
 
        if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
@@ -113,16 +107,23 @@ class AbstractInterferes {
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
 
-           op2=translateOpcode(neg2,op2);
+           op2=Opcode.translateOpcode(neg2,op2);
 
-           if (((op2==Opcode.EQ)&&(size2==0))||
+           int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
+
+           if ((maxsize!=-1)&&
+               ((op2==Opcode.LT&&size2>maxsize)||
+                (op2==Opcode.LE&&size2>=maxsize)||
+                (op2==Opcode.EQ&&size2>=maxsize)))
+               return false;
+
+           if (((op2==Opcode.NE)&&(size2==0))||
                (op2==Opcode.GE)||
                (op2==Opcode.GT))
                return false;
        }
 
        if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
-           
            (ar.getType()==AbstractRepair.MODIFYRELATION)&&
            (dp.getPredicate() instanceof ExprPredicate)&&
            (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
@@ -142,8 +143,8 @@ class AbstractInterferes {
            Expr expr2=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).right;
 
            /* Translate the opcodes */
-           op1=translateOpcode(neg1,op1);
-           op2=translateOpcode(neg2,op2);
+           op1=Opcode.translateOpcode(neg1,op1);
+           op2=Opcode.translateOpcode(neg2,op2);
            
            /* Obvious cases which can't interfere */
            if (((op1==Opcode.GT)||
@@ -236,8 +237,8 @@ class AbstractInterferes {
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
            /* Translate the opcodes */
-           op1=translateOpcode(neg1,op1);
-           op2=translateOpcode(neg2,op2);
+           op1=Opcode.translateOpcode(neg1,op1);
+           op2=Opcode.translateOpcode(neg2,op2);
 
            if (((op1==Opcode.EQ)||(op1==Opcode.LT)||op1==Opcode.LE)||(op1==Opcode.NE)) {
                int size1a=0;
@@ -264,12 +265,11 @@ class AbstractInterferes {
            boolean neg2=dp.isNegated();
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
-           if ((!neg2&&(op2==Opcode.EQ)&&(size2==0))||
-               (neg2&&(op2==Opcode.NE)&&(size2==0))||
-               (neg2&&(op2==Opcode.GE))||
-               (neg2&&(op2==Opcode.GT))||
-               (!neg2&&(op2==Opcode.LE))||
-               (!neg2&&(op2==Opcode.LT)))
+           op2=Opcode.translateOpcode(neg2,op2);
+
+           if (((op2==Opcode.EQ)&&(size2==0))||
+               (op2==Opcode.LE)||
+               (op2==Opcode.LT))
                return false;
            
        }
@@ -288,30 +288,10 @@ class AbstractInterferes {
        return true;
     }
 
-    static private Opcode translateOpcode(boolean neg, Opcode op) {
-       if (neg) {
-        /* 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;
-        }
-
-       return op;
-    }
-
     /** Does the increase (or decrease) in scope of a model defintion rule represented by sn
      * falsify the predicate dp */
 
-    static public boolean interferes(ScopeNode sn, DNFPredicate dp) {
+    public boolean interferes(ScopeNode sn, DNFPredicate dp) {
        if (!sn.getSatisfy()&&(sn.getDescriptor() instanceof SetDescriptor)) {
            Rule r=sn.getRule();
            Set target=r.getInclusion().getTargetDescriptors();
@@ -333,21 +313,8 @@ class AbstractInterferes {
                boolean neg=dp.isNegated();
                Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
                int size=((ExprPredicate)dp.getPredicate()).rightSize();
-               if (neg) {
-                   /* 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;
-               }
+               op=Opcode.translateOpcode(neg,op);
+
                if ((op==Opcode.GE)&&
                    ((size==0)||(size==1)))
                    return false;
@@ -362,7 +329,7 @@ class AbstractInterferes {
     /** Does increasing (or decreasing if satisfy=false) the size of the set or relation des
      * falsify the predicate dp */
 
-    static public boolean interferes(Descriptor des, boolean satisfy, DNFPredicate dp) {
+    public boolean interferes(Descriptor des, boolean satisfy, DNFPredicate dp) {
        if ((des!=dp.getPredicate().getDescriptor()) &&
            ((des instanceof SetDescriptor)||
             !dp.getPredicate().usesDescriptor((RelationDescriptor)des)))
@@ -376,13 +343,20 @@ class AbstractInterferes {
            boolean neg2=dp.isNegated();
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
+           op2=Opcode.translateOpcode(neg2,op2);
+
+
+           int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
            {
-               if ((!neg2&&(op2==Opcode.GE))||
-                   (!neg2&&(op2==Opcode.GT))||
-                   (neg2&&(op2==Opcode.EQ)&&(size2==0))||
-                   (!neg2&&(op2==Opcode.NE)&&(size2==0))||
-                   (neg2&&(op2==Opcode.LE))||
-                   (neg2&&(op2==Opcode.LT)))
+               if ((maxsize!=-1)&&
+                   ((op2==Opcode.LT&&size2>maxsize)||
+                    (op2==Opcode.LE&&size2>=maxsize)||
+                    (op2==Opcode.EQ&&size2>=maxsize)))
+                   return false;
+
+               if ((op2==Opcode.GE)||
+                   (op2==Opcode.GT)||
+                   (op2==Opcode.NE)&&(size2==0))
                    return false;
            }
        }
@@ -394,13 +368,11 @@ class AbstractInterferes {
            boolean neg2=dp.isNegated();
            Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
            int size2=((ExprPredicate)dp.getPredicate()).rightSize();
+           op2=Opcode.translateOpcode(neg2,op2);
            {
-               if ((neg2&&(op2==Opcode.GE))||
-                   (neg2&&(op2==Opcode.GT))||
-                   (!neg2&&(op2==Opcode.EQ)&&(size2==0))||
-                   (neg2&&(op2==Opcode.NE)&&(size2==0))||
-                   (!neg2&&(op2==Opcode.LE))||
-                   (!neg2&&(op2==Opcode.LT)))
+               if (((op2==Opcode.EQ)&&(size2==0))||
+                   (op2==Opcode.LE)||
+                   (op2==Opcode.LT))
                    return false;
            } 
        }
index 163f2379dd559bfa8a8d128a0b56aeb91c4e35ab..33e9bae5f141a37b564d0820347843060380d5f5 100755 (executable)
@@ -2,28 +2,56 @@ package MCC.IR;
 
 class Binding {
     VarDescriptor var;
+    SetDescriptor sd;
     int position;
-    boolean search;
+    int type;
+    public static final int POSITION=1;
+    public static final int CREATE=2;
+    public static final int SEARCH=3;
+
     public Binding(VarDescriptor vd,int pos) {
        var=vd;
        position=pos;
-       search=false;
+       type=POSITION;
     }
 
-    public Binding(VarDescriptor vd) {
-       var=vd;
-       search=true;
+    public Binding(VarDescriptor vd, SetDescriptor sd,boolean search) {
+       this.var=vd;
+       this.sd=sd;
+       if (search)
+           type=SEARCH;
+       else
+           type=CREATE;
     }
+
+    public int getType() {
+       return type;
+    }
+
     int getPosition() {
+       assert type==POSITION;
        return position;
     }
+
+    SetDescriptor getSet() {
+       assert type==CREATE||type==SEARCH;
+       return sd;
+    }
+
     VarDescriptor getVar() {
        return var;
     }
+
     public String toString() {
-       if (search)
-           return "SEARCHFOR"+var.toString();
-       else
+       switch(type) {
+       case POSITION:
            return var.toString()+"="+String.valueOf(position);
+       case CREATE:
+           return var.toString()+"=CREATE("+sd.toString()+")";
+       case SEARCH:
+           return var.toString()+"=SEARCH("+sd.toString()+")";
+       default:
+           return "UNRECOGNIZED Binding type";
+       }
     }
 }
index 0dec8e0db4b52f3f52b7df07a6ffe6ebe4606e1f..51221c3e7484901eb5a7b992c3c6397a60da01f1 100755 (executable)
@@ -44,13 +44,22 @@ public class ComputeMaxSize {
                                }
                                if ((size!=0)&&(d==d2))
                                    size=-1;
-                           } if (q instanceof SetQuantifier) {
+                           } else if (q instanceof SetQuantifier) {
                                Descriptor d2=((SetQuantifier)q).getSet();
                                if (sizemap.containsKey(d2)) {
                                    size=((Integer)sizemap.get(d2)).intValue();
                                }
                                if ((size!=0)&&(d==d2))
                                    size=-1;
+                           } else if (q instanceof ForQuantifier) {
+                               ForQuantifier fq=(ForQuantifier)q;
+                               boolean lowint=OpExpr.isInt(fq.lower);
+                               boolean highint=OpExpr.isInt(fq.upper);
+                               if (lowint&&highint) {
+                                   size=1+OpExpr.getInt(fq.upper)-OpExpr.getInt(fq.lower);
+                                   if (size<=0) /* Catch sneaky bounds */
+                                       throw new Error("Funny bounds in: "+fq);
+                               } else size=-1;
                            } else {
                                size=-1;
                            }
index 8cb19f8e321761ebabc932a9c5e4c58cea6153e9..f8d82d522eef4d5bf0b42cce1e6fd3ae073e68ac 100755 (executable)
@@ -93,22 +93,8 @@ class ConcreteInterferes {
 
 
                    Opcode op=expr.getOpcode();
+                   op=Opcode.translateOpcode(dexpr.getNegation(),op);
 
-                   if (dexpr.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;
-                   }
                    boolean match=false;
                    for(int k=0;k<un.numUpdates();k++) {
                        Updates update=un.getUpdate(k);
@@ -297,21 +283,8 @@ class ConcreteInterferes {
                Expr lexpr2=expr.getLeftExpr();
                Expr rexpr2=expr.getRightExpr();
                Opcode op2=expr.getOpcode();
-               if (dexpr.getNegation()) {
-                   /* remove negation through opcode translation */
-                   if (op2==Opcode.GT)
-                       op2=Opcode.LE;
-                   else if (op2==Opcode.GE)
-                       op2=Opcode.LT;
-                   else if (op2==Opcode.EQ)
-                       op2=Opcode.NE;
-                   else if (op2==Opcode.NE)
-                       op2=Opcode.EQ;
-                   else if (op2==Opcode.LT)
-                       op2=Opcode.GE;
-                   else if (op2==Opcode.LE)
-                       op2=Opcode.GT;
-               }
+               op2=Opcode.translateOpcode(dexpr.getNegation(),op2);
+
                good=true;
                vars=rexpr2.freeVars();
                VarDescriptor leftdescriptor=null;
index 7cefd2c14a92216c0f7d78674dcd3abcaf0f62af..317d12c33c8b8f1139366bf56c7326cf2875c5a9 100755 (executable)
@@ -18,7 +18,6 @@ public class ForQuantifier extends Quantifier {
        return var;
     }
 
-
     public void setBounds(Expr lower, Expr upper) {
         this.lower = lower;
         this.upper = upper;
index eed9bba9807a9409928dd2d559b57ebc0f95b98b..a1dfac7217f8e0d81e5847ecdf74a78209ed1b0e 100755 (executable)
@@ -27,6 +27,27 @@ public class Opcode {
     public static final Opcode NOP = new Opcode("NOP");
     public static final Opcode SHL = new Opcode("<<");
     public static final Opcode SHR = new Opcode(">>");
+    
+    static public Opcode translateOpcode(boolean neg, Opcode op) {
+       if (neg) {
+        /* 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;
+           else throw new Error("Unrecognized Opcode");
+        }
+
+       return op;
+    }
 
     public static Opcode decodeFromString(String opname) {
         Opcode opcode;
index 73c89f10d8e7ceae652517c6e99c1f1f5c65e4a4..d6a792f6ffbd4953ba86b40fb2c95891b206331f 100755 (executable)
@@ -25,6 +25,8 @@ public class Termination {
     Set removedset;
     ComputeMaxSize maxsize;
     State state;
+    AbstractInterferes abstractinterferes;
+
 
     public Termination(State state) {
        this.state=state;
@@ -45,6 +47,7 @@ public class Termination {
        if (!Compiler.REPAIR)
            return;
 
+       
        for(int i=0;i<state.vRules.size();i++)
            System.out.println(state.vRules.get(i));
        for(int i=0;i<state.vConstraints.size();i++)
@@ -53,6 +56,7 @@ public class Termination {
 
        maxsize=new ComputeMaxSize(state);
 
+       abstractinterferes=new AbstractInterferes(this);
        generateconjunctionnodes();
        generatescopenodes();
        generaterepairnodes();
@@ -109,9 +113,14 @@ public class Termination {
        }
 
     }
-    
+
+
+    /** This method generates a node for each conjunction in the DNF form of each constraint. 
+     * It also converts the quantifiers into conjunctions also - constraints can be satisfied by
+     * removing items from the sets and relations they are quantified over */
     void generateconjunctionnodes() {
        Vector constraints=state.vConstraints;
+       // Constructs conjunction nodes
        for(int i=0;i<constraints.size();i++) {
            Constraint c=(Constraint)constraints.get(i);
            DNFConstraint dnf=c.dnfconstraint;
@@ -126,6 +135,7 @@ public class Termination {
                ((Set)conjunctionmap.get(c)).add(gn);
                conjtonodemap.put(dnf.get(j),gn);
            }
+           // Construct quantifier "conjunction" nodes
            for(int j=0;j<c.numQuantifiers();j++) {
                Quantifier q=c.getQuantifier(j);
                if (q instanceof SetQuantifier) {
@@ -200,7 +210,7 @@ public class Termination {
                for(int i=0;i<conj.size();i++) {
                    DNFPredicate dp=conj.get(i);
                    if (AbstractInterferes.interferes(ar,cons)||
-                       AbstractInterferes.interferes(ar,dp)) {
+                       abstractinterferes.interferes(ar,dp)) {
                        GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
                        gn.addEdge(e);
                        break;
@@ -234,7 +244,7 @@ public class Termination {
                Constraint constr=tn2.getConstraint();
                for(int i=0;i<conj.size();i++) {
                    DNFPredicate dp=conj.get(i);
-                   if (AbstractInterferes.interferes(sn,dp)||
+                   if (abstractinterferes.interferes(sn,dp)||
                        AbstractInterferes.interferes(sn.getDescriptor(),sn.getSatisfy(),constr)) {
                        GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
                        GraphNode gnconseq=(GraphNode)consequence.get(sn);
@@ -263,7 +273,7 @@ public class Termination {
        }
     }
 
-    /* Generates the abstract repair nodes */
+    /** This method generates the abstract repair nodes. */
     void generaterepairnodes() {
        /* Generate repairs of conjunctions */
        for(Iterator conjiterator=conjunctions.iterator();conjiterator.hasNext();) {
@@ -529,7 +539,7 @@ public class Termination {
        }
     }
 
-    static void increment(int count[], Vector rules,boolean isremove) {
+    static private void increment(int count[], Vector rules,boolean isremove) {
        count[0]++;
        for(int i=0;i<(rules.size()-1);i++) {
            int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
@@ -540,7 +550,7 @@ public class Termination {
        }
     }
 
-    static boolean remains(int count[], Vector rules, boolean isremove) {
+    static private boolean remains(int count[], Vector rules, boolean isremove) {
        for(int i=0;i<rules.size();i++) {
            int num=isremove?(((Rule)rules.get(i)).numQuantifiers()+(((Rule)rules.get(i)).getDNFNegGuardExpr().size())):((Rule)rules.get(i)).getDNFGuardExpr().size();
            if (count[i]>=num) {
@@ -635,7 +645,10 @@ public class Termination {
            increment(count,possiblerules,false);
        }
     }
-
+    /** 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, boolean isremoval) {
        boolean goodupdate=true;
@@ -647,8 +660,10 @@ public class Termination {
                SetDescriptor set=null;
                if (q instanceof SetQuantifier) {
                    vd=((SetQuantifier)q).getVar();
-               } else
+                   set=((SetQuantifier)q).getSet();
+               } else {
                    vd=((ForQuantifier)q).getVar();
+               }
                if(inc instanceof SetInclusion) {
                    SetInclusion si=(SetInclusion)inc;
                    if ((si.elementexpr instanceof VarExpr)&&
@@ -656,8 +671,9 @@ public class Termination {
                        /* Can solve for v */
                        Binding binding=new Binding(vd,0);
                        bindings.add(binding);
-                   } else
+                   } else {
                        goodupdate=false;
+                   }
                } else if (inc instanceof RelationInclusion) {
                    RelationInclusion ri=(RelationInclusion)inc;
                    boolean f1=true;
@@ -679,11 +695,17 @@ public class Termination {
                } else throw new Error("Inclusion not recognized");
                if (!goodupdate)
                    if (isremoval) {
-                       Binding binding=new Binding(vd);
+                       /* Removals don't need bindings anymore
+                          Binding binding=new Binding(vd);
+                          bindings.add(binding);*/
+                       goodupdate=true;
+                   } else {
+                       /* Create new element to bind to */
+                       Binding binding=new Binding(vd,set,createorsearch(set));
                        bindings.add(binding);
                        goodupdate=true;
-                   } else
-                       break;
+                       //FIXME
+                   }
            } else if (q instanceof RelationQuantifier) {
                RelationQuantifier rq=(RelationQuantifier)q;
                for(int k=0;k<2;k++) {
@@ -718,8 +740,9 @@ public class Termination {
                    } else throw new Error("Inclusion not recognized");
                    if (!goodupdate)
                        if (isremoval) {
-                           Binding binding=new Binding(vd);
-                           bindings.add(binding);
+                           /* Removals don't need bindings anymore
+                              Binding binding=new Binding(vd);
+                              bindings.add(binding);*/
                            goodupdate=true;
                        } else
                            break;
@@ -731,15 +754,17 @@ public class Termination {
        return goodupdate;
     }
 
+    /** Returns true if we search for an element from sd
+     *  false if we create an element for sd */
+    private boolean createorsearch(SetDescriptor sd) {
+       return false;
+    }
+
     static int addtocount=0;
     void generateaddtosetrelation(GraphNode gn, AbstractRepair ar) {
-       //      System.out.println("Attempting to generate add to set");
-       //System.out.println(ar.getPredicate().getPredicate().name());
-       //System.out.println(ar.getPredicate().isNegated());
        for(int i=0;i<state.vRules.size();i++) {
            Rule r=(Rule) state.vRules.get(i);
            /* See if this is a good rule*/
-           //System.out.println(r.getGuardExpr().name());
            if ((r.getInclusion() instanceof SetInclusion&&
                ar.getDescriptor()==((SetInclusion)r.getInclusion()).getSet())||
                (r.getInclusion() instanceof RelationInclusion&&
@@ -748,10 +773,8 @@ public class Termination {
                /* First solve for quantifiers */
                Vector bindings=new Vector();
                /* Construct bindings */
-               //System.out.println("Attempting to generate add to set: #2");
                if (!constructbindings(bindings,r,false))
                    continue;
-               //System.out.println("Attempting to generate add to set: #3");
                //Generate add instruction
                DNFRule dnfrule=r.getDNFGuardExpr();
                for(int j=0;j<dnfrule.size();j++) {
@@ -805,16 +828,15 @@ public class Termination {
                    }
                    //Finally build necessary updates to satisfy conjunction
                    RuleConjunction ruleconj=dnfrule.get(j);
+
                    /* Add in updates for quantifiers */
-                   //System.out.println("Attempting to generate add to set #4");
                    MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.ADD);
                    TermNode tn=new TermNode(mun);
                    GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
 
-                   if (processquantifers(gn2,un, r)&&debugdd()&&
+                   if (processquantifers(gn2,un, r)&&
                        processconjunction(un,ruleconj)&&
                        un.checkupdates()) {
-                       //System.out.println("Attempting to generate add to set #5");
                        mun.addUpdate(un);
                        GraphNode.Edge e=new GraphNode.Edge("abstract"+addtocount,gn2);
                        addtocount++;
@@ -824,12 +846,10 @@ public class Termination {
            }
        }
     }
-
-    boolean debugdd() {
-       //System.out.println("Attempting to generate add to set DD");
-       return true;
-    }
-
+    
+    /** Adds updates that add an item to the appropriate set or
+     * relation quantified over by the model definition rule.. */
+    
     boolean processquantifers(GraphNode gn,UpdateNode un, Rule r) {
        Inclusion inc=r.getInclusion();
        for(Iterator iterator=r.quantifiers();iterator.hasNext();) {
@@ -849,7 +869,7 @@ public class Termination {
                } else {
                    return false;
                }
-
+               
            } else if (q instanceof SetQuantifier) {
                SetQuantifier sq=(SetQuantifier)q;
                ElementOfExpr eoe=new ElementOfExpr(new VarExpr(sq.var),sq.set);
index 0ed097d3c6bd3e57b721c6a3a26eff33223766cf..00ac87f5b7718d0cb37f61f77657afbcc6171097 100755 (executable)
@@ -177,6 +177,14 @@ class UpdateNode {
        binding.put(b.getVar(),b);
     }
 
+    public int numBindings() {
+       return bindings.size();
+    }
+
+    public Binding getBinding(int i) {
+       return (Binding)bindings.get(i);
+    }
+    
     public Binding getBinding(VarDescriptor vd) {
        if (binding.containsKey(vd))
            return (Binding)binding.get(vd);
@@ -420,8 +428,9 @@ class UpdateNode {
     private void generate_bindings(CodeWriter cr, String slot0, String slot1) {
        for(int i=0;i<bindings.size();i++) {
            Binding b=(Binding)bindings.get(i);
-           if (b.search)
-               throw new Error("Search not implemented for bindings");
+           if (b.getType()!=Binding.POSITION)
+               throw new Error("Only position bindings implemented!");
+
            VarDescriptor vd=b.getVar();
            switch(b.getPosition()) {
            case 0:
index f17d9564253cd9785be07832a5851518641708ff..684dfc8d630c11d9dc0e08f3c1b945015f359b1b 100755 (executable)
@@ -27,21 +27,9 @@ class Updates {
            System.out.println("Building invalid update");
        leftexpr=lexpr;
        type=Updates.EXPR;
-       if (negate) {
-       /* 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;
-       }
+
+       op=Opcode.translateOpcode(negate,op);
+
        opcode=op;
        rightexpr=rexpr;
     }