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;
24 public static final int MASK=15;
26 public String toString() {
29 taintlist=", "+taints.toString();
31 return "<"+srcvar+", "+dst+taintlist+">";
33 return "<"+src+", "+statuspredicate+", "+fd+", "+dst+taintlist+ ">";
35 return "<"+src+", "+statuspredicate+", [], "+dst+taintlist+">";
38 public static int mergeStatus(int stat1, int stat2) {
39 int status=stat1|stat2;
40 return ((status&NEW)==NEW)?NEW:status;
43 public boolean isNew() {
44 return (statuspredicate&NEW)==NEW;
50 public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst) {
56 public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst, int statuspredicate) {
60 this.statuspredicate=statuspredicate;
63 public Edge(TempDescriptor tmp, AllocNode dst) {
68 public AllocNode getDst() {
72 public int hashCode() {
73 int hashcode=dst.hashCode();
75 hashcode^=fd.hashCode();
78 hashcode^=(src.hashCode()<<3);
80 hashcode^=(srcvar.hashCode()<<3);
85 public Edge addTaint(Taint t) {
87 if (newe.taints==null)
88 newe.taints=TaintSet.factory(t);
90 newe.taints=newe.taints.add(t);
94 public Edge addTaintSet(TaintSet t) {
96 if (newe.taints==null)
99 newe.taints=newe.taints.merge(t);
103 public void taintModify(Set<FlatSESEEnterNode> seseSet) {
105 taints=Canonical.removeSESETaints(taints, seseSet);
109 public TaintSet getTaints() {
113 public String taintString() {
117 return taints.toString();
120 public Edge changeTaintSet(TaintSet ts) {
126 public boolean equals(Object o) {
127 if (o instanceof Edge) {
130 return (srcvar==e.srcvar)&&(dst==e.dst);
132 return (src==e.src)&&(dst==e.dst)&&(fd==e.fd);
138 public Edge changeSrcVar(TempDescriptor tmp, TaintSet taintset) {
143 e.statuspredicate=NEW;
146 else if (taintset==null)
149 e.taints=taints.merge(taintset);
153 public Edge changeSrc(FieldDescriptor newfd, AllocNode srcnode) {
158 e.statuspredicate=NEW;
170 e.statuspredicate=statuspredicate;
176 public Edge merge(Edge e) {
180 newe.statuspredicate=mergeStatus(statuspredicate, e.statuspredicate);
181 if (e.taints!=null) {
182 if (newe.taints==null)
183 newe.taints=e.taints;
185 newe.taints=newe.taints.merge(e.taints);
190 public Edge rewrite(AllocNode single, AllocNode summary) {
199 public Edge rewrite(TempDescriptor orig, TempDescriptor newtmp) {
202 throw new Error("Mismatched temps");
207 public Edge[] makeStatus(AllocFactory factory) {
208 int numedges=Integer.bitCount(statuspredicate&MASK);
210 Edge[] earray=new Edge[numedges];
213 for(int count=0; count<4; count++) {
214 if ((mask&statuspredicate)==mask) {
217 e.src=factory.getAllocNode(src, (mask&3)==0);
218 e.dst=factory.getAllocNode(dst, (mask&5)==0);
219 earray[edgeindex++]=e;
226 public boolean subsumes(Edge e) {
227 return subsumes(this.statuspredicate, e.statuspredicate)&&subsumes(this.taints, e.taints);
230 public static boolean subsumes(TaintSet ts1, TaintSet ts2) {
240 //Do a set comparison
241 //do merge + equals...faster than subset...
242 TaintSet tsmerge=ts1.merge(ts2);
243 return tsmerge.equals(ts1);
246 public static boolean subsumes(int status1, int status2) {
247 return ((status1&NEW)==NEW)||((status1|status2)==status1);
250 public Edge makeOld() {
262 e.statuspredicate=val;
266 public static MySet<Edge> makeOld(MySet<Edge> old) {
267 MySet<Edge> newedge=new MySet<Edge>();
268 for(Edge eold : old) {
269 newedge.add(eold.makeOld());
274 public static void mergeEdgesInto(MySet<Edge> orig, MySet<Edge> merge) {
275 for(Edge e : merge) {
276 if (orig.contains(e)) {
277 Edge old=orig.get(e);
284 public static MySet<Edge> taintAll(MySet<Edge> orig, Taint t) {
285 MySet<Edge> taintedEdges=new MySet<Edge>();
287 taintedEdges.add(e.addTaint(t));
292 public static MySet<Edge> taintAll(MySet<Edge> orig, TaintSet t) {
293 MySet<Edge> taintedEdges=new MySet<Edge>();
295 taintedEdges.add(e.addTaintSet(t));
300 public static void mergeEdgeInto(MySet<Edge> orig, Edge e) {
301 if (orig.contains(e)) {
302 Edge old=orig.get(e);
308 public AllocNode getSrcAlloc() {
312 public AllocNode getDstAlloc() {
316 public FieldDescriptor getFieldDesc() {