Fixed lots of bugs with increment operations and +=/etc...
[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     public ClassDescriptor(String classname) {
7         super(classname);
8         superclass=null;
9         flags=new SymbolTable();
10         fields=new SymbolTable();
11         methods=new SymbolTable();
12         classid=UIDCount++;
13     }
14     private static int UIDCount=0; 
15     private final int classid;
16     String superclass;
17     ClassDescriptor superdesc;
18     boolean hasFlags=false;
19
20     Modifiers modifiers;
21
22     SymbolTable fields;
23     SymbolTable flags;
24     SymbolTable methods;
25
26     public int getId() {
27         return classid;
28     }
29     
30     public Iterator getMethods() {
31         return methods.getDescriptorsIterator();
32     }
33
34     public Iterator getFields() {
35         return fields.getDescriptorsIterator();
36     }
37
38     public Iterator getFlags() {
39         return flags.getDescriptorsIterator();
40     }
41     
42     public SymbolTable getFieldTable() {
43         return fields;
44     }
45
46     public SymbolTable getFlagTable() {
47         return flags;
48     }
49
50     public SymbolTable getMethodTable() {
51         return methods;
52     }
53
54     public String getSafeDescriptor() {
55         return "L"+safename.replace('.','/');
56     }
57
58     public String printTree(State state) {
59         int indent;
60         String st=modifiers.toString()+"class "+getSymbol();
61         if (superclass!=null) 
62             st+="extends "+superclass.toString();
63         st+=" {\n";
64         indent=TreeNode.INDENT;
65         boolean printcr=false;
66
67         for(Iterator it=getFlags();it.hasNext();) {
68             FlagDescriptor fd=(FlagDescriptor)it.next();
69             st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
70             printcr=true;
71         }
72         if (printcr)
73             st+="\n";
74
75         printcr=false;
76
77         for(Iterator it=getFields();it.hasNext();) {
78             FieldDescriptor fd=(FieldDescriptor)it.next();
79             st+=TreeNode.printSpace(indent)+fd.toString()+"\n";
80             printcr=true;
81         }
82         if (printcr)
83             st+="\n";
84
85         for(Iterator it=getMethods();it.hasNext();) {
86             MethodDescriptor md=(MethodDescriptor)it.next();
87             st+=TreeNode.printSpace(indent)+md.toString()+" ";
88             BlockNode bn=state.getMethodBody(md);
89             st+=bn.printNode(indent)+"\n\n";
90         }
91         st+="}\n";
92         return st;
93     }
94
95     public void addFlag(FlagDescriptor fd) {
96         if (flags.contains(fd.getSymbol()))
97             throw new Error(fd.getSymbol()+" already defined");
98         hasFlags=true;
99         flags.add(fd);
100     }
101
102     public boolean hasFlags() {
103         return hasFlags;
104     }
105
106     public void addField(FieldDescriptor fd) {
107         if (fields.contains(fd.getSymbol()))
108             throw new Error(fd.getSymbol()+" already defined");
109         fields.add(fd);
110     }
111
112     public void addMethod(MethodDescriptor md) {
113         methods.add(md);
114     }
115   
116     public void setModifiers(Modifiers modifiers) {
117         this.modifiers=modifiers;
118     }
119
120     public void setSuper(String superclass) {
121         this.superclass=superclass;
122     }
123
124     public ClassDescriptor getSuperDesc() {
125         return superdesc;
126     }
127
128     public void setSuper(ClassDescriptor scd) {
129         this.superdesc=scd;
130     }
131
132     public String getSuper() {
133         return superclass;
134     }
135 }