changes: generated annotated code but it still causes type errors + re-formatting...
[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.getLocDescriptor() != null && getLocDescriptor() != null
89             && loc.getLocDescriptor().equals(getLocDescriptor())) {
90           return true;
91         } else if (loc.getLocIdentifier().equals(getLocIdentifier())) {
92           return true;
93         }
94       }
95     }
96
97     return false;
98   }
99
100   public int hashCode() {
101
102     int hash = d.hashCode();
103     if (loc != null) {
104       hash += loc.hashCode();
105     }
106     if (locDesc != null) {
107       hash += locDesc.hashCode();
108     }
109     return hash;
110
111   }
112
113   public String toString() {
114     return "Loc[" + d.getSymbol() + "." + loc + "]";
115   }
116
117   public String getSymbol() {
118     return d.getSymbol() + "." + loc;
119   }
120
121   public static Location createTopLocation(Descriptor d) {
122     Location topLoc = new Location(d, TOP);
123     return topLoc;
124   }
125
126   public static Location createBottomLocation(Descriptor d) {
127     Location bottomLoc = new Location(d, BOTTOM);
128     return bottomLoc;
129   }
130
131   public boolean isTop() {
132     return type == TOP;
133   }
134
135 }