Search in sources :

Example 1 with ArrayUpdateExpr

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);
        }
    }
}
Also used : ArrayExpr(jkind.lustre.ArrayExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) BigInteger(java.math.BigInteger) IntExpr(jkind.lustre.IntExpr)

Aggregations

BigInteger (java.math.BigInteger)1 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)1 ArrayExpr (jkind.lustre.ArrayExpr)1 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)1 IntExpr (jkind.lustre.IntExpr)1