Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Analysis / Disjoint / ChangeTuple.java
1 package Analysis.Disjoint;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8 ///////////////////////////////////////////
9 //  IMPORTANT
10 //  This class is an immutable Canonical, so
11 //
12 //  0) construct them with a factory pattern
13 //  to ensure only canonical versions escape
14 //
15 //  1) any operation that modifies a Canonical
16 //  is a static method in the Canonical class
17 //
18 //  2) operations that just read this object
19 //  should be defined here
20 //
21 //  3) every Canonical subclass hashCode should
22 //  throw an error if the hash ever changes
23 //
24 ///////////////////////////////////////////
25
26 // a change tuple is a pair that indicates if the
27 // first ReachState is found in a ReachSet,
28 // then the second ReachState should be added
29
30 public class ChangeTuple extends Canonical
31 {
32   protected ReachState toMatch;
33   protected ReachState toAdd;
34
35   public static ChangeTuple factory(ReachState toMatch,
36                                     ReachState toAdd) {
37     // we don't care about the predicates hanging on
38     // change tuple states, so always set them to empty
39     // to ensure change tuple sets work out
40     ReachState toMatchNoPreds =
41       ReachState.factory(toMatch.reachTuples,
42                          ExistPredSet.factory()
43                          );
44     ReachState toAddNoPreds =
45       ReachState.factory(toAdd.reachTuples,
46                          ExistPredSet.factory()
47                          );
48     ChangeTuple out = new ChangeTuple(toMatchNoPreds,
49                                       toAddNoPreds);
50     out = (ChangeTuple) Canonical.makeCanonical(out);
51     return out;
52   }
53
54   protected ChangeTuple(ReachState toMatch,
55                         ReachState toAdd) {
56     this.toMatch = toMatch;
57     this.toAdd   = toAdd;
58   }
59
60   public ReachState getStateToMatch() {
61     return toMatch;
62   }
63   public ReachState getStateToAdd() {
64     return toAdd;
65   }
66
67
68   public boolean equalsSpecific(Object o) {
69     if( o == null ) {
70       return false;
71     }
72
73     if( !(o instanceof ChangeTuple) ) {
74       return false;
75     }
76
77     ChangeTuple ct = (ChangeTuple) o;
78     return
79       toMatch.equals(ct.toMatch) &&
80       toAdd.equals(ct.toAdd);
81   }
82
83   public int hashCodeSpecific() {
84     return
85       toMatch.hashCode() ^
86       toAdd.hashCode()*3;
87   }
88
89   public String toString() {
90     return new String("("+toMatch+" -> "+toAdd+")");
91   }
92 }