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;
return null;
}
- if (pn.getChild("comparison") != null) {
- ParseNode cn = pn.getChild("comparison");
-
- /* 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)) {
- return null;
- }
-
- /* get comparison operator */
- String comparison = cn.getChild("compare").getTerminal();
- assert comparison != null;
-
- return new ComparisonPredicate(comparison, left, right);
- } else if (pn.getChild("inclusion") != 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);
+ return new InclusionPredicate(expr, setexpr);
+ } else if (pn.getChild("expr") != null) {
+ Expr expr = parse_expr(pn.getChild("expr"));
+
+ if (expr == null) {
+ return null;
+ }
+
+ return new ExprPredicate(expr);
} else {
throw new IRException();
}
} 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()) {
}
/* 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();
}
String opname = pn.getChild("op").getTerminal();
+ Opcode opcode = Opcode.decodeFromString(opname);
- Opcode opcode;
-
- if (opname.equals("add")) {
- opcode = Opcode.ADD;
- } else if (opname.equals("sub")) {
- opcode = Opcode.SUB;
- } else if (opname.equals("mult")) {
- opcode = Opcode.MULT;
- } else if (opname.equals("div")) {
- opcode = Opcode.DIV;
- } else if (opname.equals("and")) {
- opcode = Opcode.AND;
- } else if (opname.equals("or")) {
- opcode = Opcode.OR;
- } else if (opname.equals("not")) {
- opcode = Opcode.NOT;
- } else if (opname.equals("gt")) {
- opcode = Opcode.GT;
- } else if (opname.equals("ge")) {
- opcode = Opcode.GE;
- } else if (opname.equals("lt")) {
- opcode = Opcode.LT;
- } else if (opname.equals("le")) {
- opcode = Opcode.LE;
- } else if (opname.equals("eq")) {
- opcode = Opcode.EQ;
- } else if (opname.equals("ne")) {
- opcode = Opcode.NE;
- } else {
+ if (opcode == null) {
er.report(pn, "Unsupported operation: " + opname);
return null;
}