private NodePair flattenTaskExitNode(TaskExitNode ten) {
FlatFlagActionNode ffan=new FlatFlagActionNode(true);
updateFlagActionNode(ffan, ten.getFlagEffects());
- return new NodePair(ffan, ffan);
+ NodePair fcn=flattenConstraintCheck(ten.getChecks());
+ ffan.addNext(fcn.getBegin());
+ return new NodePair(ffan, fcn.getEnd());
+ }
+
+ private NodePair flattenConstraintCheck(Vector ccs) {
+ FlatNode begin=new FlatNop();
+ FlatNode last=begin;
+ for(int i=0;i<ccs.size();i++) {
+ ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
+ FlatCheckNode fcn=new FlatCheckNode(getTempforVar(cc.getVar()), cc.getSpec());
+ last.addNext(fcn);
+ last=fcn;
+ }
+ return new NodePair(begin,last);
}
private NodePair flattenSubBlockNode(SubBlockNode sbn) {
public static final int FlatSetElementNode=11;
public static final int FlatElementNode=12;
public static final int FlatFlagActionNode=13;
+ public static final int FlatCheckNode=14;
}
--- /dev/null
+package IR.Flat;
+
+public class FlatCheckNode extends FlatNode {
+ TempDescriptor td;
+ String spec;
+
+ public FlatCheckNode(TempDescriptor td, String spec) {
+ this.td=td;
+ this.spec=spec;
+ }
+
+ public int kind() {
+ return FKind.FlatCheckNode;
+ }
+
+ public TempDescriptor [] readsTemps() {
+ return new TempDescriptor[] {td};
+ }
+}
public class ConstraintCheck {
String varname;
String specname;
+ VarDescriptor vd;
public ConstraintCheck(String varname, String specname) {
this.varname=varname;
this.specname=specname;
}
+ public void setVar(VarDescriptor vd) {
+ this.vd=vd;
+ }
+
+ public VarDescriptor getVar() {
+ return vd;
+ }
+
public String getVarName() {
return varname;
}
checkTypeDescriptor(fd.getType());
}
+ public void checkConstraintCheck(TaskDescriptor td, Vector ccs) {
+ if (ccs==null)
+ return; /* No constraint checks to check */
+ for(int i=0;i<ccs.size();i++) {
+ ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
+ String varname=cc.getVarName();
+
+ //Make sure the variable is declared as a parameter to the task
+ VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
+ if (vd==null)
+ throw new Error("Parameter "+varname+" in Constraint Check not declared");
+ cc.setVar(vd);
+
+ //Make sure it correspods to a class
+ TypeDescriptor type_d=vd.getType();
+ if (!type_d.isClass())
+ throw new Error("Cannot have non-object argument for flag_effect");
+
+ }
+ }
+
public void checkFlagEffects(TaskDescriptor td, Vector vfe) {
if (vfe==null)
return; /* No flag effects to check */
if (md instanceof MethodDescriptor)
throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects());
+ checkConstraintCheck((TaskDescriptor) md, ten.getChecks());
}
void checkIfStatementNode(Descriptor md, SymbolTable nametable, IfStatementNode isn) {