Generalize definition of SumExpr a little...Lets sum all elements of
[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     boolean nogenerate=false;
17     String label;
18     
19     int num;
20
21     public Rule () {
22         num = count;
23         label = new String("rule" + count++);
24     }
25     
26     public void setnogenerate() {
27         nogenerate=true;
28     }
29
30     public boolean getnogenerate() {
31         return nogenerate;
32     }
33     
34     public String toString() {
35         String name="";
36         for(int i=0;i<numQuantifiers();i++) {
37             name+=getQuantifier(i).toString()+",";
38         }
39         name+=guard.name()+"=>"+inclusion.toString();
40         return name;
41     }
42
43     public int numQuantifiers() {
44         return quantifiers.size();
45     }
46
47     public Quantifier getQuantifier(int i) {
48         return (Quantifier) quantifiers.get(i);
49     }
50
51     public int getNum() {
52         return num;
53     }
54
55     public String getLabel() {
56         return label;
57     }
58
59     public void setStatic(boolean val) {
60         isstatic = val;
61     }
62
63     public void setDelay(boolean val) {
64         isdelay = val;
65     }
66
67     public void addQuantifier(Quantifier q) {
68         quantifiers.addElement(q);
69     }
70
71     public ListIterator quantifiers() {
72         return quantifiers.listIterator();
73     }
74
75     public void setGuardExpr(Expr guard) {
76         this.guard = guard;
77         dnfguard=guard.constructDNF();
78         OpExpr opexpr=new OpExpr(Opcode.NOT,guard,null);
79         dnfnegguard=opexpr.constructDNF();
80     }
81     
82     public Expr getGuardExpr() {
83         return guard;
84     }
85
86     public DNFRule getDNFGuardExpr() {
87         return dnfguard;
88     }
89
90     public DNFRule getDNFNegGuardExpr() {
91         return dnfnegguard;
92     }
93
94     public void setInclusion(Inclusion inclusion) {
95         this.inclusion = inclusion;
96     }
97
98     public Inclusion getInclusion() {
99         return inclusion;
100     }
101     
102     public SymbolTable getSymbolTable() {
103         return st;
104     }
105
106     public Set getQuantifierDescriptors() {
107
108         HashSet topdescriptors = new HashSet();
109
110         for (int i = 0; i < quantifiers.size(); i++) {            
111             Quantifier q = (Quantifier) quantifiers.elementAt(i);
112             topdescriptors.addAll(q.getRequiredDescriptors());                
113         }
114         
115         return SetDescriptor.expand(topdescriptors);
116     }
117
118
119     public Set getRequiredDescriptors() {
120
121         HashSet topdescriptors = new HashSet();
122
123         for (int i = 0; i < quantifiers.size(); i++) {            
124             Quantifier q = (Quantifier) quantifiers.elementAt(i);
125             topdescriptors.addAll(q.getRequiredDescriptors());                
126         }
127
128         assert guard != null;            
129         topdescriptors.addAll(guard.getRequiredDescriptors());
130         
131         assert inclusion != null;
132         topdescriptors.addAll(inclusion.getRequiredDescriptors());
133         
134         return SetDescriptor.expand(topdescriptors);
135     }
136 }