if (isNode(pn,"flag_effect")) {
String flagname=pn.getChild("name").getTerminal();
FlagEffects fe=new FlagEffects(flagname);
-
-
-
+ parseFlagEffect(fe, pn.getChild("flag_list"));
return fe;
} else throw new Error();
}
+ public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
+ ParseNodeVector pnv=pn.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ boolean status=true;
+ if (pn.getChild("not")!=null) {
+ status=false;
+ pn=pn.getChild("not");
+ }
+ String name=pn.getChild("name").getTerminal();
+ fes.addEffect(new FlagEffect(name,status));
+ }
+ }
+
public FlagExpressionNode parseFlagExpression(ParseNode pn) {
if (pn.getChild("or")!=null) {
ParseNodeVector pnv=pn.getChild("or").getChildren();
parseMethodDecl(cn,methodnode.getChild("method_declaration"));
return;
}
+ ParseNode flagnode=pn.getChild("flag");
+ if (flagnode!=null) {
+ parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
+ }
throw new Error();
}
}
+ private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
+ String name=pn.getChild("name").getTerminal();
+ cn.addFlag(new FlagDescriptor(name));
+ }
+
private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
ParseNode mn=pn.getChild("modifier");
Modifiers m=parseModifiersList(mn);
//Set superclass link up
if (cd.getSuper()!=null) {
cd.setSuper(typeutil.getClass(cd.getSuper()));
- // Link together Field and Method tables
+ // Link together Field, Method, and Flag tables so classes
+ // inherit these from their superclasses
cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
+ cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
}
+ /* Check to see that fields are well typed */
for(Iterator field_it=cd.getFields();field_it.hasNext();) {
FieldDescriptor fd=(FieldDescriptor)field_it.next();
System.out.println("Checking field: "+fd);
checkField(cd,fd);
}
+
for(Iterator method_it=cd.getMethods();method_it.hasNext();) {
MethodDescriptor md=(MethodDescriptor)method_it.next();
checkMethod(cd,md);
checkMethodBody(cd,md);
}
}
+
+ for(Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();task_it.hasNext();) {
+ TaskDescriptor td=(TaskDescriptor)task_it.next();
+
+
+ }
+
}
public void checkTypeDescriptor(TypeDescriptor td) {
checkTypeDescriptor(fd.getType());
}
+ public void checkTask(TaskDescriptor td) {
+ for(int i=0;i<td.numParameters();i++) {
+ /* Check that parameter is well typed */
+ TypeDescriptor param_type=td.getParamType(i);
+ checkTypeDescriptor(param_type);
+
+ /* Check the parameter's flag expression is well formed */
+ FlagExpressionNode fen=td.getFlag(td.getParameter(i));
+ if (!param_type.isClass())
+ throw new Error("Cannot have non-object argument to a task");
+ ClassDescriptor cd=param_type.getClassDesc();
+ checkFlagExpressionNode(cd, fen);
+ }
+ }
+
+ public void checkFlagExpressionNode(ClassDescriptor cd, FlagExpressionNode fen) {
+ switch(fen.kind()) {
+ case Kind.FlagOpNode:
+ {
+ FlagOpNode fon=(FlagOpNode)fen;
+ checkFlagExpressionNode(cd, fon.getLeft());
+ if (fon.getRight()!=null)
+ checkFlagExpressionNode(cd, fon.getRight());
+ break;
+ }
+ case Kind.FlagNode:
+ {
+ FlagNode fn=(FlagNode)fen;
+ String name=fn.getFlagName();
+ FlagDescriptor fd=(FlagDescriptor)cd.getFlagTable().get(name);
+ if (fd==null)
+ throw new Error("Undeclared flag: "+name);
+ fn.setFlag(fd);
+ break;
+ }
+ default:
+ throw new Error("Unrecognized FlagExpressionNode");
+ }
+ }
+
public void checkMethod(ClassDescriptor cd, MethodDescriptor md) {
/* Check return type */
if (!md.isConstructor())