Adding changes to cvs...
[repair.git] / Repair / RepairCompiler / MCC / IR / Rule.java
index a482c08c7f99a372e6e1e0d30851399592d9eda3..806b3f8085bd5bb0876a7fcfec8604fd8598ad0c 100755 (executable)
@@ -2,17 +2,18 @@ package MCC.IR;
 
 import java.util.*;
 
-public class Rule {
+public class Rule implements Quantifiers {
     
     static int count = 1;
 
     Vector quantifiers = new Vector();
     boolean isstatic = false;
     boolean isdelay = false;
-    Expr guard = null;
+    private Expr guard = null;
     Inclusion inclusion = null;    
     SymbolTable st = new SymbolTable();
-    
+    DNFRule dnfguard=null,dnfnegguard=null;
+
     String label;
     
     int num;
@@ -22,6 +23,23 @@ public class Rule {
         label = new String("rule" + count++);
     }
     
+    public String toString() {
+       String name="";
+       for(int i=0;i<numQuantifiers();i++) {
+           name+=getQuantifier(i).toString()+",";
+       }
+       name+=guard.name()+"=>"+inclusion.toString();
+       return name;
+    }
+
+    public int numQuantifiers() {
+       return quantifiers.size();
+    }
+
+    public Quantifier getQuantifier(int i) {
+       return (Quantifier) quantifiers.get(i);
+    }
+
     public int getNum() {
         return num;
     }
@@ -48,12 +66,23 @@ public class Rule {
 
     public void setGuardExpr(Expr guard) {
         this.guard = guard;
+       dnfguard=guard.constructDNF();
+       OpExpr opexpr=new OpExpr(Opcode.NOT,guard,null);
+       dnfnegguard=opexpr.constructDNF();
     }
     
     public Expr getGuardExpr() {
         return guard;
     }
 
+    public DNFRule getDNFGuardExpr() {
+        return dnfguard;
+    }
+
+    public DNFRule getDNFNegGuardExpr() {
+        return dnfnegguard;
+    }
+
     public void setInclusion(Inclusion inclusion) {
         this.inclusion = inclusion;
     }
@@ -66,6 +95,19 @@ public class Rule {
         return st;
     }
 
+    public Set getQuantifierDescriptors() {
+
+        HashSet topdescriptors = new HashSet();
+
+        for (int i = 0; i < quantifiers.size(); i++) {            
+            Quantifier q = (Quantifier) quantifiers.elementAt(i);
+            topdescriptors.addAll(q.getRequiredDescriptors());                
+        }
+        
+        return SetDescriptor.expand(topdescriptors);
+    }
+
+
     public Set getRequiredDescriptors() {
 
         HashSet topdescriptors = new HashSet();