checking in changes
[IRC.git] / Robust / src / IR / MethodDescriptor.java
1 package IR;
2 import IR.Tree.Modifiers;
3 import IR.Tree.ExpressionNode;
4 import java.util.Vector;
5
6 /**
7  * Descriptor 
8  *
9  * represents a symbol in the language (var name, function name, etc).
10  */
11
12 public class MethodDescriptor extends Descriptor {
13
14     protected Modifiers modifier;
15     protected TypeDescriptor returntype;
16     protected String identifier;
17     protected Vector param_name;
18     protected Vector param_type;
19     protected SymbolTable paramtable;
20     
21     public MethodDescriptor(Modifiers m, TypeDescriptor rt, String identifier) {
22         super(identifier);
23         this.modifier=m;
24         this.returntype=rt;
25         this.identifier=identifier;
26         this.safename = "__" + name + "__";
27         this.uniqueid=count++;
28         param_name=new Vector();
29         param_type=new Vector();
30         paramtable=new SymbolTable();
31     }
32     public TypeDescriptor getReturnType() {
33         return returntype;
34     }
35
36     public SymbolTable getParameterTable() {
37         return paramtable;
38     }
39
40     public void addParameter(TypeDescriptor type, String paramname) {
41         param_name.add(paramname);
42         param_type.add(type);
43         if (paramtable.getFromSameScope(paramname)!=null) {
44             throw new Error("Parameter "+paramname+" already defined");
45         }
46         paramtable.add(paramname,type);
47     }
48
49     public int numParameters() {
50         return param_name.size();
51     }
52
53     public String getParamName(int i) {
54         return (String) param_name.get(i);
55     }
56
57     public TypeDescriptor getParamType(int i) {
58         return (TypeDescriptor) param_type.get(i);
59     }
60
61     public String toString() {
62         String st=modifier.toString()+returntype.toString()+" "+identifier+"(";
63         for(int i=0;i<param_type.size();i++) {
64             st+=param_type.get(i).toString()+" "+param_name.get(i).toString();
65             if ((i+1)!=param_type.size())
66                 st+=", ";
67         }
68         st+=")";
69         return st;
70     }
71 }