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 boolean matches(MethodDescriptor md) {
37 if (!identifier.equals(md.identifier))
39 if (numParameters()!=md.numParameters())
41 for(int i=0;i<numParameters();i++) {
42 TypeDescriptor td1=getParameter(i).getType();
43 TypeDescriptor td2=md.getParameter(i).getType();
50 public MethodDescriptor(Modifiers m, String identifier) {
54 this.identifier=identifier;
55 this.safename = "___" + name + "___";
56 this.uniqueid=count++;
58 paramtable=new SymbolTable();
62 public void setThis(VarDescriptor vd) {
67 public VarDescriptor getThis() {
71 public String getSafeMethodDescriptor() {
73 for(int i=0;i<numParameters();i++) {
74 st+=getParamType(i).getSafeDescriptor();
75 if ((i+1)<numParameters())
81 public boolean isStatic() {
82 return modifier.isStatic();
85 public boolean isConstructor() {
86 return (returntype==null);
89 public TypeDescriptor getReturnType() {
93 public void setClassDesc(ClassDescriptor cd) {
97 public ClassDescriptor getClassDesc() {
101 public SymbolTable getParameterTable() {
105 public void addParameter(TypeDescriptor type, String paramname) {
106 if (paramname.equals("this"))
107 throw new Error("Can't have parameter named this");
108 VarDescriptor vd=new VarDescriptor(type, paramname);
111 if (paramtable.getFromSameScope(paramname)!=null) {
112 throw new Error("Parameter "+paramname+" already defined");
117 public int numParameters() {
118 return params.size();
121 public VarDescriptor getParameter(int i) {
122 return (VarDescriptor)params.get(i);
125 public String getParamName(int i) {
126 return ((VarDescriptor)params.get(i)).getName();
129 public TypeDescriptor getParamType(int i) {
130 return ((VarDescriptor)params.get(i)).getType();
133 public String toString() {
135 if (returntype!=null)
136 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
138 st=modifier.toString()+" "+identifier+"(";
139 for(int i=0;i<params.size();i++) {
140 st+=getParamType(i)+" "+getParamName(i);
141 if ((i+1)!=params.size())