use of jkind.util.BigFraction in project AGREE by loonwerks.
the class CounterexampleLoaderHelper method lustreValueToInputConstraint.
private InputConstraint lustreValueToInputConstraint(final Value value) {
if (value instanceof BooleanValue) {
final BooleanLiteral ic = InputConstraintFactory.eINSTANCE.createBooleanLiteral();
ic.setValue(((BooleanValue) value).value);
return ic;
} else if (value instanceof IntegerValue) {
final IntegerLiteral ic = InputConstraintFactory.eINSTANCE.createIntegerLiteral();
ic.setValue(((IntegerValue) value).value);
return ic;
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
final BinaryExpression ic = ExpressionFactory.createFraction(fraction.getNumerator(), fraction.getDenominator());
return ic;
} else {
throw new RuntimeException("Unsupported value type: " + value.getClass());
}
}
use of jkind.util.BigFraction in project AGREE by loonwerks.
the class AGREESimulationState method getConstantLustreValue.
// Returns the raw value stored in the counterexample provided by JKind
public Value getConstantLustreValue(final int frameIndex, final Object constant) {
if (frameIndex < 0 || frameIndex > frameInfos.size()) {
throw new IllegalArgumentException("frameIndex is outside the valid range");
}
final ConstStatement constStatement = asConstant(constant);
final com.rockwellcollins.atc.agree.agree.Expr agreeExpr = constStatement.getExpr();
if (agreeExpr instanceof IntLitExpr) {
return new IntegerValue(new BigInteger(((IntLitExpr) agreeExpr).getVal(), 10));
} else if (agreeExpr instanceof RealLitExpr) {
BigDecimal bd = new BigDecimal(((RealLitExpr) agreeExpr).getVal());
if (bd.scale() < 0) {
bd = bd.setScale(0);
}
return new RealValue(new BigFraction(bd.unscaledValue(), BigInteger.TEN.pow(bd.scale())));
} else if (agreeExpr instanceof BoolLitExpr) {
return BooleanValue.fromBoolean(((BoolLitExpr) agreeExpr).getVal().getValue());
} else {
return null;
}
}
use of jkind.util.BigFraction 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.util.BigFraction in project AGREE by loonwerks.
the class AGREESimulationState method convertLustreValue.
/**
* Converts a JKind API Lustre value to types that are independent of the JKind API. In cases where there isn't an equivalent type in the standard
* Java API, the original type will be preserved. Throws an
* @param value non-null value object.
* @throws RuntimeException if the value is not of a supported type.
* @return
*/
private Object convertLustreValue(final Value value) {
assert value != null;
if (value instanceof ArrayValue) {
final ArrayValue arrayValue = (ArrayValue) value;
final ArrayList<Object> newList = new ArrayList<Object>(arrayValue.elements.size());
for (final Value childValue : arrayValue.elements) {
newList.add(convertLustreValue(childValue));
}
return newList;
} else if (value instanceof BooleanValue) {
return ((BooleanValue) value).value;
} else if (value instanceof EnumValue) {
return ((EnumValue) value).value;
} else if (value instanceof IntegerValue) {
return ((IntegerValue) value).value;
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
return new Rational(fraction.getNumerator(), fraction.getDenominator());
} else if (value instanceof RecordValue) {
final RecordValue recordValue = (RecordValue) value;
final Map<String, Object> newMap = new HashMap<String, Object>();
for (final Entry<String, Value> entry : recordValue.fields.entrySet()) {
newMap.put(entry.getKey(), convertLustreValue(entry.getValue()));
}
return newMap;
} else if (value instanceof TupleValue) {
final TupleValue tupleValue = (TupleValue) value;
final ArrayList<Object> newList = new ArrayList<Object>(tupleValue.elements.size());
for (final Value childValue : tupleValue.elements) {
newList.add(convertLustreValue(childValue));
}
return newList;
} else {
throw new RuntimeException("Unhandled case. Value is of type: " + value.getClass());
}
}
Aggregations