1 package Analysis.OwnershipAnalysis;
9 // a token touple is a pair that indicates a
10 // heap region node and an arity
12 // THIS CLASS IS IMMUTABLE!
14 public class TokenTuple extends Canonical {
16 private Integer token;
17 private boolean isMultiObject;
19 public static final int ARITY_ZEROORMORE = 0;
20 public static final int ARITY_ONE = 1;
21 public static final int ARITY_ONEORMORE = 2;
25 public TokenTuple(HeapRegionNode hrn) {
29 isMultiObject = !hrn.isSingleObject();
34 public TokenTuple(Integer token,
35 boolean isMultiObject,
40 this.isMultiObject = isMultiObject;
45 private void fixStuff() {
46 //This is an evil hack...we should fix this stuff elsewhere...
50 if (arity==ARITY_ONEORMORE)
51 arity=ARITY_ZEROORMORE;
56 public TokenTuple makeCanonical() {
57 return (TokenTuple) Canonical.makeCanonical(this);
61 public Integer getToken() {
65 public boolean isMultiObject() {
69 public int getArity() {
74 public TokenTuple unionArity(TokenTuple tt) {
76 assert token == tt.token;
77 assert isMultiObject == tt.isMultiObject;
80 // for multiple objects only zero-or-mores combined are still zero-or-more
81 // when two tokens are present (absence of a token is arity=zero and is
82 // handled outside of this method)
83 if( arity == ARITY_ZEROORMORE && tt.arity == ARITY_ZEROORMORE ) {
84 return new TokenTuple(token, true, ARITY_ZEROORMORE).makeCanonical();
86 return new TokenTuple(token, true, ARITY_ONEORMORE).makeCanonical();
90 // a single object region's token can only have ZEROORMORE or ONE
91 if( arity == ARITY_ZEROORMORE && tt.arity == ARITY_ZEROORMORE ) {
92 return new TokenTuple(token, false, ARITY_ZEROORMORE).makeCanonical();
94 return new TokenTuple(token, false, ARITY_ONE).makeCanonical();
100 public TokenTuple changeTokenTo(Integer tokenToChangeTo) {
101 assert tokenToChangeTo != null;
103 return new TokenTuple(tokenToChangeTo,
105 arity).makeCanonical();
109 public boolean equals(Object o) {
114 if( !(o instanceof TokenTuple) ) {
118 TokenTuple tt = (TokenTuple) o;
120 return token.equals(tt.getToken() ) &&
121 arity == tt.getArity();
124 public int hashCode() {
125 return (token.intValue() << 2) ^ arity;
129 public String toString() {
130 String s = token.toString();
132 if( isMultiObject ) {
136 if( arity == ARITY_ZEROORMORE ) {
138 } else if( arity == ARITY_ONEORMORE ) {