use of com.rockwellcollins.atc.agree.agree.FoldLeftExpr 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;
}
Aggregations