bug fixes
[IRC.git] / Robust / src / Analysis / Pointer / Edge.java
1 package Analysis.Pointer;
2 import IR.Flat.*;
3 import IR.*;
4 import Analysis.Pointer.AllocFactory.AllocNode;
5
6 public class Edge {
7   FieldDescriptor fd;
8   AllocNode src;
9   TempDescriptor srcvar;
10   AllocNode dst;
11   int statuspredicate;
12   public static final int SNGSNG=1;
13   public static final int SNGSUM=2;
14   public static final int SUMSNG=4;
15   public static final int SUMSUM=8;
16   public static final int NEW=16;
17
18   public static int mergeStatus(int stat1, int stat2) {
19     int status=stat1|stat2;
20     return ((status&NEW)==NEW)?NEW:status;
21   }
22
23   public boolean isNew() {
24     return (statuspredicate&NEW)==NEW;
25   }
26
27   private Edge() {
28   }
29
30   public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst) {
31     this.src=src;
32     this.fd=fd;
33     this.dst=dst;
34   }
35
36   public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst, int statuspredicate) {
37     this.src=src;
38     this.fd=fd;
39     this.dst=dst;
40     this.statuspredicate=statuspredicate;
41   }
42   
43   public Edge(TempDescriptor tmp, AllocNode dst) {
44     this.srcvar=tmp;
45     this.dst=dst;
46   }
47   
48   public int hashCode() {
49     int hashcode=dst.hashCode();
50     if (fd!=null) {
51       hashcode^=fd.hashCode();
52     }
53     if (src!=null) {
54       hashcode^=(src.hashCode()<<3);
55     } else {
56       hashcode^=(srcvar.hashCode()<<3);
57     }
58     return hashcode;
59   }
60
61   public boolean equals(Object o) {
62     if (o instanceof Edge) {
63       Edge e=(Edge) o;
64       if (srcvar!=null) {
65         return (srcvar==e.srcvar)&&(dst==e.dst);
66       } else {
67         return (src==e.src)&&(dst==e.dst)&&(fd==e.fd);
68       }
69     }
70     return false;
71   }
72
73   public Edge copy() {
74     Edge e=new Edge();
75     e.fd=fd;
76     e.src=src;
77     e.srcvar=srcvar;
78     e.dst=dst;
79     e.statuspredicate=statuspredicate;
80     return e;
81   }
82
83   public Edge merge(Edge e) {
84     if (e==null)
85       return this;
86     Edge newe=copy();
87     newe.statuspredicate=mergeStatus(statuspredicate, e.statuspredicate);
88     return newe;
89   }
90
91   public Edge rewrite(AllocNode single, AllocNode summary) {
92     Edge e=copy();
93     if (e.src==single)
94       e.src=summary;
95     if (e.dst==single)
96       e.dst=summary;
97     return e;
98   }
99
100   public boolean statusDominates(Edge other) {
101     return (statuspredicate==NEW)||
102       ((other.statuspredicate|statuspredicate)==statuspredicate);
103   }
104
105   public Edge makeStatus(AllocFactory factory) {
106     Edge e=new Edge();
107     e.fd=fd;
108     e.src=factory.getAllocNode(src, (statuspredicate|3)==0);
109     e.dst=factory.getAllocNode(dst, (statuspredicate|5)==0);
110     return e;
111   }
112
113   public boolean subsumes(Edge e) {
114     return subsumes(this.statuspredicate, e.statuspredicate);
115   }
116
117   public static boolean subsumes(int status1, int status2) {
118     return ((status1&NEW)==NEW)&&((status1|status2)==status1);
119   }
120
121   public Edge makeOld() {
122     Edge e=new Edge();
123     e.fd=fd;
124     e.src=src;
125     e.srcvar=srcvar;
126     e.dst=dst;
127     int val=1;
128     if (dst.isSummary())
129       val=val<<1;
130     if (src.isSummary())
131       val=val<<2;
132     e.statuspredicate=val;
133     return e;
134   }
135 }