Fixed some errors in the Repair Generator code.
[repair.git] / Repair / RepairCompiler / MCC / IR / SetAnalysis.java
1 package MCC.IR;
2 import java.util.*;
3 import MCC.State;
4
5 public class SetAnalysis {
6     State state;
7     Hashtable intersection;
8     Hashtable subset;
9     Hashtable superset;
10
11     public SetAnalysis(State state) {
12         this.state=state;
13         intersection=new Hashtable();
14         subset=new Hashtable();
15         superset=new Hashtable();
16         doanalysis();
17     }
18
19     public Set getSuperset(SetDescriptor set1) {
20         return (Set)superset.get(set1);
21     }
22
23     public boolean isSubset(SetDescriptor set1, SetDescriptor set2) {
24         return subset.containsKey(set1)&&((Set)subset.get(set1)).contains(set2);
25     }
26
27     public boolean noIntersection(SetDescriptor set1, SetDescriptor set2) {
28         return intersection.containsKey(set1)&&((Set)intersection.get(set1)).contains(set2);
29     }
30     
31     void doanalysis() {
32         SymbolTable sets=state.stSets;
33         Vector descriptors=sets.getAllDescriptors();
34         for(int i=0;i<descriptors.size();i++) {
35             SetDescriptor sd=(SetDescriptor)descriptors.get(i);
36             Stack st=new Stack();
37             st.addAll(sd.getSubsets());
38
39             if (!subset.containsKey(sd))
40                 subset.put(sd,new HashSet());
41             ((HashSet)subset.get(sd)).addAll(sd.getSubsets());
42             for(Iterator it=sd.getSubsets().iterator();it.hasNext();) {
43                 SetDescriptor sd2=(SetDescriptor)it.next();
44                 if (!superset.containsKey(sd2))
45                     superset.put(sd2,new HashSet());
46                 ((HashSet)superset.get(sd2)).add(sd);
47             }
48
49             while(!st.empty()) {
50                 SetDescriptor subsetsd=(SetDescriptor)st.pop();
51
52                 st.addAll(subsetsd.getSubsets());
53                 if (!subset.containsKey(sd))
54                     subset.put(sd,new HashSet());
55                 ((HashSet)subset.get(sd)).addAll(subsetsd.getSubsets());
56                 for(Iterator it=subsetsd.getSubsets().iterator();it.hasNext();) {
57                     SetDescriptor sd2=(SetDescriptor)it.next();
58                     if (!superset.containsKey(sd2))
59                         superset.put(sd2,new HashSet());
60                     ((HashSet)superset.get(sd2)).add(sd);
61                 }
62             }
63         }
64         for(int i=0;i<descriptors.size();i++) {
65             SetDescriptor sd=(SetDescriptor)descriptors.get(i);
66             if (sd.isPartition()) {
67                 Vector subst=sd.getSubsets();
68                 for(Iterator it1=subst.iterator();it1.hasNext();) {
69                     SetDescriptor sd1=(SetDescriptor)it1.next();
70                     for(Iterator it2=subst.iterator();it2.hasNext();) {
71                         SetDescriptor sd2=(SetDescriptor)it2.next();
72                         if (sd1!=sd2) {
73                             for(Iterator it3=sd1.allSubsets().iterator();it3.hasNext();) {
74                                 SetDescriptor sd3=(SetDescriptor)it3.next();
75                                 
76                                 if (!intersection.containsKey(sd3))
77                                     intersection.put(sd3,new HashSet());
78                                 ((HashSet)intersection.get(sd3)).addAll(sd2.allSubsets());
79                             }
80                         }
81                     }
82                 }
83             }
84         }
85     }
86 }