Added:
[repair.git] / Repair / RepairCompiler / MCC / IR / LogicStatement.java
index 9c3a1ed335e7a46e4796fb4449bfcd77b6da8877..ab23ec37006a7bfe5219f0e6be00fba8d5bb0774 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; }
@@ -74,7 +98,7 @@ public class LogicStatement {
             left.generate(writer, leftd);
 
             writer.outputline("// 3-valued NOT");
-            writer.outputline("if (!maybe)");
+           //            writer.outputline("if (!maybe)"); //this isn't really necessary
             writer.startblock();
             writer.outputline(dest.getSafeSymbol() + " =  !" + leftd.getSafeSymbol() + ";");
             writer.endblock();
@@ -85,7 +109,7 @@ public class LogicStatement {
             String lm = (VarDescriptor.makeNew("leftmaybe")).getSafeSymbol();
             left.generate(writer, leftd);
             writer.outputline("int " + lm + " = maybe;");
-            
+            writer.outputline("maybe=0;");
             VarDescriptor rightd = VarDescriptor.makeNew("rightboolean");
             String rm = (VarDescriptor.makeNew("rightmaybe")).getSafeSymbol();
             assert right != null;
@@ -120,7 +144,7 @@ public class LogicStatement {
                  * 1110  1 X
                  * 1111  1 X
                  *
-                 * M = (L*RM) + (R*LM) + (LM*RM)                 
+                 * M = (L*RM) + (R*LM) + (LM*RM)
                  * O = (L*R)
                  */