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;
15 public class TaskDescriptor extends Descriptor {
17 protected Hashtable flagstable;
18 protected Hashtable tagstable;
20 protected String identifier;
21 protected Vector params;
22 protected Vector optionals;
23 protected SymbolTable paramtable;
25 public TaskDescriptor(String identifier) {
27 this.identifier=identifier;
28 this.uniqueid=count++;
29 flagstable=new Hashtable();
30 tagstable=new Hashtable(); //BUGFIX - added initialization here
32 optionals = new Vector();
33 paramtable=new SymbolTable();
36 public void addFlagEffects(Vector vfe) {
40 public Vector getFlagEffects() {
44 public SymbolTable getParameterTable() {
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);
53 if (isoptional) optionals.add(vd);
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) {
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");
67 if (paramtable.getFromSameScope(paramname)!=null) {
68 throw new Error("Parameter "+paramname+" already defined");
73 public boolean isOptional(VarDescriptor vd) {
74 return optionals.contains(vd);
77 public int numParameters() {
81 public VarDescriptor getParameter(int i) {
82 return (VarDescriptor)params.get(i);
85 public String getParamName(int i) {
86 return ((VarDescriptor)params.get(i)).getName();
89 public TypeDescriptor getParamType(int i) {
90 return ((VarDescriptor)params.get(i)).getType();
93 public FlagExpressionNode getFlag(VarDescriptor vd) {
94 return (FlagExpressionNode) flagstable.get(vd);
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);
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())