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 Modifiers getModifiers() {
39 public boolean matches(MethodDescriptor md) {
41 if (!identifier.equals(md.identifier))
43 if (numParameters()!=md.numParameters())
45 for(int i=0;i<numParameters();i++) {
46 TypeDescriptor td1=getParameter(i).getType();
47 TypeDescriptor td2=md.getParameter(i).getType();
54 public MethodDescriptor(Modifiers m, String identifier) {
58 this.identifier=identifier;
59 this.safename = "___" + name + "___";
60 this.uniqueid=count++;
62 paramtable=new SymbolTable();
66 public void setThis(VarDescriptor vd) {
71 public VarDescriptor getThis() {
75 public String getSafeMethodDescriptor() {
77 for(int i=0;i<numParameters();i++) {
78 st+=getParamType(i).getSafeDescriptor();
79 if ((i+1)<numParameters())
85 public boolean isStatic() {
86 return modifier.isStatic();
89 public boolean isConstructor() {
90 return (returntype==null);
93 public TypeDescriptor getReturnType() {
97 public void setClassDesc(ClassDescriptor cd) {
101 public ClassDescriptor getClassDesc() {
105 public SymbolTable getParameterTable() {
109 public void addParameter(TypeDescriptor type, String paramname) {
110 if (paramname.equals("this"))
111 throw new Error("Can't have parameter named this");
112 VarDescriptor vd=new VarDescriptor(type, paramname);
115 if (paramtable.getFromSameScope(paramname)!=null) {
116 throw new Error("Parameter "+paramname+" already defined");
121 public int numParameters() {
122 return params.size();
125 public VarDescriptor getParameter(int i) {
126 return (VarDescriptor)params.get(i);
129 public String getParamName(int i) {
130 return ((VarDescriptor)params.get(i)).getName();
133 public TypeDescriptor getParamType(int i) {
134 return ((VarDescriptor)params.get(i)).getType();
137 public String toString() {
139 if (returntype!=null)
140 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
142 st=modifier.toString()+" "+identifier+"(";
143 for(int i=0;i<params.size();i++) {
144 st+=getParamType(i)+" "+getParamName(i);
145 if ((i+1)!=params.size())