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 boolean isStatic() {
53 return modifier.isStatic();
56 public boolean isConstructor() {
57 return (returntype==null);
60 public TypeDescriptor getReturnType() {
64 public void setClassDesc(ClassDescriptor cd) {
68 public ClassDescriptor getClassDesc() {
72 public SymbolTable getParameterTable() {
76 public void addParameter(TypeDescriptor type, String paramname) {
77 if (paramname.equals("this"))
78 throw new Error("Can't have parameter named this");
79 VarDescriptor vd=new VarDescriptor(type, paramname);
82 if (paramtable.getFromSameScope(paramname)!=null) {
83 throw new Error("Parameter "+paramname+" already defined");
88 public int numParameters() {
92 public String getParamName(int i) {
93 return ((VarDescriptor)params.get(i)).getName();
96 public TypeDescriptor getParamType(int i) {
97 return ((VarDescriptor)params.get(i)).getType();
100 public String toString() {
102 if (returntype!=null)
103 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
105 st=modifier.toString()+" "+identifier+"(";
106 for(int i=0;i<params.size();i++) {
107 st+=getParamType(i)+" "+getParamName(i);
108 if ((i+1)!=params.size())