changes
[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   private Edge() {
24   }
25
26   public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst) {
27     this.src=src;
28     this.fd=fd;
29     this.dst=dst;
30   }
31
32   public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst, int statuspredicate) {
33     this.src=src;
34     this.fd=fd;
35     this.dst=dst;
36     this.statuspredicate=statuspredicate;
37   }
38   
39   public Edge(TempDescriptor tmp, AllocNode dst) {
40     this.srcvar=tmp;
41     this.dst=dst;
42   }
43   
44   public int hashCode() {
45     int hashcode=dst.hashCode();
46     if (fd!=null) {
47       hashcode^=fd.hashCode();
48     }
49     if (src!=null) {
50       hashcode^=(src.hashCode()<<3);
51     } else {
52       hashcode^=(srcvar.hashCode()<<3);
53     }
54     return hashcode;
55   }
56
57   public boolean equals(Object o) {
58     if (o instanceof Edge) {
59       Edge e=(Edge) o;
60       if (srcvar!=null) {
61         return (srcvar==e.srcvar)&&(dst==e.dst);
62       } else {
63         return (src==e.src)&&(dst==e.dst)&&(fd==e.fd);
64       }
65     }
66     return false;
67   }
68
69   public Edge copy() {
70     Edge e=new Edge();
71     e.fd=fd;
72     e.src=src;
73     e.srcvar=srcvar;
74     e.dst=dst;
75     e.statuspredicate=statuspredicate;
76     return e;
77   }
78
79   public Edge merge(Edge e) {
80     if (e==null)
81       return this;
82     Edge newe=copy();
83     newe.statuspredicate=mergeStatus(statuspredicate, e.statuspredicate);
84     return newe;
85   }
86
87   public Edge rewrite(AllocNode single, AllocNode summary) {
88     Edge e=copy();
89     if (e.src==single)
90       e.src=summary;
91     if (e.dst==single)
92       e.dst=summary;
93     return e;
94   }
95
96   public boolean statusDominates(Edge other) {
97     return (statuspredicate==NEW)||
98       ((other.statuspredicate|statuspredicate)==statuspredicate);
99   }
100
101   public Edge makeStatus(AllocFactory factory) {
102     Edge e=new Edge();
103     e.fd=fd;
104     e.src=factory.getAllocNode(src, (statuspredicate|3)==0);
105     e.dst=factory.getAllocNode(dst, (statuspredicate|5)==0);
106     return e;
107   }
108
109   public boolean subsumes(Edge e) {
110     return subsumes(this.statuspredicate, e.statuspredicate);
111   }
112
113   public static boolean subsumes(int status1, int status2) {
114     return ((status1&NEW)==NEW)&&((status1|status2)==status1);
115   }
116
117   public Edge makeOld() {
118     Edge e=new Edge();
119     e.fd=fd;
120     e.src=src;
121     e.srcvar=srcvar;
122     e.dst=dst;
123     int val=1;
124     if (dst.isSummary())
125       val=val<<1;
126     if (src.isSummary())
127       val=val<<2;
128     e.statuspredicate=val;
129     return e;
130   }
131 }