271b447f9e769f2ed79dd1c2e7013ae43ac40dcd
[IRC.git] / Robust / src / Analysis / SSJava / Location.java
1 package Analysis.SSJava;
2
3 import IR.Descriptor;
4 import IR.TypeExtension;
5
6 public class Location implements TypeExtension {
7
8   public static final int TOP = 1;
9   public static final int NORMAL = 2;
10   public static final int BOTTOM = 3;
11
12   int type;
13   Descriptor d;
14   String loc;
15
16   public Location(Descriptor d, String loc) {
17     this.d = d;
18     this.loc = loc;
19     this.type = NORMAL;
20   }
21
22   public Location(Descriptor d, int type) {
23     this.d = d;
24     this.type = type;
25     if (type == TOP) {
26       loc = SSJavaLattice.TOP;
27     } else if (type == BOTTOM) {
28       loc = SSJavaLattice.BOTTOM;
29     }
30   }
31
32   public void setType(int type) {
33     this.type = type;
34   }
35
36   public Descriptor getDescriptor() {
37     return d;
38   }
39
40   public String getLocIdentifier() {
41     return loc;
42   }
43
44   public int getType() {
45     return this.type;
46   }
47
48   public boolean equals(Object o) {
49     if (!(o instanceof Location)) {
50       return false;
51     }
52
53     Location loc = (Location) o;
54
55     if (loc.getDescriptor().equals(getDescriptor())) {
56       if (loc.getLocIdentifier() == null || getLocIdentifier() == null) {
57         if (loc.getType() == getType()) {
58           return true;
59         }
60       } else {
61         if (loc.getLocIdentifier().equals(getLocIdentifier())) {
62           return true;
63         }
64       }
65     }
66
67     return false;
68   }
69
70   public int hashCode() {
71
72     int hash = d.hashCode();
73     if (loc != null) {
74       hash += loc.hashCode();
75     }
76     return hash;
77
78   }
79
80   public String toString() {
81     return "Loc[" + d.getSymbol() + "." + loc + "]";
82   }
83
84   public String getSymbol() {
85     return d.getSymbol() + "." + loc;
86   }
87
88   public static Location createTopLocation(Descriptor d) {
89     Location topLoc = new Location(d, TOP);
90     return topLoc;
91   }
92
93   public static Location createBottomLocation(Descriptor d) {
94     Location bottomLoc = new Location(d, BOTTOM);
95     return bottomLoc;
96   }
97
98   public boolean isTop() {
99     return type == TOP;
100   }
101
102 }