more changes
[IRC.git] / Robust / src / Analysis / TaskStateAnalysis / TagState.java
1 package Analysis.TaskStateAnalysis;
2 import Analysis.TaskStateAnalysis.*;
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import Util.GraphNode;
7
8
9 public class TagState extends GraphNode {
10     private TagDescriptor tag;
11     private ClassDescriptor cd;
12     private Hashtable<FlagState, Integer> flags;
13     public static final int KLIMIT=2;
14     public HashSet<TaskDescriptor> sourceset;
15
16     public TagState() {
17         this(null);
18     }
19
20     public TagState(ClassDescriptor cd) {
21         this(null);
22         this.cd=cd;
23     }
24
25     public void addSource(TaskDescriptor td) {
26         sourceset.add(td);
27     }
28
29     public TagState(TagDescriptor tag) {
30         this.tag=tag;
31         this.flags=new Hashtable<FlagState, Integer>();
32         this.sourceset=new HashSet,TaskDescriptor>();
33     }
34
35     public TagDescriptor getTag() {
36         return tag;
37     }
38
39     public TagState[] clearFS(FlagState fs) {
40         int num=0;
41         if (flags.containsKey(fs))
42             num=flags.get(fs).intValue();
43         if (num>0)
44             num--;
45         
46         TagState ts=new TagState(tag);
47         ts.flags.putAll(flags);
48         ts.flags.put(fs, new Integer(num));
49
50         if ((num+1)==KLIMIT)
51             return new TagState[] {ts, this};
52         else
53             return new TagState[] {ts};
54     }
55
56     public TagState[] addnewFS(FlagState fs) {
57         int num=0;
58         if (flags.containsKey(fs))
59             num=flags.get(fs).intValue();
60         if (num<KLIMIT)
61             num++;
62
63         TagState ts=new TagState(tag);
64         ts.flags.putAll(flags);
65         ts.flags.put(fs, new Integer(num));
66         return new TagState[] {ts};
67     }
68
69     public TagState[] addFS(FlagState fs) {
70         int num=0;
71         if (flags.containsKey(fs))
72             num=flags.get(fs).intValue();
73         if (num<KLIMIT)
74             num++;
75         
76         TagState ts=new TagState(tag);
77         ts.flags.putAll(flags);
78         ts.flags.put(fs, new Integer(num));
79         if (num==1)
80             return new TagState[] {ts};
81         else
82             return new TagState[] {this, ts};
83     }
84
85     public boolean containsFS(FlagState fs) {
86         return flags.containsKey(fs);
87     }
88
89     public Set<FlagState> getFS() {
90         return flags.keySet();
91     }
92
93     public int hashCode() {
94         int hashcode=flags.hashCode();
95         if (tag!=null)
96             hashcode^=tag.hashCode();
97         return hashcode;
98     }
99   
100     public boolean equals(Object o) {
101         if (o instanceof TagState) {
102             TagState t=(TagState)o;
103             if ((tag==null&&t.tag==null)||
104                 (tag!=null&&t.tag!=null&&tag.equals(t.tag))) {
105                 return flags.equals(t.flags);
106             }
107         }
108         return false;
109     }
110 }