} else {
rule.addQuantifier(quantifier);
}
- }
+ }
}
/* get guard expr */
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) {
+ System.out.println("Failed attempting to type constraint");
+ ok = false;
+ } else if (constype != ReservedTypeDescriptor.INT) {
+ er.report(null, "Type of guard must be 'int' not '" + constype.getSymbol() + "'");
+ ok = false;
+ }
+ }
+
return ok;
}
assert qn.getLabel().equals("quantifier");
Quantifier quantifier = parse_quantifier(qn);
if (quantifier == null) {
+ System.out.println("Failed parsing quantifier");
ok = false;
} else {
constraint.addQuantifier(quantifier);
}
}
}
-
+
/* get body */
LogicStatement logicexpr = parse_body(pn.getChild("body"));
if (logicexpr == null) {
+ System.out.println("Failed parsing logical expression");
ok = false;
} else {
constraint.setLogicStatement(logicexpr);
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();
/* grab var */
VarDescriptor vd = reserveName(pn.getChild("var"));
-
+
if (vd == null) {
return null;
}
+ vd.setSet(lookupSet("int", false));
vd.setType(ReservedTypeDescriptor.INT);
fq.setVar(vd);
Expr lower = parse_expr(pn.getChild("lower").getChild("expr"));
Expr upper = parse_expr(pn.getChild("upper").getChild("expr"));
+
if ((lower == null) || (upper == null)) {
return null;
}
-
+ vd.setBounds(lower,upper);
fq.setBounds(lower, upper);
return fq;
String rangesetname = pn.getChild("range").getChild("type").getTerminal();
assert rangesetname != null;
- /* get domain multiplicity */
- String domainmult = pn.getChild("domain").getChild("mult").getTerminal();
- assert domainmult != null;
+ /* get domain multiplicity */
+ String domainmult;
+ if (pn.getChild("domain").getChild("domainmult") != null)
+ domainmult = pn.getChild("domain").getChild("domainmult").getChild("mult").getTerminal();
+ //assert domainmult != null;
/* get range multiplicity */
- String rangemult = pn.getChild("range").getChild("mult").getTerminal();
- assert rangemult != null;
+ String rangemult;
+ if (pn.getChild("range").getChild("domainrange") != null)
+ rangemult = pn.getChild("range").getChild("domainrange").getChild("mult").getTerminal();
+ //assert rangemult != null;
/* NOTE: it is assumed that the sets have been parsed already so that the
set namespace is fully populated. any missing setdescriptors for the set
if (newtype == null) {
// type never defined
// #TBD#: replace new ParseNode with original parsenode
- er.report(null, "Undefined type '" + fieldtype.getSymbol() + "'");
- ok = false;
+
+ if (!field.getPtr()) {
+ /* Pointer types don't have to be defined */
+ er.report(null, "Undefined type '" + fieldtype.getSymbol() + "'");
+ ok = false;
+ }
} else {
assert newtype != null;
field.setType(newtype);
}
- }
+ }
}
Iterator labels = type.getLabels();
}
}
}
-
- } 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
/* lookup the type to get the type descriptor */
type.setSuperType(lookupType(subtype, CREATE_MISSING));
+ } else if (pn.getChild("subclass") != null) {
+ // has a subtype, lets try to resolve it
+ String subclass = pn.getChild("subclass").getTerminal();
+
+ if (subclass.equals(typename)) {
+ // Semantic Error: cyclic inheritance
+ er.report(pn, "Cyclic inheritance prohibited");
+ ok = false;
+ }
+
+ /* lookup the type to get the type descriptor */
+ type.setSuperType(lookupType(subclass, CREATE_MISSING));
+ type.setSubClass(true);
}
// set the current type so that the recursive parses on the labels
RelationDescriptor relation = lookupRelation(pn.getChild("dotinv").getChild("relation").getTerminal());
relation.addUsage(RelationDescriptor.INVIMAGE);
return new ImageSetExpr(ImageSetExpr.INVERSE, vd, relation);
+ } else if (pn.getChild("dotset") != null) {
+ ImageSetExpr ise = (ImageSetExpr) parse_setexpr(pn.getChild("dotset").getChild("setexpr"));
+ RelationDescriptor relation = lookupRelation(pn.getChild("dotset").getChild("relation").getTerminal());
+ relation.addUsage(RelationDescriptor.IMAGE);
+ return new ImageSetExpr(ise, relation);
+ } else if (pn.getChild("dotinvset") != null) {
+ ImageSetExpr ise = (ImageSetExpr) parse_setexpr(pn.getChild("dotinvset").getChild("setexpr"));
+ RelationDescriptor relation = lookupRelation(pn.getChild("dotinvset").getChild("relation").getTerminal());
+ relation.addUsage(RelationDescriptor.INVIMAGE);
+ return new ImageSetExpr(ImageSetExpr.INVERSE, ise, relation);
} else {
throw new IRException();
}
/* 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 + "'");