Add support for 'static' fields in multicore gc version w/o tasks. Now we can have...
[IRC.git] / Robust / src / IR / ClassDescriptor.java
1 package IR;
2 import java.util.*;
3 import IR.Tree.*;
4
5 public class ClassDescriptor extends Descriptor {
6   private static int UIDCount=1; // start from 1 instead of 0 for multicore gc
7   private final int classid;
8   String superclass;
9   ClassDescriptor superdesc;
10   boolean hasFlags=false;
11   String packagename;
12
13   Modifiers modifiers;
14
15   SymbolTable fields;
16   Vector fieldvec;
17   SymbolTable flags;
18   SymbolTable methods;
19   
20   int numstaticblocks=0;
21
22   public ClassDescriptor(String classname) {
23     this("", classname);
24   }
25
26   public ClassDescriptor(String packagename, String classname) {
27     super(classname);
28     superclass=null;
29     flags=new SymbolTable();
30     fields=new SymbolTable();
31     fieldvec=new Vector();
32     methods=new SymbolTable();
33     classid=UIDCount++;
34     this.packagename=packagename;
35   }
36
37   public int getId() {
38     return classid;
39   }
40
41   public Iterator getMethods() {
42     return methods.getDescriptorsIterator();
43   }
44
45   public Iterator getFields() {
46     return fields.getDescriptorsIterator();
47   }
48
49   public Iterator getFlags() {
50     return flags.getDescriptorsIterator();
51   }
52
53   public SymbolTable getFieldTable() {
54     return fields;
55   }
56
57   public Vector getFieldVec() {
58     return fieldvec;
59   }
60
61   public SymbolTable getFlagTable() {
62     return flags;
63   }
64
65   public SymbolTable getMethodTable() {
66     return methods;
67   }
68
69   public String getSafeDescriptor() {
70     return "L"+safename.replace('.','/');
71   }
72
73   public String printTree(State state) {
74     int indent;
75     String st=modifiers.toString()+"class "+getSymbol();
76     if (superclass!=null)
77       st+="extends "+superclass.toString();
78     st+=" {\n";
79     indent=TreeNode.INDENT;
80     boolean printcr=false;
81
82     for(Iterator it=getFlags(); it.hasNext();) {
83       FlagDescriptor fd=(FlagDescriptor)it.next();
84       st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
85       printcr=true;
86     }
87     if (printcr)
88       st+="\n";
89
90     printcr=false;
91
92     for(Iterator it=getFields(); it.hasNext();) {
93       FieldDescriptor fd=(FieldDescriptor)it.next();
94       st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
95       printcr=true;
96     }
97     if (printcr)
98       st+="\n";
99
100     for(Iterator it=getMethods(); it.hasNext();) {
101       MethodDescriptor md=(MethodDescriptor)it.next();
102       st+=TreeNode.printSpace(indent)+md.toString()+" ";
103       BlockNode bn=state.getMethodBody(md);
104       st+=bn.printNode(indent)+"\n\n";
105     }
106     st+="}\n";
107     return st;
108   }
109
110   public void addFlag(FlagDescriptor fd) {
111     if (flags.contains(fd.getSymbol()))
112       throw new Error(fd.getSymbol()+" already defined");
113     hasFlags=true;
114     flags.add(fd);
115   }
116
117   public boolean hasFlags() {
118     return hasFlags||getSuperDesc()!=null&&getSuperDesc().hasFlags();
119   }
120
121   public void addField(FieldDescriptor fd) {
122     if (fields.contains(fd.getSymbol()))
123       throw new Error(fd.getSymbol()+" already defined");
124     fields.add(fd);
125     fieldvec.add(fd);
126   }
127
128   public void addMethod(MethodDescriptor md) {
129     methods.add(md);
130   }
131
132   public void setModifiers(Modifiers modifiers) {
133     this.modifiers=modifiers;
134   }
135
136   public void setSuper(String superclass) {
137     this.superclass=superclass;
138   }
139
140   public ClassDescriptor getSuperDesc() {
141     return superdesc;
142   }
143
144   public void setSuper(ClassDescriptor scd) {
145     this.superdesc=scd;
146   }
147
148   public String getSuper() {
149     return superclass;
150   }
151   
152   public void incStaticBlocks() {
153     this.numstaticblocks++;
154   }
155   
156   public int getNumStaticBlocks() {
157     return this.numstaticblocks;
158   }
159 }