1 package Analysis.Disjoint;
8 ///////////////////////////////////////////
10 // This class is an immutable Canonical, so
12 // 0) construct them with a factory pattern
13 // to ensure only canonical versions escape
15 // 1) any operation that modifies a Canonical
16 // is a static method in the Canonical class
18 // 2) operations that just read this object
19 // should be defined here
21 // 3) every Canonical subclass hashCode should
22 // throw an error if the hash ever changes
24 ///////////////////////////////////////////
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
31 public class TaintSet extends Canonical {
33 protected HashSet<Taint> taints;
35 public static TaintSet factory() {
36 TaintSet out = new TaintSet();
37 out = (TaintSet) Canonical.makeCanonical( out );
41 public static TaintSet factory( Taint t ) {
43 assert t.isCanonical();
44 TaintSet out = new TaintSet();
46 out = (TaintSet) Canonical.makeCanonical( out );
50 public static TaintSet factory( TaintSet ts,
51 ExistPredSet preds ) {
53 assert ts.isCanonical();
55 TaintSet out = new TaintSet();
57 Iterator<Taint> tItr = ts.iterator();
58 while( tItr.hasNext() ) {
59 Taint t = tItr.next();
60 Taint tOut = Taint.factory( t.sese,
65 out.taints.add( tOut );
68 out = (TaintSet) Canonical.makeCanonical( out );
72 protected TaintSet() {
73 taints = new HashSet<Taint>();
76 public Iterator iterator() {
77 return taints.iterator();
80 public boolean isEmpty() {
81 return taints.isEmpty();
84 public Taint containsIgnorePreds( Taint t ) {
87 Iterator<Taint> tItr = taints.iterator();
88 while( tItr.hasNext() ) {
89 Taint tThis = tItr.next();
90 if( tThis.equalsIgnorePreds( t ) ) {
98 public boolean equalsSpecific( Object o ) {
103 if( !(o instanceof TaintSet) ) {
107 TaintSet ts = (TaintSet) o;
108 return taints.equals( ts.taints );
111 public int hashCodeSpecific() {
112 return taints.hashCode();
115 public String toString() {
116 return taints.toString();