Search in sources :

Example 1 with ArrayValue

use of jkind.lustre.values.ArrayValue 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 2 with ArrayValue

use of jkind.lustre.values.ArrayValue 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());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BigFraction(jkind.util.BigFraction) Rational(edu.uah.rsesc.aadlsimulator.Rational) EnumValue(jkind.lustre.values.EnumValue) IntegerValue(jkind.lustre.values.IntegerValue) ArrayList(java.util.ArrayList) RecordValue(jkind.lustre.values.RecordValue) TupleValue(jkind.lustre.values.TupleValue) Entry(java.util.Map.Entry) BooleanValue(jkind.lustre.values.BooleanValue) TupleValue(jkind.lustre.values.TupleValue) IntegerValue(jkind.lustre.values.IntegerValue) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) RecordValue(jkind.lustre.values.RecordValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) ArrayValue(jkind.lustre.values.ArrayValue) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)2 ArrayValue (jkind.lustre.values.ArrayValue)2 BooleanValue (jkind.lustre.values.BooleanValue)2 EnumValue (jkind.lustre.values.EnumValue)2 IntegerValue (jkind.lustre.values.IntegerValue)2 RealValue (jkind.lustre.values.RealValue)2 TupleValue (jkind.lustre.values.TupleValue)2 Value (jkind.lustre.values.Value)2 BigFraction (jkind.util.BigFraction)2 Rational (edu.uah.rsesc.aadlsimulator.Rational)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ArrayExpr (jkind.lustre.ArrayExpr)1 BinaryExpr (jkind.lustre.BinaryExpr)1 BoolExpr (jkind.lustre.BoolExpr)1 Expr (jkind.lustre.Expr)1 IdExpr (jkind.lustre.IdExpr)1 IntExpr (jkind.lustre.IntExpr)1