changes on ssjava.
[IRC.git] / Robust / src / Analysis / SSJava / DeltaLocation.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.List;
5 import java.util.Set;
6 import java.util.Vector;
7
8 import IR.ClassDescriptor;
9 import IR.TypeDescriptor;
10
11 public class DeltaLocation extends Location {
12
13   private Vector<Location> operandVec;
14   private TypeDescriptor refOperand = null;
15
16   public DeltaLocation(ClassDescriptor cd) {
17     super(cd);
18     operandVec = new Vector<Location>();
19   }
20
21   public DeltaLocation(ClassDescriptor cd, Set<Location> set) {
22     super(cd);
23     operandVec = new Vector<Location>();
24     operandVec.addAll(set);
25   }
26
27   public DeltaLocation(ClassDescriptor cd, TypeDescriptor refOperand) {
28     super(cd);
29     this.refOperand = refOperand;
30     operandVec = new Vector<Location>();
31   }
32
33   public TypeDescriptor getRefLocationId() {
34     return this.refOperand;
35   }
36
37   public void addDeltaOperand(Location op) {
38     operandVec.add(op);
39   }
40
41   public List<Location> getDeltaOperandLocationVec() {
42     return operandVec;
43   }
44
45   public Set<Location> getBaseLocationSet() {
46
47     if (operandVec.size() == 1 && (operandVec.get(0) instanceof DeltaLocation)) {
48       // nested delta definition
49       DeltaLocation deltaLoc = (DeltaLocation) operandVec.get(0);
50       return deltaLoc.getBaseLocationSet();
51     } else {
52       Set<Location> set = new HashSet<Location>();
53       set.addAll(operandVec);
54       return set;
55     }
56
57   }
58
59   public boolean equals(Object o) {
60
61     if (!(o instanceof DeltaLocation)) {
62       return false;
63     }
64
65     DeltaLocation deltaLoc = (DeltaLocation) o;
66
67     if (deltaLoc.getDeltaOperandLocationVec().equals(getDeltaOperandLocationVec())) {
68       return true;
69     }
70     return false;
71   }
72
73   public int hashCode() {
74     int hash = cd.hashCode();
75     if (loc != null) {
76       hash += operandVec.hashCode();
77     }
78     return hash;
79   }
80
81   public String toString() {
82     String rtr = "delta(";
83
84     if (operandVec.size() != 0) {
85       int tupleSize = operandVec.size();
86       for (int i = 0; i < tupleSize; i++) {
87         Location locElement = operandVec.elementAt(i);
88         if (i != 0) {
89           rtr += ",";
90         }
91         rtr += locElement;
92       }
93     } else {
94       rtr += "LOC_REF";
95     }
96
97     rtr += ")";
98
99     return rtr;
100   }
101
102 }