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 protected MethodDescriptor(String s) {
39 public Modifiers getModifiers() {
43 public boolean matches(MethodDescriptor md) {
45 if (!identifier.equals(md.identifier))
47 if (numParameters()!=md.numParameters())
49 for(int i=0;i<numParameters();i++) {
50 TypeDescriptor td1=getParameter(i).getType();
51 TypeDescriptor td2=md.getParameter(i).getType();
58 public MethodDescriptor(Modifiers m, String identifier) {
62 this.identifier=identifier;
63 this.safename = "___" + name + "___";
64 this.uniqueid=count++;
66 paramtable=new SymbolTable();
70 public void setThis(VarDescriptor vd) {
75 public VarDescriptor getThis() {
79 public String getSafeMethodDescriptor() {
81 for(int i=0;i<numParameters();i++) {
82 st+=getParamType(i).getSafeDescriptor();
83 if ((i+1)<numParameters())
89 public boolean isStatic() {
90 return modifier.isStatic();
93 public boolean isConstructor() {
94 return (returntype==null);
97 public TypeDescriptor getReturnType() {
101 public void setClassDesc(ClassDescriptor cd) {
105 public ClassDescriptor getClassDesc() {
109 public SymbolTable getParameterTable() {
113 public void addParameter(TypeDescriptor type, String paramname) {
114 if (paramname.equals("this"))
115 throw new Error("Can't have parameter named this");
116 VarDescriptor vd=new VarDescriptor(type, paramname);
119 if (paramtable.getFromSameScope(paramname)!=null) {
120 throw new Error("Parameter "+paramname+" already defined");
125 public int numParameters() {
126 return params.size();
129 public VarDescriptor getParameter(int i) {
130 return (VarDescriptor)params.get(i);
133 public String getParamName(int i) {
134 return ((VarDescriptor)params.get(i)).getName();
137 public TypeDescriptor getParamType(int i) {
138 return ((VarDescriptor)params.get(i)).getType();
141 public String toString() {
143 if (returntype!=null)
144 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
146 st=modifier.toString()+" "+identifier+"(";
147 for(int i=0;i<params.size();i++) {
148 st+=getParamType(i)+" "+getParamName(i);
149 if ((i+1)!=params.size())