Working on allocating with reachability, mostly the "aging" of tokens.
[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     // 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 TokenTuple makeCanonical() {
39         return (TokenTuple) Canonical.makeCanonical( this );
40     }
41
42     public Integer getToken() { return token; }
43     public int     getArity() { return arity; }
44
45     public TokenTuple increaseArity() {
46         if( isNewSummary ) {
47             return (TokenTuple) Canonical.makeCanonical( 
48               new TokenTuple( token, isNewSummary, ARITY_MANY )
49                                                          );
50         }
51         return this;
52     }
53
54     public TokenTuple changeTokenTo( Integer tokenToChangeTo ) {
55         assert isNewSummary == false;
56
57         return new TokenTuple( tokenToChangeTo,
58                                isNewSummary,
59                                arity ).makeCanonical();
60     }
61
62     public boolean equals( Object o ) {
63         if( !(o instanceof TokenTuple) ) {
64             return false;
65         }
66
67         TokenTuple tt = (TokenTuple) o;
68
69         return token.equals( tt.getToken() ) &&
70                arity ==      tt.getArity();
71     }
72
73     public int hashCode() {
74         return token.intValue();
75     }
76
77     public String toString() {
78         String s = "";
79         if( isNewSummary ) {
80             s = "S";
81         }
82
83         String t = "";
84         if( arity == ARITY_MANY ) {
85             t = "*";
86         }
87
88         return new String( token+s+t );
89     }
90 }