switch to spaces only..
[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(ClassDescriptor cd) {
17     this.flags=new Hashtable<FlagState, Integer>();
18     this.sourceset=new HashSet<TaskDescriptor>();
19     this.cd=cd;
20   }
21
22   public void addSource(TaskDescriptor td) {
23     sourceset.add(td);
24   }
25
26   public TagState(TagDescriptor tag) {
27     this.tag=tag;
28     this.flags=new Hashtable<FlagState, Integer>();
29     this.sourceset=new HashSet<TaskDescriptor>();
30   }
31
32   public TagDescriptor getTag() {
33     return tag;
34   }
35
36   public ClassDescriptor getClassDesc() {
37     return cd;
38   }
39
40   public TagState[] clearFS(FlagState fs) {
41     int num=0;
42     if (flags.containsKey(fs))
43       num=flags.get(fs).intValue();
44     if (num>0)
45       num--;
46
47     TagState ts=new TagState(tag);
48     ts.flags.putAll(flags);
49     ts.flags.put(fs, new Integer(num));
50
51     if ((num+1)==KLIMIT)
52       return new TagState[] {ts, this};
53     else
54       return new TagState[] {ts};
55   }
56
57   public TagState[] addnewFS(FlagState fs) {
58     int num=0;
59     if (flags.containsKey(fs))
60       num=flags.get(fs).intValue();
61     if (num<KLIMIT)
62       num++;
63
64     TagState ts=new TagState(tag);
65     ts.flags.putAll(flags);
66     ts.flags.put(fs, new Integer(num));
67     return new TagState[] {ts};
68   }
69
70   public TagState[] addFS(FlagState fs) {
71     int num=0;
72     if (flags.containsKey(fs))
73       num=flags.get(fs).intValue();
74     if (num<KLIMIT)
75       num++;
76
77     TagState ts=new TagState(tag);
78     ts.flags.putAll(flags);
79     ts.flags.put(fs, new Integer(num));
80     if (num==1)
81       return new TagState[] {ts};
82     else
83       return new TagState[] {this, ts};
84   }
85
86   public boolean containsFS(FlagState fs) {
87     return flags.containsKey(fs);
88   }
89
90   public Set<FlagState> getFS() {
91     return flags.keySet();
92   }
93
94   public int hashCode() {
95     int hashcode=flags.hashCode();
96     if (tag!=null)
97       hashcode^=tag.hashCode();
98     return hashcode;
99   }
100
101   public boolean equals(Object o) {
102     if (o instanceof TagState) {
103       TagState t=(TagState)o;
104       if ((tag==null&&t.tag==null)||
105           (tag!=null&&t.tag!=null&&tag.equals(t.tag))) {
106         return flags.equals(t.flags);
107       }
108     }
109     return false;
110   }
111 }