cpaturing some makefile updates and have OoOJava print number of sites disjoint reach...
[IRC.git] / Robust / src / Analysis / Disjoint / TaintSet.java
1 package Analysis.Disjoint;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8 ///////////////////////////////////////////
9 //  IMPORTANT
10 //  This class is an immutable Canonical, so
11 //
12 //  0) construct them with a factory pattern
13 //  to ensure only canonical versions escape
14 //
15 //  1) any operation that modifies a Canonical
16 //  is a static method in the Canonical class
17 //
18 //  2) operations that just read this object
19 //  should be defined here
20 //
21 //  3) every Canonical subclass hashCode should
22 //  throw an error if the hash ever changes
23 //
24 ///////////////////////////////////////////
25
26 // a taint set is simply the union of possible
27 // taints for an abstract reference edge--in a
28 // concrete heap each reference would have
29 // exactly one taint
30
31 public class TaintSet extends Canonical {
32
33   protected HashSet<Taint> taints;
34
35   public static TaintSet factory() {
36     TaintSet out = new TaintSet();
37     out = (TaintSet) Canonical.makeCanonical( out );
38     return out;
39   }
40
41   public static TaintSet factory( Taint t ) {
42     assert t != null;
43     assert t.isCanonical();
44     TaintSet out = new TaintSet();    
45     out.taints.add( t );
46     out = (TaintSet) Canonical.makeCanonical( out );
47     return out;
48   }
49
50   public static TaintSet factory( TaintSet     ts,
51                                   ExistPredSet preds ) {
52     assert ts != null;
53     assert ts.isCanonical();
54
55     TaintSet out = new TaintSet();
56
57     Iterator<Taint> tItr = ts.iterator();
58     while( tItr.hasNext() ) {
59       Taint t    = tItr.next();
60       Taint tOut = Taint.factory( t.sese,
61                                   t.stallSite,
62                                   t.var,
63                                   t.allocSite,
64                                   preds );
65       out.taints.add( tOut );
66     }
67
68     out = (TaintSet) Canonical.makeCanonical( out );
69     return out;
70   }
71
72   protected TaintSet() {
73     taints = new HashSet<Taint>();
74   }
75
76   public Iterator iterator() {
77     return taints.iterator();
78   }
79
80   public boolean isEmpty() {
81     return taints.isEmpty();
82   }
83
84   public Taint containsIgnorePreds( Taint t ) {
85     assert t != null;
86
87     Iterator<Taint> tItr = taints.iterator();
88     while( tItr.hasNext() ) {
89       Taint tThis = tItr.next();
90       if( tThis.equalsIgnorePreds( t ) ) {
91         return tThis;
92       }
93     }
94
95     return null;
96   }
97
98   public boolean equalsSpecific( Object o ) {
99     if( o == null ) {
100       return false;
101     }
102
103     if( !(o instanceof TaintSet) ) {
104       return false;
105     }
106
107     TaintSet ts = (TaintSet) o;
108     return taints.equals( ts.taints );
109   }
110   
111   public int hashCodeSpecific() {
112     return taints.hashCode();
113   }
114   
115   public String toString() {
116     return taints.toString();
117   }
118 }