this.state = state;
State.currentState = state;
- // Don't clear the state!! Do clear the IR-related state
- this.state.stTypes = null;
-
if (er == null) {
throw new IRException("IRBuilder.build: Received null ErrorReporter");
} else {
}
/* do any post checks... (type constraints, etc?) */
-
- return ok;
+
+ return ok;
}
private boolean parse_constraint(ParseNode pn) {
/* return to caller */
return sq;
- } else if (pn.getChild("relatiion") != null) { /* for < v1, v2 > in Relation */
+ } else if (pn.getChild("relation") != null) { /* for < v1, v2 > in Relation */
RelationQuantifier rq = new RelationQuantifier();
/* get vars */
} else {
throw new IRException("not supported yet");
}
-
}
private LogicStatement parse_body(ParseNode pn) {
return new LogicStatement(LogicStatement.OR, left, right);
} else if (pn.getChild("not") != null) {
/* NOT body */
- LogicStatement left = parse_body(pn.getChild("not").getChild("left").getChild("body"));
+ LogicStatement left = parse_body(pn.getChild("not").getChild("body"));
if (left == null) {
return null;
if (pn.getChild("inclusion") != null) {
ParseNode in = pn.getChild("inclusion");
- /* get quantiifer var */
- VarDescriptor vd = parse_quantifiervar(in.getChild("quantifiervar"));
+ /* Expr */
+ Expr expr = parse_expr(in.getChild("expr"));
- if (vd == null) {
+ if (expr == null) {
return null;
}
return null;
}
- return new InclusionPredicate(vd, setexpr);
- } else if (pn.getChild("sizeof") != null) {
- ParseNode sizeof = pn.getChild("sizeof");
-
- /* get set expr */
- SetExpr setexpr = parse_setexpr(sizeof.getChild("setexpr"));
-
- if (setexpr == null) {
- return null;
- }
-
- /* get comparison operator */
- String compareop = sizeof.getChild("compare").getTerminal();
- Opcode opcode = Opcode.decodeFromString(opname);
-
- if (opcode == null) {
- er.report(pn, "Unsupported operation: " + opname);
- return null;
- }
-
-
-
- return new InclusionPredicate(vd, setexpr);
- } else if (pn.getChild("comparison") != null) {
- ParseNode cn = pn.getChild("comparison");
+ return new InclusionPredicate(expr, setexpr);
+ } else if (pn.getChild("expr") != null) {
+ Expr expr = parse_expr(pn.getChild("expr"));
- /* get the expr's */
- Expr left = parse_expr(cn.getChild("left").getChild("expr"));
- Expr right = parse_expr(cn.getChild("right").getChild("expr"));
-
- if ((left == null) || (right == null)) {
+ if (expr == null) {
return null;
}
- /* get comparison operator */
- String comparison = cn.getChild("compare").getTerminal();
- assert comparison != null;
-
- return new ComparisonPredicate(comparison, left, right);
+ return new ExprPredicate(expr);
} else {
throw new IRException();
}
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
} else if (t instanceof StructureTypeDescriptor) {
StructureTypeDescriptor type = (StructureTypeDescriptor) t;
- TypeDescriptor subtype = type.getSubType();
+ TypeDescriptor subtype = type.getSuperType();
// check that the subtype is valid
if (subtype instanceof MissingTypeDescriptor) {
er.report(null, "Undefined subtype '" + subtype.getSymbol() + "'");
ok = false;
} else {
- type.setSubType(newtype);
+ type.setSuperType(newtype);
}
}
} else if (t instanceof StructureTypeDescriptor) {
StructureTypeDescriptor type = (StructureTypeDescriptor)t;
- TypeDescriptor subtype = type.getSubType();
+ TypeDescriptor subtype = type.getSuperType();
Iterator fields = type.getFields();
while (fields.hasNext()) {
return false;
}
- stGlobals.add(new VarDescriptor(name, name, td));
+ stGlobals.add(new VarDescriptor(name, name, td,true));
return true;
}
}
/* lookup the type to get the type descriptor */
- type.setSubType(lookupType(subtype, CREATE_MISSING));
+ type.setSuperType(lookupType(subtype, CREATE_MISSING));
}
// set the current type so that the recursive parses on the labels
return null;
}
- RelationExpr re = new RelationExpr();
+ String relname = pn.getChild("name").getTerminal();
+ boolean inverse = pn.getChild("inv") != null;
+ Expr expr = parse_expr(pn.getChild("expr"));
- /* get quantitifer var */
- VarDescriptor vd = parse_quantifiervar(pn.getChild("quantifiervar"));
-
- if (vd == null) {
+ if (expr == null) {
return null;
}
-
- // #TBD#: bad name
- re.setDomain(vd);
-
- /* grab list of relations */
- ParseNodeVector relations = pn.getChild("relations").getChildren();
- assert relations.size() >= 1;
-
- // #TBD#: verify that the relations are in the correct order and that the
- // first relation is getting the correct "inv" assigned from "expr"
-
- /* lets verify that these relations are defined */
- for (int i = 0; i < relations.size(); i++) {
- ParseNode rn = relations.elementAt(i);
- String relname = rn.getLabel();
- boolean inverse = rn.getChild("inv") != null;
-
- RelationDescriptor relation = lookupRelation(relname);
+
+ RelationDescriptor relation = lookupRelation(relname);
- if (relation == null) {
- /* Semantic Error: relation not definied" */
- er.report(rn, "Undefined relation '" + relname + "'");
- return null;
- }
+ if (relation == null) {
+ /* Semantic Error: relation not definied" */
+ er.report(pn, "Undefined relation '" + relname + "'");
+ return null;
+ }
- re.setRelation(relation, inverse);
+ /* add usage so correct sets are created */
+ relation.addUsage(inverse ? RelationDescriptor.INVIMAGE : RelationDescriptor.IMAGE);
- /* if we are not at end of list then create new relation and
- replace it to chain the relations */
- if (i + 1 < relations.size()) {
- re = new RelationExpr(re); // should create relation with domain as older 're'
- }
- }
-
- return re;
+ return new RelationExpr(expr, relation, inverse);
}
private SizeofExpr parse_sizeof(ParseNode pn) {
} else if (pn.getChild("dot") != null) {
VarDescriptor vd = parse_quantifiervar(pn.getChild("dot").getChild("quantifiervar"));
RelationDescriptor relation = lookupRelation(pn.getChild("dot").getChild("relation").getTerminal());
+ relation.addUsage(RelationDescriptor.IMAGE);
return new ImageSetExpr(vd, relation);
} else if (pn.getChild("dotinv") != null) {
VarDescriptor vd = parse_quantifiervar(pn.getChild("dotinv").getChild("quantifiervar"));
RelationDescriptor relation = lookupRelation(pn.getChild("dotinv").getChild("relation").getTerminal());
+ relation.addUsage(RelationDescriptor.INVIMAGE);
return new ImageSetExpr(ImageSetExpr.INVERSE, vd, relation);
} else {
throw new IRException();