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