2 import IR.Tree.Modifiers;
3 import IR.Tree.ExpressionNode;
4 import java.util.Vector;
9 * represents a symbol in the language (var name, function name, etc).
12 public class MethodDescriptor extends Descriptor {
14 protected Modifiers modifier;
15 protected TypeDescriptor returntype;
16 protected String identifier;
17 protected Vector params;
18 protected SymbolTable paramtable;
19 protected ClassDescriptor cd;
20 protected VarDescriptor thisvd;
23 public MethodDescriptor(Modifiers m, TypeDescriptor rt, String identifier) {
27 this.identifier=identifier;
28 this.safename = "___" + name + "___";
29 this.uniqueid=count++;
31 paramtable=new SymbolTable();
35 public MethodDescriptor(Modifiers m, String identifier) {
39 this.identifier=identifier;
40 this.safename = "___" + name + "___";
41 this.uniqueid=count++;
43 paramtable=new SymbolTable();
47 public void setThis(VarDescriptor vd) {
52 public VarDescriptor getThis() {
56 public String getSafeMethodDescriptor() {
58 for(int i=0;i<numParameters();i++) {
59 st+=getParamType(i).getSafeDescriptor();
60 if ((i+1)<numParameters())
66 public boolean isStatic() {
67 return modifier.isStatic();
70 public boolean isConstructor() {
71 return (returntype==null);
74 public TypeDescriptor getReturnType() {
78 public void setClassDesc(ClassDescriptor cd) {
82 public ClassDescriptor getClassDesc() {
86 public SymbolTable getParameterTable() {
90 public void addParameter(TypeDescriptor type, String paramname) {
91 if (paramname.equals("this"))
92 throw new Error("Can't have parameter named this");
93 VarDescriptor vd=new VarDescriptor(type, paramname);
96 if (paramtable.getFromSameScope(paramname)!=null) {
97 throw new Error("Parameter "+paramname+" already defined");
102 public int numParameters() {
103 return params.size();
106 public VarDescriptor getParameter(int i) {
107 return (VarDescriptor)params.get(i);
110 public String getParamName(int i) {
111 return ((VarDescriptor)params.get(i)).getName();
114 public TypeDescriptor getParamType(int i) {
115 return ((VarDescriptor)params.get(i)).getType();
118 public String toString() {
120 if (returntype!=null)
121 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
123 st=modifier.toString()+" "+identifier+"(";
124 for(int i=0;i<params.size();i++) {
125 st+=getParamType(i)+" "+getParamName(i);
126 if ((i+1)!=params.size())