7be110b36f79832bebad74224bdc51288f211ccf
[repair.git] / Repair / RepairCompiler / MCC / IR / ExactSize.java
1 package MCC.IR;
2 import java.util.*;
3 import MCC.State;
4
5
6 class ExactSize {
7     State state;
8     private Hashtable sizemap;
9     private Hashtable constraintmap;
10
11     public ExactSize(State state) {
12         this.state=state;
13         this.sizemap=new Hashtable();
14         this.constraintmap=new Hashtable();
15         computesizes();
16     }
17     
18     public int getsize(SetDescriptor sd) {
19         if (sizemap.contains(sd))
20             return ((Integer)sizemap.get(sd)).intValue();
21         else
22             return -1;
23     }
24     public Constraint getConstraint(SetDescriptor sd) {
25         return (Constraint)constraintmap.get(sd);
26     }
27
28     private void computesizes() {
29         for(Iterator it=state.stSets.descriptors();it.hasNext();) {
30             SetDescriptor sd=(SetDescriptor)it.next();
31             for(int i=0;i<state.vConstraints.size();i++) {
32                 Constraint c=(Constraint)state.vConstraints.get(i);
33                 DNFConstraint dconst=c.dnfconstraint;
34                 int oldsize=-1;
35                 boolean matches=true;
36                 for(int j=0;j<dconst.size();j++) {
37                     Conjunction conj=dconst.get(j);
38                     boolean goodmatch=false;
39                     for(int k=0;k<conj.size();k++) {
40                         DNFPredicate dpred=conj.get(k);
41                         if (!dpred.isNegated()) {
42                             Predicate p=dpred.getPredicate();
43                             if (p instanceof ExprPredicate) {
44                                 ExprPredicate ep=(ExprPredicate)p;
45                                 if (ep.getType()==ExprPredicate.SIZE&&
46                                     ep.getOp()==Opcode.EQ&&
47                                     ep.getDescriptor()==sd&&
48                                     ep.isRightInt()) {
49                                     if (k==0) {
50                                         oldsize=ep.rightSize();
51                                     } else {
52                                         if (oldsize==ep.rightSize()) {
53                                             goodmatch=true;
54                                             break;
55                                         }
56                                     }
57                                 }
58                             }
59                         }
60                     }
61                     if (!goodmatch) {
62                         matches=false;
63                         break; //this constraint won't work
64                     }
65                 }
66                 if (matches) {
67                     sizemap.put(sd,new Integer(oldsize));
68                     constraintmap.put(sd,c);
69                 }
70             }
71         }
72     }
73 }