use of com.rockwellcollins.atc.agree.agree.FlatmapExpr 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