6f612414bada4286e7a23e04ec364cf6a5270065
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ReachabilitySet.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8
9 public class ReachabilitySet {
10
11     public HashSet<TokenTupleSet> possibleReachabilities;
12
13     public ReachabilitySet() {
14         possibleReachabilities = new HashSet<TokenTupleSet>();
15     }
16
17     public ReachabilitySet( ReachabilitySet rs ) {
18         possibleReachabilities = (HashSet<TokenTupleSet>) rs.possibleReachabilities.clone(); // again, DEEP COPY?!
19     }
20
21     public Iterator iterator() {
22         return possibleReachabilities.iterator();
23     }
24
25     public ReachabilitySet union( ReachabilitySet rsIn ) {
26         ReachabilitySet rsOut = new ReachabilitySet( this );
27         rsOut.possibleReachabilities.addAll( rsIn.possibleReachabilities );
28         return rsOut;
29     }
30
31     public ReachabilitySet intersection( ReachabilitySet rsIn ) {
32         ReachabilitySet rsOut = new ReachabilitySet();
33
34         Iterator i = this.iterator();
35         while( i.hasNext() ) {
36             TokenTupleSet tts = (TokenTupleSet) i.next();
37             if( rsIn.possibleReachabilities.contains( tts ) ) {
38                 rsOut.possibleReachabilities.add( tts );
39             }
40         }
41
42         return rsOut;
43     }
44
45     public ChangeTupleSet unionUpArity( ReachabilitySet rsIn ) {
46         ChangeTupleSet ctsOut = new ChangeTupleSet();
47
48         Iterator itrO = this.iterator();
49         while( itrO.hasNext() ) {
50             TokenTupleSet o = (TokenTupleSet) itrO.next();
51
52             Iterator itrR = rsIn.iterator();
53             while( itrR.hasNext() ) {
54                 TokenTupleSet r = (TokenTupleSet) itrR.next();
55
56                 TokenTupleSet theUnion = new TokenTupleSet();
57
58                 Iterator itrRelement = r.iterator();
59                 while( itrRelement.hasNext() ) {
60                     TokenTuple e = (TokenTuple) itrRelement.next();
61
62                     if( o.contains( e ) ) {
63                         theUnion.union( new TokenTupleSet( e.increaseArity() ) );
64                     }
65                 }
66             }
67         }
68
69         return ctsOut;
70     }
71 }
72
73 /*
74 Set specialUnion( Set O, Set R ) {
75   Set C = {}
76
77   foreach o in O {
78     foreach r in R {
79
80       Set theUnion = {}
81
82       foreach e in r {
83         if o.contains( e ) {
84           if e.isSummaryToken() { // wait, stronger condition?
85             theUnion.add( e.copy().increaseArity() )
86           } else {
87             theUnion.add( e.copy() )
88           }
89         }
90       }
91
92       foreach e in o {
93         if !theUnion.contains( e ) {
94            theUnion.add( e.copy() )
95         }
96       }
97
98       if !theUnion.isEmpty() {
99         C.add( <o, theUnion> )
100       }
101
102     }
103   }
104
105   return C
106 }
107 */