Fix implementation to use little d when possible, and big D only if there's no other...
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / TokenTuple.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8
9 // a token touple is a pair that indicates a
10 // heap region node and an arity
11
12 // THIS CLASS IS IMMUTABLE!
13
14 public class TokenTuple extends Canonical {
15
16   private Integer token;
17   private boolean isNewSummary;
18
19
20   // only summary tokens should have ARITY_MANY?
21   // acutally, multiple-object regions can be arity-many
22   // so isNewSummary actually means "multi-object" in
23   // this class.  CHANGE THIS SOMETIME!
24   public static final int ARITY_ONE  = 1;
25   public static final int ARITY_MANY = 2;
26   private int arity;
27
28
29   public TokenTuple(HeapRegionNode hrn) {
30     assert hrn != null;
31
32     token        = hrn.getID();
33     isNewSummary = hrn.isNewSummary();
34     arity        = ARITY_ONE;
35   }
36
37   public TokenTuple(Integer token,
38                     boolean isNewSummary,
39                     int arity) {
40     assert token != null;
41
42     this.token        = token;
43     this.isNewSummary = isNewSummary;
44     this.arity        = arity;
45   }
46
47
48   public TokenTuple makeCanonical() {
49     return (TokenTuple) Canonical.makeCanonical(this);
50   }
51
52
53   public Integer getToken() {
54     return token;
55   }
56   public int     getArity() {
57     return arity;
58   }
59
60
61   public TokenTuple increaseArity() {
62     if( isNewSummary ) {
63       return (TokenTuple) Canonical.makeCanonical(
64                new TokenTuple(token, isNewSummary, ARITY_MANY)
65                );
66     }
67     return this;
68   }
69
70
71   public TokenTuple changeTokenTo(Integer tokenToChangeTo) {
72     assert tokenToChangeTo != null;
73
74     return new TokenTuple(tokenToChangeTo,
75                           isNewSummary,
76                           arity).makeCanonical();
77   }
78
79
80   public boolean equals(Object o) {
81     if( o == null ) {
82       return false;
83     }
84
85     if( !(o instanceof TokenTuple) ) {
86       return false;
87     }
88
89     TokenTuple tt = (TokenTuple) o;
90
91     return token.equals(tt.getToken() ) &&
92            arity ==      tt.getArity();
93   }
94
95   public int hashCode() {
96     return token.intValue()*31 + arity;
97   }
98
99
100   public String toString() {
101     String s = token.toString();
102
103     if( isNewSummary ) {
104       s += "S";
105     }
106
107     if( arity == ARITY_MANY ) {
108       s += "*";
109     }
110
111     return s;
112   }
113 }