changes to process/prune state machines
[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 = 4;
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 static boolean isWrite(int effect) {
29     return (effect & Effect.write)==Effect.write;
30   }
31
32   public Alloc getAffectedAllocSite() {
33     return affectedAllocSite;
34   }
35
36   public void setAffectedAllocSite(Alloc affectedAllocSite) {
37     this.affectedAllocSite = affectedAllocSite;
38   }
39
40   public int getType() {
41     return type;
42   }
43
44   public void setType(int type) {
45     this.type = type;
46   }
47
48   public FieldDescriptor getField() {
49     return field;
50   }
51
52   public void setField(FieldDescriptor field) {
53     this.field = field;
54   }
55
56   public boolean equals(Object o) {
57
58     if (o == null) {
59       return false;
60     }
61
62     if (!(o instanceof Effect)) {
63       return false;
64     }
65
66     Effect in = (Effect) o;
67     
68     if (affectedAllocSite.equals(in.getAffectedAllocSite()) 
69         && type == in.getType() 
70         && ((field!=null&&field.equals(in.getField()))||
71             (field==null&&in.getField()==null))) {
72       return true;
73     } else {
74       return false;
75     }
76   }
77
78   public int hashCode() {
79
80     int hash = affectedAllocSite.hashCode();
81
82     hash = hash + type;
83
84     if (field != null) {
85       hash = hash ^ field.hashCode();
86     }
87
88     return hash;
89
90   }
91
92   public String toString() {
93     String s = "(";
94
95     s += affectedAllocSite.toStringBrief();
96     s += ", ";
97     if (type == read) {
98       s += "read";
99     } else if (type == write) {
100       s += "write";
101     } else {
102       s += "SU";
103     }
104
105     if (field==null) {
106       s += ", []";
107     } else {
108       s += ", " + field.toStringBrief();
109     }
110     return s + ")";
111   }
112
113 }