98a05497131af40d7898f5fd74b086067678750f
[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   Descriptor locDesc;
16
17   public Location(Descriptor d, String loc) {
18     this.d = d;
19     this.loc = loc;
20
21     if (loc.equals(SSJavaAnalysis.TOP)) {
22       type = TOP;
23     } else if (loc.equals(SSJavaAnalysis.BOTTOM)) {
24       type = BOTTOM;
25     } else {
26       type = NORMAL;
27     }
28
29   }
30
31   public Location(Descriptor d, int type) {
32     this.d = d;
33     this.type = type;
34     if (type == TOP) {
35       loc = SSJavaAnalysis.TOP;
36     } else if (type == BOTTOM) {
37       loc = SSJavaAnalysis.BOTTOM;
38     }
39   }
40
41   public void setLocIdentifier(String s) {
42     loc = s;
43   }
44
45   public void setLocDescriptor(Descriptor d) {
46     locDesc = d;
47   }
48
49   public Descriptor getLocDescriptor() {
50     return locDesc;
51   }
52
53   public void setType(int type) {
54     this.type = type;
55   }
56
57   public Descriptor getDescriptor() {
58     return d;
59   }
60
61   public String getLocIdentifier() {
62     return loc;
63   }
64
65   public int getType() {
66     return this.type;
67   }
68
69   public boolean equals(Object o) {
70     if (!(o instanceof Location)) {
71       return false;
72     }
73
74     Location loc = (Location) o;
75
76     if (loc.getDescriptor().equals(getDescriptor())) {
77       if (loc.getLocIdentifier() == null || getLocIdentifier() == null) {
78         if (loc.getType() == getType()) {
79           return true;
80         }
81       } else {
82         if (loc.getLocIdentifier().equals(getLocIdentifier())) {
83           return true;
84         }
85       }
86     }
87
88     return false;
89   }
90
91   public int hashCode() {
92
93     int hash = d.hashCode();
94     if (loc != null) {
95       hash += loc.hashCode();
96     }
97     return hash;
98
99   }
100
101   public String toString() {
102     return "Loc[" + d.getSymbol() + "." + loc + "]";
103   }
104
105   public String getSymbol() {
106     return d.getSymbol() + "." + loc;
107   }
108
109   public static Location createTopLocation(Descriptor d) {
110     Location topLoc = new Location(d, TOP);
111     return topLoc;
112   }
113
114   public static Location createBottomLocation(Descriptor d) {
115     Location bottomLoc = new Location(d, BOTTOM);
116     return bottomLoc;
117   }
118
119   public boolean isTop() {
120     return type == TOP;
121   }
122
123 }