Added fields to ReferenceEdgeProperties and combed over all classes that need proper...
[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 == null ) {
64             return false;
65         }
66
67         if( !(o instanceof TokenTuple) ) {
68             return false;
69         }
70
71         TokenTuple tt = (TokenTuple) o;
72
73         return token.equals( tt.getToken() ) &&
74                arity ==      tt.getArity();
75     }
76
77     public int hashCode() {
78         return token.intValue();
79     }
80
81     public String toString() {
82         String s = "";
83         if( isNewSummary ) {
84             s = "S";
85         }
86
87         String t = "";
88         if( arity == ARITY_MANY ) {
89             t = "*";
90         }
91
92         return new String( token+s+t );
93     }
94 }