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 boolean isStatic() {
57 return modifier.isStatic();
60 public boolean isConstructor() {
61 return (returntype==null);
64 public TypeDescriptor getReturnType() {
68 public void setClassDesc(ClassDescriptor cd) {
72 public ClassDescriptor getClassDesc() {
76 public SymbolTable getParameterTable() {
80 public void addParameter(TypeDescriptor type, String paramname) {
81 if (paramname.equals("this"))
82 throw new Error("Can't have parameter named this");
83 VarDescriptor vd=new VarDescriptor(type, paramname);
86 if (paramtable.getFromSameScope(paramname)!=null) {
87 throw new Error("Parameter "+paramname+" already defined");
92 public int numParameters() {
96 public VarDescriptor getParameter(int i) {
97 return (VarDescriptor)params.get(i);
100 public String getParamName(int i) {
101 return ((VarDescriptor)params.get(i)).getName();
104 public TypeDescriptor getParamType(int i) {
105 return ((VarDescriptor)params.get(i)).getType();
108 public String toString() {
110 if (returntype!=null)
111 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
113 st=modifier.toString()+" "+identifier+"(";
114 for(int i=0;i<params.size();i++) {
115 st+=getParamType(i)+" "+getParamName(i);
116 if ((i+1)!=params.size())