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 is applied to a reference edge, and
27 // is used to associate an effect with an
28 // sese (rblock) and in-
30 public class Taint extends Canonical {
32 // taints can either be associated with
33 // a callsite and parameter index or
34 // an sese (rblock) and an in-set var
35 // only one set of identifying objects
38 // identify a parameter index
39 protected FlatCall callSite;
40 protected Integer paramIndex;
42 // identify an sese (rblock) + inset var
43 protected FlatSESEEnterNode sese;
44 protected TempDescriptor insetVar;
46 // either type of taint also includes
48 protected AllocSite allocSite;
50 // existance predicates must be true in a caller
51 // context for this taint's effects to transfer from this
52 // callee to that context
53 protected ExistPredSet preds;
56 public static Taint factory( FlatCall fc,
61 Taint out = new Taint( fc, pi, s, iv, as );
62 out.preds = ExistPredSet.factory();
63 out = (Taint) Canonical.makeCanonical( out );
67 public static Taint factory( FlatCall fc,
73 Taint out = new Taint( fc, pi, s, iv, as );
75 out = (Taint) Canonical.makeCanonical( out );
79 protected Taint( FlatCall fc,
85 // either fc and pi are non-null, OR s and iv are non-null
87 (fc != null && pi != null && s == null && iv == null) ||
88 (fc == null && pi == null && s != null && iv != null);
99 public boolean isParamTaint() {
100 return callSite != null;
103 public boolean isSESETaint() {
107 public FlatCall getCallSite() {
111 public Integer getParamIndex() {
115 public FlatSESEEnterNode getSESE() {
119 public TempDescriptor getInSetVar() {
123 public AllocSite getAllocSite() {
127 public ExistPredSet getPreds() {
131 public boolean equalsSpecific( Object o ) {
132 if( !equalsIgnorePreds( o ) ) {
137 return preds.equals( t.preds );
140 public boolean equalsIgnorePreds( Object o ) {
145 if( !(o instanceof Taint) ) {
151 boolean fcMatches = true;
152 if( callSite == null ) {
153 fcMatches = t.callSite == null;
155 fcMatches = callSite.equals( t.callSite );
158 boolean piMatches = true;
159 if( paramIndex == null ) {
160 piMatches = t.paramIndex == null;
162 piMatches = paramIndex.equals( t.paramIndex );
165 boolean sMatches = true;
167 sMatches = t.sese == null;
169 sMatches = sese.equals( t.sese );
172 boolean ivMatches = true;
173 if( insetVar == null ) {
174 ivMatches = t.insetVar == null;
176 ivMatches = insetVar.equals( t.insetVar );
179 return allocSite.equals( t.allocSite ) &&
180 piMatches && sMatches && ivMatches;
183 public int hashCodeSpecific() {
184 int hash = allocSite.hashCode();
186 if( callSite != null ) {
187 hash = hash ^ callSite.hashCode();
190 if( paramIndex != null ) {
191 hash = hash ^ paramIndex.hashCode();
195 hash = hash ^ sese.hashCode();
198 if( insetVar != null ) {
199 hash = hash ^ insetVar.hashCode();
205 public String toString() {
208 if( isParamTaint() ) {
209 s += "cs"+callSite.nodeid+"-"+paramIndex;
211 s += sese.toPrettyString()+"-"+insetVar;
214 return s+", "+allocSite.toStringBrief()+"):"+preds;