run ooojava and rcrpointer that print out effects and annotate them with the source...
[IRC.git] / Robust / src / Analysis / Disjoint / Taint.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 is applied to a reference edge, and
27 // is used to associate an effect with a heap root
28
29 public class Taint extends Canonical {
30
31   // taints can either be associated with
32   // a stall site and live variable or
33   // an sese (rblock) and an in-set var
34   // only one identifer will be non-null
35
36   // identify an sese (rblock) + inset var
37   protected FlatSESEEnterNode sese;
38
39   // identify a stall site + live variable
40   protected FlatNode stallSite;
41
42   // either type of taint includes a var
43   // and allocation site
44   protected TempDescriptor var;
45   protected Alloc allocSite;
46
47   // taints have a new, possibly null element which is
48   // the FlatNode at which the tainted reference was
49   // defined, which currently supports DFJ but doesn't
50   // hinder other analysis modes
51   protected FlatNode fnDefined;
52
53   // existance predicates must be true in a caller
54   // context for this taint's effects to transfer from this
55   // callee to that context
56   protected ExistPredSet preds;
57
58   public Taint reTaint(FlatNode fn) {
59     Taint out=new Taint(sese, stallSite, var, allocSite, fn, preds);
60     out = (Taint) Canonical.makeCanonical(out);
61     return out;
62   }
63
64   public static Taint factory(FlatSESEEnterNode sese,
65                               TempDescriptor insetVar,
66                               Alloc as,
67                               FlatNode whereDefined,
68                               ExistPredSet eps) {
69     Taint out = new Taint(sese, null, insetVar, as, whereDefined, eps);
70     out = (Taint) Canonical.makeCanonical(out);
71     return out;
72   }
73
74   public static Taint factory(FlatNode stallSite,
75                               TempDescriptor var,
76                               Alloc as,
77                               FlatNode whereDefined,
78                               ExistPredSet eps) {
79     Taint out = new Taint(null, stallSite, var, as, whereDefined, eps);
80     out = (Taint) Canonical.makeCanonical(out);
81     return out;
82   }
83
84   public static Taint factory(FlatSESEEnterNode sese,
85                               FlatNode stallSite,
86                               TempDescriptor var,
87                               Alloc as,
88                               FlatNode whereDefined,
89                               ExistPredSet eps) {
90     Taint out = new Taint(sese, stallSite, var, as, whereDefined, eps);
91     out = (Taint) Canonical.makeCanonical(out);
92     return out;
93   }
94
95   protected Taint(FlatSESEEnterNode sese,
96                   FlatNode stallSite,
97                   TempDescriptor v,
98                   Alloc as,
99                   FlatNode fnDefined,
100                   ExistPredSet eps) {
101     assert
102       (sese == null && stallSite != null) ||
103     (sese != null && stallSite == null);
104
105     assert v   != null;
106     assert as  != null;
107     assert eps != null;
108
109     this.sese      = sese;
110     this.stallSite = stallSite;
111     this.var       = v;
112     this.allocSite = as;
113     this.fnDefined = fnDefined;
114     this.preds     = eps;
115   }
116
117   protected Taint(Taint t) {
118     this( t.sese,
119           t.stallSite,
120           t.var,
121           t.allocSite,
122           t.fnDefined,
123           t.preds );
124   }
125
126   public boolean isRBlockTaint() {
127     return sese != null;
128   }
129
130   public boolean isStallSiteTaint() {
131     return stallSite != null;
132   }
133
134   public FlatSESEEnterNode getSESE() {
135     return sese;
136   }
137
138   public FlatNode getStallSite() {
139     return stallSite;
140   }
141
142   public TempDescriptor getVar() {
143     return var;
144   }
145
146   public Alloc getAllocSite() {
147     return allocSite;
148   }
149
150   public FlatNode getWhereDefined() {
151     return fnDefined;
152   }
153
154   public ExistPredSet getPreds() {
155     return preds;
156   }
157
158   public boolean equalsSpecific(Object o) {
159     if( !equalsIgnorePreds(o) ) {
160       return false;
161     }
162
163     Taint t = (Taint) o;
164     return preds.equals(t.preds);
165   }
166
167   public boolean equalsIgnorePreds(Object o) {
168     if( o == null ) {
169       return false;
170     }
171
172     if( !(o instanceof Taint) ) {
173       return false;
174     }
175
176     Taint t = (Taint) o;
177
178     boolean seseEqual;
179     if( sese == null ) {
180       seseEqual = (t.sese == null);
181     } else {
182       seseEqual = sese.equals(t.sese);
183     }
184
185     boolean stallSiteEqual;
186     if( stallSite == null ) {
187       stallSiteEqual = (t.stallSite == null);
188     } else {
189       stallSiteEqual = stallSite.equals(t.stallSite);
190     }
191
192     boolean fnDefinedEqual;
193     if( fnDefined == null ) {
194       fnDefinedEqual = (t.fnDefined == null);
195     } else {
196       fnDefinedEqual = fnDefined.equals(t.fnDefined);
197     }
198
199     return
200       seseEqual                      &&
201       stallSiteEqual                 &&
202       fnDefinedEqual                 &&
203       var.equals(t.var)     &&
204       allocSite.equals(t.allocSite);
205   }
206
207   public int hashCodeSpecific() {
208     int hash = allocSite.hashCode();
209     hash = hash ^ var.hashCode();
210
211     if( sese != null ) {
212       hash = hash ^ sese.hashCode();
213     }
214
215     if( stallSite != null ) {
216       hash = hash ^ stallSite.hashCode();
217     }
218
219     if( fnDefined != null ) {
220       hash = hash ^ fnDefined.hashCode();
221     }
222
223     return hash;
224   }
225
226   public String toString() {
227
228     String s;
229
230     if( isRBlockTaint() ) {
231       s = sese.getPrettyIdentifier();
232     } else {
233       s = stallSite.toString();
234     }
235
236     String f = "";
237     if( fnDefined != null ) {
238       f += ", "+fnDefined;
239     }
240
241     return
242       "("+s+
243       "-"+var+
244       ", "+allocSite.toStringBrief()+
245       f+
246       "):"+preds;
247   }
248 }