1 package Analysis.Pointer;
4 import Analysis.Pointer.AllocFactory.AllocNode;
5 import Analysis.Disjoint.Canonical;
6 import Analysis.Disjoint.Taint;
7 import Analysis.Disjoint.TaintSet;
8 import Analysis.Pointer.MySet;
14 TempDescriptor srcvar;
19 public static final int SNGSNG=1;
20 public static final int SNGSUM=2;
21 public static final int SUMSNG=4;
22 public static final int SUMSUM=8;
23 public static final int NEW=16;
25 public String toString() {
28 taintlist=", "+taints.toString();
30 return "<"+srcvar+", "+dst+taintlist+">";
32 return "<"+src+", "+statuspredicate+", "+fd+", "+dst+taintlist+ ">";
34 return "<"+src+", "+statuspredicate+", [], "+dst+taintlist+">";
37 public static int mergeStatus(int stat1, int stat2) {
38 int status=stat1|stat2;
39 return ((status&NEW)==NEW)?NEW:status;
42 public boolean isNew() {
43 return (statuspredicate&NEW)==NEW;
49 public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst) {
55 public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst, int statuspredicate) {
59 this.statuspredicate=statuspredicate;
62 public Edge(TempDescriptor tmp, AllocNode dst) {
67 public AllocNode getDst() {
71 public int hashCode() {
72 int hashcode=dst.hashCode();
74 hashcode^=fd.hashCode();
77 hashcode^=(src.hashCode()<<3);
79 hashcode^=(srcvar.hashCode()<<3);
84 public Edge addTaint(Taint t) {
86 if (newe.taints==null)
87 newe.taints=TaintSet.factory(t);
89 newe.taints=newe.taints.add(t);
93 public Edge addTaintSet(TaintSet t) {
95 if (newe.taints==null)
98 newe.taints=newe.taints.merge(t);
102 public void taintModify(Set<FlatSESEEnterNode> seseSet) {
104 taints=Canonical.removeSESETaints(taints, seseSet);
107 public TaintSet getTaints() {
111 public String taintString() {
115 return taints.toString();
118 public Edge changeTaintSet(TaintSet ts) {
124 public boolean equals(Object o) {
125 if (o instanceof Edge) {
128 return (srcvar==e.srcvar)&&(dst==e.dst);
130 return (src==e.src)&&(dst==e.dst)&&(fd==e.fd);
136 public Edge changeSrcVar(TempDescriptor tmp, TaintSet taintset) {
141 e.statuspredicate=NEW;
144 else if (taintset==null)
147 e.taints=taints.merge(taintset);
151 public Edge changeSrc(FieldDescriptor newfd, AllocNode srcnode) {
156 e.statuspredicate=NEW;
168 e.statuspredicate=statuspredicate;
174 public Edge merge(Edge e) {
178 newe.statuspredicate=mergeStatus(statuspredicate, e.statuspredicate);
179 if (e.taints!=null) {
180 if (newe.taints==null)
181 newe.taints=e.taints;
183 newe.taints=newe.taints.merge(e.taints);
188 public Edge rewrite(AllocNode single, AllocNode summary) {
197 public Edge rewrite(TempDescriptor orig, TempDescriptor newtmp) {
200 throw new Error("Mismatched temps");
205 public Edge makeStatus(AllocFactory factory) {
208 e.src=factory.getAllocNode(src, (statuspredicate|3)==0);
209 e.dst=factory.getAllocNode(dst, (statuspredicate|5)==0);
213 public boolean subsumes(Edge e) {
214 return subsumes(this.statuspredicate, e.statuspredicate)&&subsumes(this.taints, e.taints);
217 public static boolean subsumes(TaintSet ts1, TaintSet ts2) {
227 //Do a set comparison
229 return ts1.getTaints().containsAll(ts2.getTaints());
232 public static boolean subsumes(int status1, int status2) {
233 return ((status1&NEW)==NEW)||((status1|status2)==status1);
236 public Edge makeOld() {
247 e.statuspredicate=val;
251 public static void mergeEdgesInto(MySet<Edge> orig, MySet<Edge> merge) {
253 if (orig.contains(e)) {
254 Edge old=orig.get(e);
261 public static MySet<Edge> taintAll(MySet<Edge> orig, Taint t) {
262 MySet<Edge> taintedEdges=new MySet<Edge>();
264 taintedEdges.add(e.addTaint(t));
269 public static MySet<Edge> taintAll(MySet<Edge> orig, TaintSet t) {
270 MySet<Edge> taintedEdges=new MySet<Edge>();
272 taintedEdges.add(e.addTaintSet(t));
277 public static void mergeEdgeInto(MySet<Edge> orig, Edge e) {
278 if (orig.contains(e)) {
279 Edge old=orig.get(e);