Make merging nodes an option.
[repair.git] / Repair / RepairCompiler / MCC / IR / Termination.java
index ff9a293a7874e36a63ad491afbc1ccfcb7d2205b..0a0859c18b0a787fe8f43b39f538f9fbe8dc0785 100755 (executable)
@@ -31,6 +31,12 @@ public class Termination {
     ExactSize exactsize;
     ArrayAnalysis arrayanalysis;
     Sources sources;
+    static String conjoption="style=bold";
+    static String absrepoption="shape=box,color=blue,style=bold";
+    static String updateoption="shape=box,color=red,style=bold";
+    static String scopeoption="color=brown";
+    static String conseqoption="style=bold,color=green";
+    static String compoption="shape=box,color=purple,style=bold";
 
     public Termination(State state) {
        this.state=state;
@@ -67,20 +73,27 @@ public class Termination {
        generateconjunctionnodes();
        constraintdependence=new ConstraintDependence(state,this);
 
+        debugmsg("Generating scope nodes");
        generatescopenodes();
+        debugmsg("Generating repair nodes");
        generaterepairnodes();
+        debugmsg("Generating data structure nodes");
        generatedatastructureupdatenodes();
-       generatecompensationnodes();
-
+        debugmsg("Generating compensation nodes");
+       if (!Compiler.OMITCOMP)
+           generatecompensationnodes();
+        debugmsg("Generating abstract edges");
        generateabstractedges();
+        debugmsg("Generating scope edges");
        generatescopeedges();
+        debugmsg("Generating update edges");
        generateupdateedges();
 
 
        HashSet superset=new HashSet();
        superset.addAll(conjunctions);
        HashSet closureset=new HashSet();
-
+        debugmsg("Computing closure");
        GraphNode.computeclosure(superset,closureset);
        try {
            GraphNode.DOTVisitor.visit(new FileOutputStream("graph.dot"),superset);
@@ -164,6 +177,7 @@ public class Termination {
                GraphNode gn=new GraphNode("Conj"+i+"A"+j,
                                           "Conj ("+i+","+j+") "+dnf.get(j).name()
                                           ,tn);
+               gn.setOption(conjoption);
                conjunctions.add(gn);
                if (!conjunctionmap.containsKey(c))
                    conjunctionmap.put(c,new HashSet());
@@ -184,6 +198,7 @@ public class Termination {
                    GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
                                               "Conj ("+i+","+j+") "+dconst.get(0).name()
                                               ,tn);
+                   gn.setOption(conjoption);
                    conjunctions.add(gn);
                    if (!conjunctionmap.containsKey(c))
                        conjunctionmap.put(c,new HashSet());
@@ -201,6 +216,7 @@ public class Termination {
                    GraphNode gn=new GraphNode("Conj"+i+"AQ"+j,
                                               "Conj ("+i+","+j+") "+dconst.get(0).name()
                                               ,tn);
+                   gn.setOption(conjoption);
                    conjunctions.add(gn);
                    if (!conjunctionmap.containsKey(c))
                        conjunctionmap.put(c,new HashSet());
@@ -287,11 +303,11 @@ public class Termination {
                 } else {
                     for(int i=0;i<conj.size();i++) {
                         DNFPredicate dp=conj.get(i);
-                        if (getConstraint(gn)!=null&&
-                            abstractinterferes.interferemodifies(ar,getConstraint(gn),dp,cons))
-                            continue;
 
-                        if (abstractinterferes.interfereswithpredicate(ar,dp)) {
+                        if (!abstractinterferes.interfereswithpredicate(ar,dp))
+                            continue;
+                        if (getConstraint(gn)==null||
+                            !abstractinterferes.interferemodifies(ar,getConstraint(gn),dp,cons)) {
                             GraphNode.Edge e=new GraphNode.Edge("interferes",gn2);
                             gn.addEdge(e);
                             break;
@@ -329,9 +345,13 @@ public class Termination {
            ScopeNode satisfy=new ScopeNode(r,true);
            TermNode tnsatisfy=new TermNode(satisfy);
            GraphNode gnsatisfy=new GraphNode("SatisfyRule"+i,tnsatisfy);
+           gnsatisfy.setOption(scopeoption);
+            if (Compiler.MERGENODES)
+                gnsatisfy.setMerge();
            ConsequenceNode cnsatisfy=new ConsequenceNode();
            TermNode ctnsatisfy=new TermNode(cnsatisfy);
            GraphNode cgnsatisfy=new GraphNode("ConseqSatisfyRule"+i,ctnsatisfy);
+           cgnsatisfy.setOption(conseqoption);
            consequence.put(satisfy,cgnsatisfy);
            GraphNode.Edge esat=new GraphNode.Edge("consequencesatisfy"+i,cgnsatisfy);
            gnsatisfy.addEdge(esat);
@@ -342,9 +362,13 @@ public class Termination {
            ScopeNode falsify=new ScopeNode(r,false);
            TermNode tnfalsify=new TermNode(falsify);
            GraphNode gnfalsify=new GraphNode("FalsifyRule"+i,tnfalsify);
+           gnfalsify.setOption(scopeoption);
+            if (Compiler.MERGENODES)
+                gnfalsify.setMerge();
            ConsequenceNode cnfalsify=new ConsequenceNode();
            TermNode ctnfalsify=new TermNode(cnfalsify);
            GraphNode cgnfalsify=new GraphNode("ConseqFalsifyRule"+i,ctnfalsify);
+           cgnfalsify.setOption(conseqoption);
            consequence.put(falsify,cgnfalsify);
            GraphNode.Edge efals=new GraphNode.Edge("consequencefalsify"+i,cgnfalsify);
            gnfalsify.addEdge(efals);
@@ -436,7 +460,9 @@ public class Termination {
                for(int j=0;j<array.length;j++) {
                    AbstractRepair ar=new AbstractRepair(dp,array[j],d,sources);
                    TermNode tn2=new TermNode(ar);
-                   GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
+                   //              GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),gn.getTextLabel()+" #"+i+" "+ar.type(),tn2);
+                   GraphNode gn2=new GraphNode(gn.getLabel()+"A"+i+"B"+ar.type(),dp.name()+" "+ar.type(),tn2);
+                   gn2.setOption(absrepoption);
                    GraphNode.Edge e=new GraphNode.Edge("abstract",gn2);
                    gn.addEdge(e);
                    if (!predtoabstractmap.containsKey(dp))
@@ -457,6 +483,7 @@ public class Termination {
            AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTOSET, sd,sources);
            TermNode tn=new TermNode(ar);
            GraphNode gn=new GraphNode("AbstractAddSetRule"+i,tn);
+           gn.setOption(absrepoption);
            if (!predtoabstractmap.containsKey(tp))
                predtoabstractmap.put(tp,new HashSet());
            ((Set)predtoabstractmap.get(tp)).add(gn);
@@ -468,6 +495,7 @@ public class Termination {
            AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMSET, sd,sources);
            TermNode tn2=new TermNode(ar2);
            GraphNode gn2=new GraphNode("AbstractRemSetRule"+i,tn2);
+           gn2.setOption(absrepoption);
            if (!predtoabstractmap.containsKey(tp2))
                predtoabstractmap.put(tp2,new HashSet());
            ((Set)predtoabstractmap.get(tp2)).add(gn2);
@@ -488,6 +516,7 @@ public class Termination {
            AbstractRepair ar=new AbstractRepair(tp, AbstractRepair.ADDTORELATION, rd,sources);
            TermNode tn=new TermNode(ar);
            GraphNode gn=new GraphNode("AbstractAddRelRule"+i,tn);
+           gn.setOption(absrepoption);
            if (!predtoabstractmap.containsKey(tp))
                predtoabstractmap.put(tp,new HashSet());
            ((Set)predtoabstractmap.get(tp)).add(gn);
@@ -499,6 +528,7 @@ public class Termination {
            AbstractRepair ar2=new AbstractRepair(tp2, AbstractRepair.REMOVEFROMRELATION, rd,sources);
            TermNode tn2=new TermNode(ar2);
            GraphNode gn2=new GraphNode("AbstractRemRelRule"+i,tn2);
+           gn2.setOption(absrepoption);
            if (!predtoabstractmap.containsKey(tp2))
                predtoabstractmap.put(tp2,new HashSet());
            ((Set)predtoabstractmap.get(tp2)).add(gn2);
@@ -521,6 +551,7 @@ public class Termination {
                MultUpdateNode mun=new MultUpdateNode(sn);
                TermNode tn2=new TermNode(mun);
                GraphNode gn2=new GraphNode("CompRem"+compensationcount,tn2);
+               gn2.setOption(compoption);
                UpdateNode un=new UpdateNode(r);
 
                if (j<r.numQuantifiers()) {
@@ -626,6 +657,7 @@ public class Termination {
            MultUpdateNode mun=new MultUpdateNode(ar,MultUpdateNode.REMOVE);
            TermNode tn=new TermNode(mun);
            GraphNode gn2=new GraphNode("UpdateRem"+removefromcount,tn);
+           gn2.setOption(updateoption);
 
            boolean goodflag=true;
            for(int i=0;i<possiblerules.size();i++) {
@@ -741,6 +773,7 @@ public class Termination {
            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++) {
@@ -969,6 +1002,7 @@ public class Termination {
                    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)&&
@@ -1056,7 +1090,7 @@ public class Termination {
                    if ((e instanceof VarExpr)&&
                        (((VarExpr)e).getVar()==vd)) {
                        /* Can solve for v */
-                       if (!si.getSet().getType().isSubtypeOf(set.getType()))
+                       if (set==null||!si.getSet().getType().isSubtypeOf(set.getType()))
                            return false;
                        Binding binding=new Binding(vd,0);
                        bindings.add(binding);