changes to reflect ssjava design changes and temporarily remove some of ssjava class...
[IRC.git] / Robust / src / Analysis / SSJava / CompositeLocation.java
1 package Analysis.SSJava;
2
3 import IR.TypeExtension;
4
5 public class CompositeLocation implements TypeExtension {
6
7   protected NTuple<Location> locTuple;
8
9   public CompositeLocation() {
10     locTuple = new NTuple<Location>();
11   }
12
13   public CompositeLocation(Location loc) {
14     locTuple = new NTuple<Location>();
15     locTuple.addElement(loc);
16   }
17
18   public NTuple<Location> getTuple() {
19     return locTuple;
20   }
21
22   public int getSize() {
23     return locTuple.size();
24   }
25
26   public void addLocation(Location loc) {
27     locTuple.addElement(loc);
28   }
29
30   public Location get(int idx) {
31     return locTuple.get(idx);
32   }
33   
34   public boolean isEmpty(){
35     return locTuple.size()==0;
36   }
37
38   // public void addLocationSet(Set<Location> set) {
39   //
40   // for (Iterator iterator = set.iterator(); iterator.hasNext();) {
41   // Location location = (Location) iterator.next();
42   // locTuple.addElement(location);
43   // }
44   //
45   // }
46
47   // public Location getLocation(ClassDescriptor cd) {
48   //
49   // // need to get more optimization version later
50   // Set<Location> locSet = getBaseLocationSet();
51   // for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
52   // Location location = (Location) iterator.next();
53   // if (location.getClassDescriptor().equals(cd)) {
54   // return location;
55   // }
56   // }
57   //
58   // return null;
59   //
60   // }
61
62   // public Map<ClassDescriptor, Location> getCd2Loc() {
63   //
64   // Map<ClassDescriptor, Location> cd2loc = new Hashtable<ClassDescriptor,
65   // Location>();
66   //
67   // Set<Location> baseLocSet = getBaseLocationSet();
68   // for (Iterator iterator = baseLocSet.iterator(); iterator.hasNext();) {
69   // Location location = (Location) iterator.next();
70   // cd2loc.put(location.getClassDescriptor(), location);
71   // }
72   //
73   // return cd2loc;
74   //
75   // }
76
77   public NTuple<Location> getBaseLocationTuple() {
78
79     return locTuple;
80
81     // NTuple<Location> baseLocationTuple = new NTuple<Location>();
82     // int tupleSize = locTuple.size();
83     // for (int i = 0; i < tupleSize; i++) {
84     // Location locElement = locTuple.at(i);
85     //
86     // if (locElement instanceof DeltaLocation) {
87     // // baseLocationSet.addAll(((DeltaLocation)
88     // // locElement).getDeltaOperandLocationVec());
89     // baseLocationTuple.addAll(((DeltaLocation)
90     // locElement).getBaseLocationTuple());
91     // } else {
92     // baseLocationTuple.addElement(locElement);
93     // }
94     // }
95     // return baseLocationTuple;
96
97   }
98
99   // public List<Location> getBaseLocationList() {
100   //
101   // Set<Location> baseLocationSet = new HashSet<Location>();
102   // int tupleSize = locTuple.size();
103   // for (int i = 0; i < tupleSize; i++) {
104   // Location locElement = locTuple.at(i);
105   //
106   // if (locElement instanceof DeltaLocation) {
107   // // baseLocationSet.addAll(((DeltaLocation)
108   // // locElement).getDeltaOperandLocationVec());
109   // baseLocationSet.addAll(((DeltaLocation) locElement).getBaseLocationSet());
110   // } else {
111   // baseLocationSet.add(locElement);
112   // }
113   // }
114   // return baseLocationSet;
115   // }
116
117   // public int getNumofDelta() {
118   //
119   // int result = 0;
120   //
121   // if (locTuple.size() == 1) {
122   // Location locElement = locTuple.at(0);
123   // if (locElement instanceof DeltaLocation) {
124   // result++;
125   // result += getNumofDelta((DeltaLocation) locElement);
126   // }
127   // }
128   // return result;
129   // }
130
131   // public int getNumofDelta(DeltaLocation delta) {
132   // int result = 0;
133   //
134   // if (delta.getDeltaOperandLocationVec().size() == 1) {
135   // Location locElement = delta.getDeltaOperandLocationVec().at(0);
136   // if (locElement instanceof DeltaLocation) {
137   // result++;
138   // result += getNumofDelta((DeltaLocation) locElement);
139   // }
140   // }
141   //
142   // return result;
143   // }
144
145   // public void removieLocation(ClassDescriptor cd) {
146   // for (int i = 0; i < locTuple.size(); i++) {
147   // if (locTuple.at(i).getClassDescriptor().equals(cd)) {
148   // locTuple.removeAt(i);
149   // return;
150   // }
151   // }
152   // }
153
154   public String toString() {
155
156     // for better representation
157     // if compositeLoc has only one single location,
158     // just print out single location
159     // if(locTuple.size()==1){
160     // Location locElement=locTuple.at(0);
161     // if(locElement instanceof Location){
162     // return locElement.toString();
163     // }
164     // }
165
166     String rtr = "CompLoc[";
167
168     int tupleSize = locTuple.size();
169     for (int i = 0; i < tupleSize; i++) {
170       Location locElement = locTuple.get(i);
171       if (i != 0) {
172         rtr += ",";
173       }
174       rtr += locElement;
175     }
176     rtr += "]";
177
178     return rtr;
179   }
180
181   public boolean equals(Object o) {
182
183     if (!(o instanceof CompositeLocation)) {
184       return false;
185     }
186
187     CompositeLocation compLoc = (CompositeLocation) o;
188
189     if (compLoc.getTuple().equals(getTuple())) {
190       return true;
191     } else {
192       return false;
193     }
194
195   }
196
197   public int hashCode() {
198
199     return locTuple.hashCode();
200
201   }
202
203 }