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