use of jkind.lustre.ArrayAccessExpr 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.ArrayAccessExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseArraySubExpr.
@Override
public Expr caseArraySubExpr(ArraySubExpr expr) {
// Note: AADL/AGREE arrays are indexed starting at 1, JKind arrays are indexed starting at zero
Expr index = new BinaryExpr(doSwitch(expr.getIndex()), BinaryOp.MINUS, new IntExpr(1));
Expr array = doSwitch(expr.getExpr());
return new ArrayAccessExpr(array, index);
}
use of jkind.lustre.ArrayAccessExpr in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method replPathIdExpr.
/**
* Replaces original expression with a nested record update expr. ex:
* fault__nominal -> output{val:= fault__nominal}
*
* @param original Original expression
* @param toAssign What needs to be replaced and assigned in original
* @return returns completed expression
*/
private Expr replPathIdExpr(Expr original, Expr toAssign) {
if (original instanceof IdExpr) {
return toAssign;
} else if (original instanceof RecordAccessExpr) {
RecordAccessExpr rae = (RecordAccessExpr) original;
Expr newBase = replPathIdExpr(rae.record, toAssign);
return new RecordAccessExpr(newBase, rae.field);
} else if (original instanceof ArrayAccessExpr) {
ArrayAccessExpr aae = (ArrayAccessExpr) original;
Expr newBase = replPathIdExpr(aae.array, aae.index);
return new ArrayAccessExpr(newBase, aae.index);
} else {
new Exception("Problem with record expressions in safety analysis");
return null;
}
}
use of jkind.lustre.ArrayAccessExpr 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.lustre.ArrayAccessExpr 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);
}
Aggregations