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>();
43 for(Taint t : taints) {
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,
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,
89 out = (TaintSet) Canonical.makeCanonical(out);
93 public TaintSet add(Taint t) {
94 return Canonical.addPTR(this, t);
95 /* TaintSet newt=new TaintSet();
96 newt.taints.addAll(taints);
98 return (TaintSet) Canonical.makeCanonical(newt);*/
101 public TaintSet merge(TaintSet ts) {
102 return Canonical.unionPTR(this, ts);
103 /* TaintSet newt=new TaintSet();
104 newt.taints.addAll(taints);
105 newt.taints.addAll(ts.taints);
106 return (TaintSet) Canonical.makeCanonical(newt);*/
109 protected TaintSet() {
110 taints = new HashSet<Taint>();
113 protected TaintSet(HashSet<Taint> taints) {
114 this.taints = taints;
117 public Set<Taint> getTaints() {
121 public Iterator iterator() {
122 return taints.iterator();
125 public boolean isEmpty() {
126 return taints.isEmpty();
129 public Taint containsIgnorePreds(Taint t) {
132 Iterator<Taint> tItr = taints.iterator();
133 while( tItr.hasNext() ) {
134 Taint tThis = tItr.next();
135 if( tThis.equalsIgnorePreds(t) ) {
143 public boolean equalsSpecific(Object o) {
148 if( !(o instanceof TaintSet) ) {
152 TaintSet ts = (TaintSet) o;
153 return taints.equals(ts.taints);
156 public int hashCodeSpecific() {
157 return taints.hashCode();
160 public String toStringEscNewline( boolean suppressPredicates ) {
161 String s = "taints[";
163 Iterator<Taint> tItr = taints.iterator();
164 while( tItr.hasNext() ) {
165 Taint t = tItr.next();
167 s += t.toString( suppressPredicates );
168 if( tItr.hasNext() ) {
176 public String toString() {
177 return taints.toString();