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;
}
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());
}
}
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);
}
}
}
Aggregations