7717ca67056f2f2a921b86c76a8da8e4de42195a
[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.contains(set1)&&((Set)subset.get(set1)).contains(set2);
25     }
26
27     public boolean noIntersection(SetDescriptor set1, SetDescriptor set2) {
28         return intersection.contains(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             while(!st.empty()) {
39                 SetDescriptor subsetsd=(SetDescriptor)st.pop();
40                 System.out.print(subsetsd.toString());
41
42                 st.addAll(subsetsd.getSubsets());
43                 if (!subset.contains(sd))
44                     subset.put(sd,new HashSet());
45                 ((HashSet)subset.get(sd)).addAll(subsetsd.getSubsets());
46                 for(Iterator it=subsetsd.getSubsets().iterator();it.hasNext();) {
47                     SetDescriptor sd2=(SetDescriptor)it.next();
48                     if (!superset.contains(sd2))
49                         superset.put(sd2,new HashSet());
50                     ((HashSet)superset.get(sd2)).add(sd);
51                 }
52             }
53         }
54         for(int i=0;i<descriptors.size();i++) {
55             SetDescriptor sd=(SetDescriptor)descriptors.get(i);
56             if (sd.isPartition()) {
57                 Vector subst=sd.getSubsets();
58                 for(Iterator it1=subst.iterator();it1.hasNext();) {
59                     SetDescriptor sd1=(SetDescriptor)it1.next();
60                     for(Iterator it2=subst.iterator();it2.hasNext();) {
61                         SetDescriptor sd2=(SetDescriptor)it2.next();
62                         if (sd1!=sd2) {
63                             for(Iterator it3=sd1.allSubsets().iterator();it3.hasNext();) {
64                                 SetDescriptor sd3=(SetDescriptor)it3.next();
65                                 
66                                 if (!intersection.contains(sd3))
67                                     intersection.put(sd3,new HashSet());
68                                 ((HashSet)intersection.get(sd3)).addAll(sd2.allSubsets());
69                             }
70                         }
71                     }
72                 }
73             }
74         }
75     }
76 }