5e59e005ba6ec650d6f462712df5ec5b3b91c592
[IRC.git] / Robust / src / Analysis / Disjoint / Effect.java
1 package Analysis.Disjoint;
2
3 import IR.FieldDescriptor;
4 import IR.Flat.TempDescriptor;
5
6 public class Effect {
7
8   // operation type
9   public static final int read = 1;
10   public static final int write = 2;
11   public static final int strongupdate = 3;
12
13   // identify an allocation site of affected object
14   protected Alloc affectedAllocSite;
15
16   // identify operation type
17   protected int type;
18
19   // identify a field
20   protected FieldDescriptor field;
21
22   public Effect(Alloc affectedAS, int type, FieldDescriptor field) {
23     this.affectedAllocSite = affectedAS;
24     this.type = type;
25     this.field = field;
26   }
27
28   public Alloc getAffectedAllocSite() {
29     return affectedAllocSite;
30   }
31
32   public void setAffectedAllocSite(Alloc affectedAllocSite) {
33     this.affectedAllocSite = affectedAllocSite;
34   }
35
36   public int getType() {
37     return type;
38   }
39
40   public void setType(int type) {
41     this.type = type;
42   }
43
44   public FieldDescriptor getField() {
45     return field;
46   }
47
48   public void setField(FieldDescriptor field) {
49     this.field = field;
50   }
51
52   public boolean equals(Object o) {
53
54     if (o == null) {
55       return false;
56     }
57
58     if (!(o instanceof Effect)) {
59       return false;
60     }
61
62     Effect in = (Effect) o;
63     
64     if (affectedAllocSite.equals(in.getAffectedAllocSite()) 
65         && type == in.getType() 
66         && ((field!=null&&field.equals(in.getField()))||
67             (field==null&&in.getField()==null))) {
68       return true;
69     } else {
70       return false;
71     }
72   }
73
74   public int hashCode() {
75
76     int hash = affectedAllocSite.hashCode();
77
78     hash = hash + type;
79
80     if (field != null) {
81       hash = hash ^ field.hashCode();
82     }
83
84     return hash;
85
86   }
87
88   public String toString() {
89     String s = "(";
90
91     s += affectedAllocSite.toStringBrief();
92     s += ", ";
93     if (type == read) {
94       s += "read";
95     } else if (type == write) {
96       s += "write";
97     } else {
98       s += "SU";
99     }
100
101     if (field==null) {
102       s += ", []";
103     } else {
104       s += ", " + field.toStringBrief();
105     }
106     return s + ")";
107   }
108
109 }