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();
36 public Modifiers getModifiers() {
40 public boolean matches(MethodDescriptor md) {
42 if (!identifier.equals(md.identifier))
44 if (numParameters()!=md.numParameters())
46 for(int i=0;i<numParameters();i++) {
47 TypeDescriptor td1=getParameter(i).getType();
48 TypeDescriptor td2=md.getParameter(i).getType();
55 public MethodDescriptor(Modifiers m, String identifier) {
59 this.identifier=identifier;
60 this.safename = "___" + name + "___";
61 this.uniqueid=count++;
63 paramtable=new SymbolTable();
67 public void setThis(VarDescriptor vd) {
72 public VarDescriptor getThis() {
76 public String getSafeMethodDescriptor() {
78 for(int i=0;i<numParameters();i++) {
79 st+=getParamType(i).getSafeDescriptor();
80 if ((i+1)<numParameters())
86 public boolean isStatic() {
87 return modifier.isStatic();
90 public boolean isConstructor() {
91 return (returntype==null);
94 public TypeDescriptor getReturnType() {
98 public void setClassDesc(ClassDescriptor cd) {
102 public ClassDescriptor getClassDesc() {
106 public SymbolTable getParameterTable() {
110 public void addParameter(TypeDescriptor type, String paramname) {
111 if (paramname.equals("this"))
112 throw new Error("Can't have parameter named this");
113 VarDescriptor vd=new VarDescriptor(type, paramname);
116 if (paramtable.getFromSameScope(paramname)!=null) {
117 throw new Error("Parameter "+paramname+" already defined");
122 public int numParameters() {
123 return params.size();
126 public VarDescriptor getParameter(int i) {
127 return (VarDescriptor)params.get(i);
130 public String getParamName(int i) {
131 return ((VarDescriptor)params.get(i)).getName();
134 public TypeDescriptor getParamType(int i) {
135 return ((VarDescriptor)params.get(i)).getType();
138 public String toString() {
140 if (returntype!=null)
141 st=modifier.toString()+returntype.toString()+" "+identifier+"(";
143 st=modifier.toString()+" "+identifier+"(";
144 for(int i=0;i<params.size();i++) {
145 st+=getParamType(i)+" "+getParamName(i);
146 if ((i+1)!=params.size())