2478d217ce9c9175fa1ed04f0731d7ee159746c6
[IRC.git] / Robust / src / IR / TaskDescriptor.java
1 package IR;
2 import IR.Tree.FlagExpressionNode;
3 import IR.Tree.TagExpressionList;
4 import IR.Tree.FlagEffects;
5 import java.util.Vector;
6 import java.util.Hashtable;
7 import IR.Tree.Modifiers;
8
9 /**
10  * Descriptor 
11  *
12  */
13
14 public class TaskDescriptor extends Descriptor {
15
16     protected Hashtable flagstable;
17     protected Hashtable tagstable;
18     protected Vector vfe;
19     protected String identifier;
20     protected Vector params;
21     protected SymbolTable paramtable;
22
23     public TaskDescriptor(String identifier) {
24         super(identifier);
25         this.identifier=identifier;
26         this.uniqueid=count++;
27         flagstable=new Hashtable();
28         tagstable=new Hashtable(); //BUGFIX - added initialization here
29         params=new Vector();
30         paramtable=new SymbolTable();
31     }
32
33     public void addFlagEffects(Vector vfe) {
34         this.vfe=vfe;
35     }
36
37     public Vector getFlagEffects() {
38         return vfe;
39     }
40
41     public SymbolTable getParameterTable() {
42         return paramtable;
43     }
44
45     public void addParameter(TypeDescriptor type, String paramname, FlagExpressionNode fen, TagExpressionList tel) {
46         if (paramname.equals("this"))
47             throw new Error("Can't have parameter named this");
48         VarDescriptor vd=new VarDescriptor(type, paramname);
49         params.add(vd);
50         flagstable.put(vd, fen);
51         if (tel!=null) {//BUGFIX - added null check here...test with any bristlecone program
52             tagstable.put(vd, tel);
53             for(int i=0;i<tel.numTags();i++) {
54                 TagVarDescriptor tvd=new TagVarDescriptor(new TagDescriptor(tel.getType(i)), tel.getName(i));
55                 if (paramtable.getFromSameScope(tel.getName(i))==null) {
56                     paramtable.add(tvd);
57                 } else if (!(((paramtable.getFromSameScope(tel.getName(i)) instanceof TagVarDescriptor)&&paramtable.getFromSameScope(tel.getName(i))).equals(tvd))) 
58                     throw new Error("Parameter "+paramname+" already defined");
59             }
60         }
61         
62         if (paramtable.getFromSameScope(paramname)!=null) {
63             throw new Error("Parameter "+paramname+" already defined");
64         }
65         paramtable.add(vd);
66     }
67
68     public int numParameters() {
69         return params.size();
70     }
71
72     public VarDescriptor getParameter(int i) {
73         return (VarDescriptor)params.get(i);
74     }
75
76     public String getParamName(int i) {
77         return ((VarDescriptor)params.get(i)).getName();
78     }
79
80     public TypeDescriptor getParamType(int i) {
81         return ((VarDescriptor)params.get(i)).getType();
82     }
83
84     public FlagExpressionNode getFlag(VarDescriptor vd) {
85         return (FlagExpressionNode) flagstable.get(vd);
86     }
87
88     public TagExpressionList getTag(VarDescriptor vd) {
89         return (TagExpressionList) flagstable.get(vd);
90     }
91
92     public String toString() {
93         String st=identifier+"(";
94         for(int i=0;i<params.size();i++) {
95             st+=getParamType(i)+" "+getParamName(i);
96             if ((i+1)!=params.size())
97                 st+=", ";
98         }
99         st+=")";
100         return st;
101     }
102 }