806b3f8085bd5bb0876a7fcfec8604fd8598ad0c
[repair.git] / Repair / RepairCompiler / MCC / IR / Rule.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class Rule implements Quantifiers {
6     
7     static int count = 1;
8
9     Vector quantifiers = new Vector();
10     boolean isstatic = false;
11     boolean isdelay = false;
12     private Expr guard = null;
13     Inclusion inclusion = null;    
14     SymbolTable st = new SymbolTable();
15     DNFRule dnfguard=null,dnfnegguard=null;
16
17     String label;
18     
19     int num;
20
21     public Rule () {
22         num = count;
23         label = new String("rule" + count++);
24     }
25     
26     public String toString() {
27         String name="";
28         for(int i=0;i<numQuantifiers();i++) {
29             name+=getQuantifier(i).toString()+",";
30         }
31         name+=guard.name()+"=>"+inclusion.toString();
32         return name;
33     }
34
35     public int numQuantifiers() {
36         return quantifiers.size();
37     }
38
39     public Quantifier getQuantifier(int i) {
40         return (Quantifier) quantifiers.get(i);
41     }
42
43     public int getNum() {
44         return num;
45     }
46
47     public String getLabel() {
48         return label;
49     }
50
51     public void setStatic(boolean val) {
52         isstatic = val;
53     }
54
55     public void setDelay(boolean val) {
56         isdelay = val;
57     }
58
59     public void addQuantifier(Quantifier q) {
60         quantifiers.addElement(q);
61     }
62
63     public ListIterator quantifiers() {
64         return quantifiers.listIterator();
65     }
66
67     public void setGuardExpr(Expr guard) {
68         this.guard = guard;
69         dnfguard=guard.constructDNF();
70         OpExpr opexpr=new OpExpr(Opcode.NOT,guard,null);
71         dnfnegguard=opexpr.constructDNF();
72     }
73     
74     public Expr getGuardExpr() {
75         return guard;
76     }
77
78     public DNFRule getDNFGuardExpr() {
79         return dnfguard;
80     }
81
82     public DNFRule getDNFNegGuardExpr() {
83         return dnfnegguard;
84     }
85
86     public void setInclusion(Inclusion inclusion) {
87         this.inclusion = inclusion;
88     }
89
90     public Inclusion getInclusion() {
91         return inclusion;
92     }
93     
94     public SymbolTable getSymbolTable() {
95         return st;
96     }
97
98     public Set getQuantifierDescriptors() {
99
100         HashSet topdescriptors = new HashSet();
101
102         for (int i = 0; i < quantifiers.size(); i++) {            
103             Quantifier q = (Quantifier) quantifiers.elementAt(i);
104             topdescriptors.addAll(q.getRequiredDescriptors());                
105         }
106         
107         return SetDescriptor.expand(topdescriptors);
108     }
109
110
111     public Set getRequiredDescriptors() {
112
113         HashSet topdescriptors = new HashSet();
114
115         for (int i = 0; i < quantifiers.size(); i++) {            
116             Quantifier q = (Quantifier) quantifiers.elementAt(i);
117             topdescriptors.addAll(q.getRequiredDescriptors());                
118         }
119
120         assert guard != null;            
121         topdescriptors.addAll(guard.getRequiredDescriptors());
122         
123         assert inclusion != null;
124         topdescriptors.addAll(inclusion.getRequiredDescriptors());
125         
126         return SetDescriptor.expand(topdescriptors);
127     }
128
129 }