getting parameter taints in new analysis
[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   // parameters or seses (rblocks),
33   // only one set of identifying objects
34   // will be non-null
35
36   // identify a parameter index
37   protected Integer paramIndex;
38   
39   // identify an sese (rblock) + inset var
40   protected FlatSESEEnterNode sese;
41   protected TempDescriptor    insetVar;
42
43   // either type of taint also includes
44   // an allocation site
45   protected AllocSite allocSite;
46
47
48   public static Taint factory( Integer           pi,
49                                FlatSESEEnterNode s,
50                                TempDescriptor    iv,
51                                AllocSite         as ) {
52     Taint out = new Taint( pi, s, iv, as );
53     out = (Taint) Canonical.makeCanonical( out );
54     return out;
55   }
56
57   protected Taint( Integer           pi,
58                    FlatSESEEnterNode s,
59                    TempDescriptor    iv,
60                    AllocSite         as ) {    
61     assert 
62       (pi != null && s == null && iv == null) ||
63       (pi == null && s != null && iv != null);
64
65     assert as != null;
66
67     paramIndex = pi;
68     sese       = s;
69     insetVar   = iv;
70     allocSite  = as;
71   }
72
73   public Integer getParamIndex() {
74     return paramIndex;
75   }
76
77   public FlatSESEEnterNode getSESE() {
78     return sese;
79   }
80
81   public TempDescriptor getInSetVar() {
82     return insetVar;
83   }
84
85   public AllocSite getAllocSite() {
86     return allocSite;
87   }
88
89
90   public boolean equalsSpecific( Object o ) {
91     if( o == null ) {
92       return false;
93     }
94
95     if( !(o instanceof Taint) ) {
96       return false;
97     }
98
99     Taint t = (Taint) o;
100
101     boolean piMatches = true;
102     if( paramIndex == null ) {
103       piMatches = t.paramIndex == null;
104     } else {
105       piMatches = paramIndex.equals( t.paramIndex );
106     }
107
108     boolean sMatches = true;
109     if( sese == null ) {
110       sMatches = t.sese == null;
111     } else {
112       sMatches = sese.equals( t.sese );
113     }
114
115     boolean ivMatches = true;
116     if( insetVar == null ) {
117       ivMatches = t.insetVar == null;
118     } else {
119       ivMatches = insetVar.equals( t.insetVar );
120     }
121
122     return allocSite.equals( t.allocSite ) &&
123       piMatches && sMatches && ivMatches;
124   }
125
126   public int hashCodeSpecific() {
127     int hash = allocSite.hashCode();
128
129     if( paramIndex != null ) {
130       hash = hash ^ paramIndex.hashCode();
131     }
132
133     if( sese != null ) {
134       hash = hash ^ sese.hashCode();
135     }
136
137     if( insetVar != null ) {
138       hash = hash ^ insetVar.hashCode();
139     }
140
141     return hash;
142   }
143
144   public String toString() {
145     String s = "(";
146
147     if( paramIndex != null ) {
148       s += "param"+paramIndex;
149     } else {
150       s += sese.toPrettyString()+"-"+insetVar;
151     }
152
153     return s+", "+allocSite.toStringBrief()+")";
154   }
155 }