support no flag parameters
[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         if (fen!=null)
51             flagstable.put(vd, fen);
52         if (tel!=null) {//BUGFIX - added null check here...test with any bristlecone program
53             tagstable.put(vd, tel);
54             for(int i=0;i<tel.numTags();i++) {
55                 TagVarDescriptor tvd=new TagVarDescriptor(new TagDescriptor(tel.getType(i)), tel.getName(i));
56                 if (paramtable.getFromSameScope(tel.getName(i))==null) {
57                     paramtable.add(tvd);
58                 } else if (!((paramtable.getFromSameScope(tel.getName(i)) instanceof TagVarDescriptor)&&paramtable.getFromSameScope(tel.getName(i)).equals(tvd)))
59                     throw new Error("Parameter "+paramname+" already defined");
60             }
61         }
62         
63         if (paramtable.getFromSameScope(paramname)!=null) {
64             throw new Error("Parameter "+paramname+" already defined");
65         }
66         paramtable.add(vd);
67     }
68
69     public int numParameters() {
70         return params.size();
71     }
72
73     public VarDescriptor getParameter(int i) {
74         return (VarDescriptor)params.get(i);
75     }
76
77     public String getParamName(int i) {
78         return ((VarDescriptor)params.get(i)).getName();
79     }
80
81     public TypeDescriptor getParamType(int i) {
82         return ((VarDescriptor)params.get(i)).getType();
83     }
84
85     public FlagExpressionNode getFlag(VarDescriptor vd) {
86         return (FlagExpressionNode) flagstable.get(vd);
87     }
88
89     public TagExpressionList getTag(VarDescriptor vd) {
90         //BUG did lookup in wrong table (originally flagstable)...to
91         //test, use any task program
92         return (TagExpressionList) tagstable.get(vd);
93     }
94
95     public String toString() {
96         String st=identifier+"(";
97         for(int i=0;i<params.size();i++) {
98             st+=getParamType(i)+" "+getParamName(i);
99             if ((i+1)!=params.size())
100                 st+=", ";
101         }
102         st+=")";
103         return st;
104     }
105 }