special union of reachability sets works correctly now
[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
15 {
16     private Integer token;
17     private boolean isNewSummary;
18
19     // only summary tokens should have ARITY_MANY?
20     public static final int ARITY_ONE  = 1;
21     public static final int ARITY_MANY = 2;
22     private int arity;
23
24     public TokenTuple( HeapRegionNode hrn ) {
25         token        = hrn.getID();
26         isNewSummary = hrn.isNewSummary();
27         arity        = ARITY_ONE;
28     }
29
30     public TokenTuple( Integer token,
31                        boolean isNewSummary,
32                        int     arity ) {
33         this.token        = token;
34         this.isNewSummary = isNewSummary;
35         this.arity        = arity;
36     }
37
38     public Integer getToken() { return token; }
39     public int     getArity() { return arity; }
40
41     public TokenTuple increaseArity() {
42         if( isNewSummary ) {
43             return new TokenTuple( token, isNewSummary, ARITY_MANY );
44         }
45         return this;
46     }
47
48     public boolean equals( Object o ) {
49         if( !(o instanceof TokenTuple) ) {
50             return false;
51         }
52
53         TokenTuple tt = (TokenTuple) o;
54
55         return token.equals( tt.getToken() ) &&
56                arity ==      tt.getArity();
57     }
58
59     public int hashCode() {
60         return token.intValue();
61     }
62
63     public String toString() {
64         String s = "";
65         if( isNewSummary ) {
66             s = "S";
67         }
68
69         String t = "1";
70         if( arity == ARITY_MANY ) {
71             t = "M";
72         }
73
74         return new String( "<"+token+s+","+t+">" );
75     }
76 }