Search in sources :

Example 6 with ArrayExpr

use of jkind.lustre.ArrayExpr in project AGREE by loonwerks.

the class AgreeASTBuilder method caseArrayUpdateExpr.

@Override
public Expr caseArrayUpdateExpr(ArrayUpdateExpr expr) {
    Expr arrayExpr = doSwitch(expr.getArray());
    for (int i = 0; i < expr.getIndices().size(); i++) {
        Expr indexExpr = doSwitch(expr.getIndices().get(i));
        Expr newExpr = doSwitch(expr.getValueExprs().get(i));
        arrayExpr = new jkind.lustre.ArrayUpdateExpr(arrayExpr, indexExpr, newExpr);
    }
    return arrayExpr;
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)

Example 7 with ArrayExpr

use of jkind.lustre.ArrayExpr in project AGREE by loonwerks.

the class FrameAssertionHelper method valueToExpr.

private static Expr valueToExpr(final Value value) {
    assert value != null;
    if (value instanceof ArrayValue) {
        final ArrayValue arrayValue = (ArrayValue) value;
        final ArrayList<Expr> exprList = new ArrayList<Expr>(arrayValue.elements.size());
        for (final Value childValue : arrayValue.elements) {
            exprList.add(valueToExpr(childValue));
        }
        return new ArrayExpr(exprList);
    } else if (value instanceof BooleanValue) {
        return new BoolExpr(((BooleanValue) value).value);
    } else if (value instanceof EnumValue) {
        return new IdExpr(((EnumValue) value).value);
    } else if (value instanceof IntegerValue) {
        return new IntExpr(((IntegerValue) value).value);
    } else if (value instanceof RealValue) {
        final BigFraction fraction = ((RealValue) value).value;
        return new BinaryExpr(new RealExpr(new BigDecimal(fraction.getNumerator())), BinaryOp.DIVIDE, new RealExpr(new BigDecimal(fraction.getDenominator())));
    }
    if (value instanceof TupleValue) {
        final TupleValue tupleValue = (TupleValue) value;
        final ArrayList<Expr> exprList = new ArrayList<Expr>(tupleValue.elements.size());
        for (final Value childValue : tupleValue.elements) {
            exprList.add(valueToExpr(childValue));
        }
        return new TupleExpr(exprList);
    } else {
        throw new RuntimeException("Unhandled case. Value is of type: " + value.getClass());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BigFraction(jkind.util.BigFraction) EnumValue(jkind.lustre.values.EnumValue) IntegerValue(jkind.lustre.values.IntegerValue) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) TupleValue(jkind.lustre.values.TupleValue) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) TupleValue(jkind.lustre.values.TupleValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) IntExpr(jkind.lustre.IntExpr) ArrayValue(jkind.lustre.values.ArrayValue) RealExpr(jkind.lustre.RealExpr)

Example 8 with ArrayExpr

use of jkind.lustre.ArrayExpr 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

ArrayExpr (jkind.lustre.ArrayExpr)8 IntExpr (jkind.lustre.IntExpr)8 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)7 BinaryExpr (jkind.lustre.BinaryExpr)7 BoolExpr (jkind.lustre.BoolExpr)7 Expr (jkind.lustre.Expr)7 IdExpr (jkind.lustre.IdExpr)7 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)6 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)6 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)6 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)6 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)6 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)6 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)6 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)6 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)6 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)6 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)6 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)6 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)6