f198a0a08ea505072c875efe888504e376ca168e
[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 boolean equals( Object o ) {
55         if( !(o instanceof TokenTuple) ) {
56             return false;
57         }
58
59         TokenTuple tt = (TokenTuple) o;
60
61         return token.equals( tt.getToken() ) &&
62                arity ==      tt.getArity();
63     }
64
65     public int hashCode() {
66         return token.intValue();
67     }
68
69     public String toString() {
70         String s = "";
71         if( isNewSummary ) {
72             s = "S";
73         }
74
75         String t = "1";
76         if( arity == ARITY_MANY ) {
77             t = "M";
78         }
79
80         return new String( "<"+token+s+","+t+">" );
81     }
82 }