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