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;
9 ClassDescriptor superdesc;
10 boolean hasFlags=false;
20 int numstaticblocks = 0;
21 int numstaticfields = 0;
23 public ClassDescriptor(String classname) {
27 public ClassDescriptor(String packagename, String classname) {
30 flags=new SymbolTable();
31 fields=new SymbolTable();
32 fieldvec=new Vector();
33 methods=new SymbolTable();
35 this.packagename=packagename;
42 public Iterator getMethods() {
43 return methods.getDescriptorsIterator();
46 public Iterator getFields() {
47 return fields.getDescriptorsIterator();
50 public Iterator getFlags() {
51 return flags.getDescriptorsIterator();
54 public SymbolTable getFieldTable() {
58 public Vector getFieldVec() {
62 public SymbolTable getFlagTable() {
66 public SymbolTable getMethodTable() {
70 public String getSafeDescriptor() {
71 return "L"+safename.replace('.','/');
74 public String printTree(State state) {
76 String st=modifiers.toString()+"class "+getSymbol();
78 st+="extends "+superclass.toString();
80 indent=TreeNode.INDENT;
81 boolean printcr=false;
83 for(Iterator it=getFlags(); it.hasNext();) {
84 FlagDescriptor fd=(FlagDescriptor)it.next();
85 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
93 for(Iterator it=getFields(); it.hasNext();) {
94 FieldDescriptor fd=(FieldDescriptor)it.next();
95 st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
101 for(Iterator it=getMethods(); it.hasNext();) {
102 MethodDescriptor md=(MethodDescriptor)it.next();
103 st+=TreeNode.printSpace(indent)+md.toString()+" ";
104 BlockNode bn=state.getMethodBody(md);
105 st+=bn.printNode(indent)+"\n\n";
111 public void addFlag(FlagDescriptor fd) {
112 if (flags.contains(fd.getSymbol()))
113 throw new Error(fd.getSymbol()+" already defined");
118 public boolean hasFlags() {
119 return hasFlags||getSuperDesc()!=null&&getSuperDesc().hasFlags();
122 public void addField(FieldDescriptor fd) {
123 if (fields.contains(fd.getSymbol()))
124 throw new Error(fd.getSymbol()+" already defined");
128 this.incStaticFields();
132 public void addMethod(MethodDescriptor md) {
136 public void setModifiers(Modifiers modifiers) {
137 this.modifiers=modifiers;
140 public void setSuper(String superclass) {
141 this.superclass=superclass;
144 public ClassDescriptor getSuperDesc() {
148 public void setSuper(ClassDescriptor scd) {
152 public String getSuper() {
156 public void incStaticBlocks() {
157 this.numstaticblocks++;
160 public int getNumStaticBlocks() {
161 return this.numstaticblocks;
164 public void incStaticFields() {
165 this.numstaticfields++;
168 public int getNumStaticFields() {
169 return this.numstaticfields;