use of jkind.lustre.ArrayUpdateExpr in project AGREE by loonwerks.
the class ExpressionFlattener method flattenArrayExpression.
private static void flattenArrayExpression(final Expr expr, final ArrayType arrayType, final Expr[] results) {
if (expr instanceof ArrayUpdateExpr) {
final ArrayUpdateExpr updateExpr = (ArrayUpdateExpr) expr;
// Handle base array
flattenArrayExpression(updateExpr.array, arrayType, results);
// Handle the update
if (updateExpr.index instanceof IntExpr) {
final BigInteger bigIndex = ((IntExpr) updateExpr.index).value;
try {
final int index = bigIndex.intValueExact();
results[index] = updateExpr.value;
} catch (ArithmeticException ex) {
// Ignore
}
}
} else if (expr instanceof ArrayExpr) {
final ArrayExpr arrayExpr = (ArrayExpr) expr;
final int elementExpressions = Math.min(arrayType.size, arrayExpr.elements.size());
for (int i = 0; i < elementExpressions; i++) {
results[i] = arrayExpr.elements.get(i);
}
} else {
// IdExpr
for (int i = 0; i < arrayType.size; i++) {
results[i] = new ArrayAccessExpr(expr, i);
}
}
}
Aggregations