use of jkind.translation.SubstitutionVisitor in project AGREE by loonwerks.
the class AgreeASTBuilder method caseFoldRightExpr.
@Override
public Expr caseFoldRightExpr(FoldRightExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseFoldRightExpr");
}
Expr array = doSwitch(expr.getArray());
Expr accExpr = doSwitch(expr.getInitial());
NamedID binding = expr.getBinding();
NamedID accBinding = expr.getAccumulator();
for (int i = size - 1; i >= 0; i--) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
}
return accExpr;
}
use of jkind.translation.SubstitutionVisitor in project AGREE by loonwerks.
the class AgreeASTBuilder method getEquationStatements.
private GatheredVariablesAndConstraints getEquationStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
for (SpecStatement spec : specs) {
if (spec instanceof EqStatement) {
EqStatement eq = (EqStatement) spec;
EList<Arg> lhs = eq.getLhs();
if (eq.getExpr() != null) {
Expr expr = doSwitch(eq.getExpr()).accept(new SubstitutionVisitor(rewriteMap));
if (lhs.size() != 1) {
List<Expr> ids = new ArrayList<>();
for (Arg arg : lhs) {
ids.add(new IdExpr(arg.getName()));
}
TupleExpr tuple = new TupleExpr(ids);
expr = new BinaryExpr(tuple, BinaryOp.EQUAL, expr);
} else {
expr = new BinaryExpr(new IdExpr(lhs.get(0).getName()), BinaryOp.EQUAL, expr);
}
result.assertions.add(new AgreeStatement("", expr, spec));
}
result.obligations.addAll(getConstraintsFromArgs(lhs, eq));
}
}
return result;
}
use of jkind.translation.SubstitutionVisitor in project AGREE by loonwerks.
the class AgreeASTBuilder method caseFlatmapExpr.
@Override
public Expr caseFlatmapExpr(FlatmapExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseFlatmapExpr");
}
Expr array = doSwitch(expr.getArray());
NamedID binding = expr.getBinding();
List<Expr> elems = new ArrayList<>();
for (int i = 0; i < size; ++i) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
AgreeTypeSystem.TypeDef innerArrType = AgreeTypeSystem.infer(expr.getExpr());
if (innerArrType instanceof AgreeTypeSystem.ArrayTypeDef) {
int innerSize = ((AgreeTypeSystem.ArrayTypeDef) innerArrType).size;
for (int j = 0; j < innerSize; j++) {
Expr innerAccess = new ArrayAccessExpr(body, j);
elems.add(innerAccess);
}
}
}
return new ArrayExpr(elems);
}
use of jkind.translation.SubstitutionVisitor in project AGREE by loonwerks.
the class AgreeASTBuilder method caseFoldLeftExpr.
@Override
public Expr caseFoldLeftExpr(FoldLeftExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseFoldLeftExpr");
}
Expr array = doSwitch(expr.getArray());
Expr accExpr = doSwitch(expr.getInitial());
NamedID binding = expr.getBinding();
NamedID accBinding = expr.getAccumulator();
for (int i = 0; i < size; i++) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
}
return accExpr;
}
use of jkind.translation.SubstitutionVisitor in project AGREE by loonwerks.
the class AgreeASTBuilder method caseForallExpr.
@Override
public Expr caseForallExpr(ForallExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseForallExpr - '" + agreeType.getClass() + "' not handled");
}
NamedID binding = expr.getBinding();
Expr final_expr = new BoolExpr(true);
for (int i = 0; i < size; ++i) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
final_expr = LustreExprFactory.makeANDExpr(final_expr, body);
}
return final_expr;
}
Aggregations