Make the Scheduling codes can handle back edges in combined flag transition diagram...
[IRC.git] / Robust / src / Analysis / Scheduling / ClassNode.java
1 package Analysis.Scheduling;
2
3 import Analysis.TaskStateAnalysis.*;
4 import IR.*;
5 import java.util.*;
6
7 import Util.GraphNode;
8
9 /** This class holds a flag diagram for one class.
10  */
11 public class ClassNode extends GraphNode implements Cloneable{
12     
13     private int uid;
14     private static int nodeID=0;
15
16     private final ClassDescriptor cd;
17     private ScheduleNode sn;
18     private Vector<FlagState> flagStates;
19     private boolean sorted = false;
20
21     /** Class constructor
22      *  @param cd ClassDescriptor
23      *  @param fStates
24      */
25     public ClassNode(ClassDescriptor cd, Vector<FlagState> fStates) {
26         this.cd=cd;
27         this.flagStates = fStates;
28         this.sn = null;
29         this.uid=ClassNode.nodeID++;
30     }
31    
32     public int getuid() {
33         return uid;
34     }
35     
36     public ScheduleNode getScheduleNode() {
37         return this.sn;
38     }
39     
40     public void setScheduleNode(ScheduleNode sn) {
41         this.sn = sn;
42     }
43     
44     public boolean isSorted() {
45         return sorted;
46     }
47     
48     public void setSorted(boolean sorted) {
49         this.sorted = sorted;
50     }
51     
52     public Vector<FlagState> getFlagStates() {
53         return flagStates;
54     }
55     
56     public String toString() {
57         return cd.toString()+getTextLabel();
58     }
59
60     /** @return Iterator over the flags in the flagstate.
61      */
62      
63     public Iterator getFlags() {
64         return flagStates.iterator();
65     }
66
67     public int numFlags(){
68         return flagStates.size();
69     }
70     
71     /** Accessor method
72      *  @return returns the classdescriptor of the flagstate.
73      */
74          
75     public ClassDescriptor getClassDescriptor(){
76         return cd;
77     }
78     
79     /** Tests for equality of two flagstate objects.
80     */
81     
82     public boolean equals(Object o) {
83         if (o instanceof ClassNode) {
84             ClassNode fs=(ClassNode)o;
85             if ((fs.getClassDescriptor()!= cd) || 
86                 (fs.getScheduleNode() != sn) || 
87                 (fs.isSorted() != sorted)) {
88                 return false;
89             }
90             return (fs.getFlagStates().equals(flagStates));
91         }
92         return false;
93     }
94
95     public int hashCode() {
96         return cd.hashCode()^flagStates.hashCode();
97     }
98
99     public String getLabel() {
100         return "N_"+uid;
101     }
102     
103     public String getClusterLabel() {
104         return "cluster_"+uid;
105     }
106
107     public String getTextLabel() {
108         String label=null;
109         label = "Class " + this.cd.getSymbol();
110         
111         if (label==null)
112             return " ";
113         return label;
114     }
115     
116     public Object clone() {
117         ClassNode o = null;
118         try {
119             o = (ClassNode)super.clone();
120         } catch(CloneNotSupportedException e){
121             e.printStackTrace();
122         }
123         o.uid = ClassNode.nodeID++;
124         return o;
125     }
126 }