use of jkind.lustre.ArrayExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseExistsExpr.
@Override
public Expr caseExistsExpr(ExistsExpr 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: caseExistsExpr - '" + agreeType.getClass() + "' not handled");
}
NamedID binding = expr.getBinding();
Expr final_expr = new BoolExpr(false);
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.makeORExpr(final_expr, body);
}
return final_expr;
}
use of jkind.lustre.ArrayExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseArrayLiteralExpr.
@Override
public Expr caseArrayLiteralExpr(ArrayLiteralExpr agreeExpr) {
List<Expr> elems = new ArrayList<>();
for (com.rockwellcollins.atc.agree.agree.Expr agreeElem : agreeExpr.getElems()) {
Expr elem = doSwitch(agreeElem);
elems.add(elem);
}
return new ArrayExpr(elems);
}
use of jkind.lustre.ArrayExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseIndicesExpr.
@Override
public Expr caseIndicesExpr(IndicesExpr expr) {
AgreeTypeSystem.TypeDef arrayTypeDef = AgreeTypeSystem.infer(expr.getArray());
if (arrayTypeDef instanceof AgreeTypeSystem.ArrayTypeDef) {
int size = ((AgreeTypeSystem.ArrayTypeDef) arrayTypeDef).size;
List<Expr> elems = new ArrayList<>();
for (int i = 0; i < size; i++) {
elems.add(new IntExpr(i + 1));
}
return new ArrayExpr(elems);
}
throw new RuntimeException("Error caseIndicesExpr");
}
use of jkind.lustre.ArrayExpr 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.lustre.ArrayExpr 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