use of com.rockwellcollins.atc.agree.agree.NamedID in project AGREE by loonwerks.
the class FoldRightExprImpl method basicSetBinding.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetBinding(NamedID newBinding, NotificationChain msgs) {
NamedID oldBinding = binding;
binding = newBinding;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.FOLD_RIGHT_EXPR__BINDING, oldBinding, newBinding);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.rockwellcollins.atc.agree.agree.NamedID 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 com.rockwellcollins.atc.agree.agree.NamedID 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 com.rockwellcollins.atc.agree.agree.NamedID 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 com.rockwellcollins.atc.agree.agree.NamedID 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