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(HashSet<Taint> taints) {
36 TaintSet out = new TaintSet(taints);
37 out = (TaintSet) Canonical.makeCanonical( out );
41 public TaintSet reTaint(FlatNode fn) {
42 HashSet<Taint> taintset=new HashSet<Taint>();
44 if (t.getWhereDefined()!=fn) {
50 TaintSet out=new TaintSet(taintset);
51 out = (TaintSet) Canonical.makeCanonical( out );
55 public static TaintSet factory() {
56 TaintSet out = new TaintSet();
57 out = (TaintSet) Canonical.makeCanonical( out );
61 public static TaintSet factory( Taint t ) {
63 assert t.isCanonical();
64 TaintSet out = new TaintSet();
66 out = (TaintSet) Canonical.makeCanonical( out );
70 public static TaintSet factory( TaintSet ts,
71 ExistPredSet preds ) {
73 assert ts.isCanonical();
75 TaintSet out = new TaintSet();
77 Iterator<Taint> tItr = ts.iterator();
78 while( tItr.hasNext() ) {
79 Taint t = tItr.next();
80 Taint tOut = Taint.factory( t.sese,
86 out.taints.add( tOut );
89 out = (TaintSet) Canonical.makeCanonical( out );
93 public TaintSet add(Taint t) {
94 TaintSet newt=new TaintSet();
95 newt.taints.addAll(taints);
97 return (TaintSet) Canonical.makeCanonical(newt);
100 public TaintSet merge(TaintSet ts) {
101 TaintSet newt=new TaintSet();
102 newt.taints.addAll(taints);
103 newt.taints.addAll(ts.taints);
104 return (TaintSet) Canonical.makeCanonical(newt);
107 protected TaintSet() {
108 taints = new HashSet<Taint>();
111 protected TaintSet(HashSet<Taint> taints) {
112 this.taints = taints;
115 public Set<Taint> getTaints() {
119 public Iterator iterator() {
120 return taints.iterator();
123 public boolean isEmpty() {
124 return taints.isEmpty();
127 public Taint containsIgnorePreds( Taint t ) {
130 Iterator<Taint> tItr = taints.iterator();
131 while( tItr.hasNext() ) {
132 Taint tThis = tItr.next();
133 if( tThis.equalsIgnorePreds( t ) ) {
141 public boolean equalsSpecific( Object o ) {
146 if( !(o instanceof TaintSet) ) {
150 TaintSet ts = (TaintSet) o;
151 return taints.equals( ts.taints );
154 public int hashCodeSpecific() {
155 return taints.hashCode();
158 public String toStringEscNewline() {
159 String s = "taints[";
161 Iterator<Taint> tItr = taints.iterator();
162 while( tItr.hasNext() ) {
163 Taint t = tItr.next();
166 if( tItr.hasNext() ) {
174 public String toString() {
175 return taints.toString();