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