Checking in code to perform safety checks on repair dependency graph.
[repair.git] / Repair / RepairCompiler / MCC / IR / LogicStatement.java
index 9c3a1ed335e7a46e4796fb4449bfcd77b6da8877..58710048a6ad9ea491a92486d995782d3f00f540 100755 (executable)
@@ -8,11 +8,20 @@ public class LogicStatement {
     public static final Operation OR = new Operation("OR");
     public static final Operation NOT = new Operation("NOT");
 
+    public String name() {
+       if (op==NOT)
+           return "!"+left.name();
+       String name=left.name();
+       name+=" "+op.toString()+" ";
+       if (right!=null)
+           name+=right.name();
+       return name;
+    }
+
     public Set getInversedRelations() {
         if (left == null) {
             throw new IRException();
         }
-
         Set set = left.getInversedRelations();
         if (right != null) {
             set.addAll(right.getInversedRelations());
@@ -20,6 +29,21 @@ public class LogicStatement {
         return set;
     }
     
+    public DNFConstraint constructDNF() {
+       if (op==AND) {
+           DNFConstraint leftd=left.constructDNF();
+           DNFConstraint rightd=right.constructDNF();
+           return leftd.and(rightd);
+       } else if (op==OR) {
+           DNFConstraint leftd=left.constructDNF();
+           DNFConstraint rightd=right.constructDNF();
+           return leftd.or(rightd);
+       } else if (op==NOT) {
+           DNFConstraint leftd=left.constructDNF();
+           return leftd.not();
+       } else throw new Error();
+    }
+
     public static class Operation {
         private final String name;
         private Operation(String opname) { name = opname; }