Checking in code to perform safety checks on repair dependency graph.
[repair.git] / Repair / RepairCompiler / MCC / IR / Termination.java
index 271d9f2fca7744ba18f945b9e12ef036da4e58bb..b788acc3ac8937242cd905b7a216dbe8ff5778f5 100755 (executable)
@@ -47,17 +47,25 @@ public class Termination {
 
        HashSet superset=new HashSet();
        superset.addAll(conjunctions);
-       superset.addAll(abstractrepair);
+       //superset.addAll(abstractrepair);
        //superset.addAll(updatenodes);
        //superset.addAll(scopenodes);
        //superset.addAll(consequencenodes);
-       //GraphNode.computeclosure(superset);
+       GraphNode.computeclosure(superset,null);
        try {
            GraphNode.DOTVisitor.visit(new FileOutputStream("graph.dot"),superset);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
+       for(Iterator it=updatenodes.iterator();it.hasNext();) {
+           GraphNode gn=(GraphNode)it.next();
+           TermNode tn=(TermNode)gn.getOwner();
+           MultUpdateNode mun=tn.getUpdate();
+           System.out.println(gn.getTextLabel());
+           System.out.println(mun.toString());
+       }
+       GraphAnalysis ga=new GraphAnalysis(this);
     }
     
     void generateconjunctionnodes() {
@@ -71,7 +79,9 @@ public class Termination {
                                           "Conj ("+i+","+j+") "+dnf.get(j).name()
                                           ,tn);
                conjunctions.add(gn);
-               conjunctionmap.put(c,gn);
+               if (!conjunctionmap.containsKey(c))
+                   conjunctionmap.put(c,new HashSet());
+               ((Set)conjunctionmap.get(c)).add(gn);
            }
        }
     }
@@ -120,6 +130,16 @@ public class Termination {
                    }
                }
            }
+
+           for(Iterator scopeiterator=scopenodes.iterator();scopeiterator.hasNext();) {
+               GraphNode gn2=(GraphNode)scopeiterator.next();
+               TermNode tn2=(TermNode)gn2.getOwner();
+               ScopeNode sn2=tn2.getScope();
+               if (AbstractInterferes.interferes(ar,sn2.getRule(),sn2.getSatisfy())) {
+                   GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
+                   gn.addEdge(e);
+               }
+           }
        }
     }
     
@@ -180,7 +200,7 @@ public class Termination {
                for(int j=0;j<array.length;j++) {
                    AbstractRepair ar=new AbstractRepair(dp,array[j],d);
                    TermNode tn2=new TermNode(ar);
-                   GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),tn2);
+                   GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
                    GraphNode.Edge e=new GraphNode.Edge("abstract",gn2);
                    gn.addEdge(e);
                    abstractrepair.add(gn2);
@@ -254,7 +274,7 @@ public class Termination {
                MultUpdateNode mun=new MultUpdateNode(sn);
                TermNode tn2=new TermNode(mun);
                GraphNode gn2=new GraphNode("CompRem"+compensationcount,tn2);
-               UpdateNode un=new UpdateNode();
+               UpdateNode un=new UpdateNode(r);
                un.addBindings(bindings);
                if (j<r.numQuantifiers()) {
                    /* Remove quantifier */
@@ -294,7 +314,9 @@ public class Termination {
                        continue;
                    }
                }
-
+               if (!un.checkupdates()) /* Make sure we have a good update */
+                   continue;
+               
                mun.addUpdate(un);
 
                GraphNode.Edge e=new GraphNode.Edge("abstract"+compensationcount,gn2);
@@ -351,7 +373,7 @@ public class Termination {
            boolean goodflag=true;
            for(int i=0;i<possiblerules.size();i++) {
                Rule r=(Rule)possiblerules.get(i);
-               UpdateNode un=new UpdateNode();
+               UpdateNode un=new UpdateNode(r);
                /* Construct bindings */
                Vector bindings=new Vector();
                constructbindings(bindings, r,true);
@@ -392,6 +414,10 @@ public class Termination {
                        goodflag=false;break;
                    }
                }
+               if (!un.checkupdates()) {
+                   goodflag=false;
+                   break;
+               }
                mun.addUpdate(un);
            }
            if (goodflag) {
@@ -546,7 +572,7 @@ public class Termination {
                DNFRule dnfrule=r.getDNFGuardExpr();
                for(int j=0;j<dnfrule.size();j++) {
                    Inclusion inc=r.getInclusion();
-                   UpdateNode un=new UpdateNode();
+                   UpdateNode un=new UpdateNode(r);
                    un.addBindings(bindings);
                    /* Now build update for tuple/set inclusion condition */
                    if(inc instanceof SetInclusion) {
@@ -593,7 +619,8 @@ public class Termination {
                    GraphNode gn2=new GraphNode("UpdateAdd"+addtocount,tn);
 
                    if (processquantifers(gn2,un, r)&&debugdd()&&
-                       processconjunction(un,ruleconj)) {
+                       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);