boolean ok = true;
ParseNodeVector constraints = pn.getChildren();
-
+
for (int i = 0; i < constraints.size(); i++) {
ParseNode constraint = constraints.elementAt(i);
assert constraint.getLabel().equals("constraint");
/* do any post checks... (type constraints, etc?) */
+ Iterator consiterator = state.vConstraints.iterator();
+
+ while (consiterator.hasNext()) {
+ Constraint cons = (Constraint) consiterator.next();
+
+ final SymbolTable consst = cons.getSymbolTable();
+ SemanticAnalyzer sa = new SemanticAnalyzer() {
+ public IRErrorReporter getErrorReporter() { return er; }
+ public SymbolTable getSymbolTable() { return consst; }
+ };
+
+ TypeDescriptor constype = cons.getLogicStatement().typecheck(sa);
+
+ if (constype == null) {
+ ok = false;
+ } else if (constype != ReservedTypeDescriptor.INT) {
+ er.report(null, "Type of guard must be 'int' not '" + constype.getSymbol() + "'");
+ ok = false;
+ }
+ }
+
return ok;
}
}
}
}
-
+
/* get body */
LogicStatement logicexpr = parse_body(pn.getChild("body"));
assert sts.empty();
/* add to vConstraints */
- vConstraints.addElement(constraint);
+ vConstraints.addElement(constraint);
return ok;
}
SetDescriptor set = parse_set(pn.getChild("set"));
assert set != null;
sq.setSet(set);
+ vd.setSet(set);
vd.setType(set.getType());
rq.setRelation(rd);
vd1.setType(rd.getDomain().getType());
+ vd1.setSet(rd.getDomain());
vd2.setType(rd.getRange().getType());
+ vd2.setSet(rd.getRange());
return rq;
} else if (pn.getChild("for") != null) { /* for j = x to y */
ForQuantifier fq = new ForQuantifier();
return null;
}
+ vd.setSet(lookupSet("int", false));
vd.setType(ReservedTypeDescriptor.INT);
fq.setVar(vd);
}
}
}
-
- } else {
+ } else {
throw new IRException("shouldn't be any other typedescriptor classes");
}
-
}
// #TBD#: need to make sure that no cycles exist in any of the declarations or subtypes
/* do semantic check and if valid, add it to symbol table
and add it to the quantifier as well */
if (sts.peek().contains(varname)) {
- return new VarDescriptor(varname);
+ VarDescriptor vdold=(VarDescriptor)sts.peek().get(varname);
+ return vdold;
+ /* Dan was creating a new VarDescriptor...This seems
+ like the wrong thing to do. We'll just lookup the
+ other one.
+ --------------------------------------------------
+ VarDescriptor vd=new VarDescriptor(varname);
+ vd.setSet(vdold.getSet()); return vd;*/
} else {
/* Semantic Error: undefined variable */
er.report(pn, "Undefined variable '" + varname + "'");