Search in sources :

Example 1 with ArrayType

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

the class ExpressionFlattener method flattenEqualsExpression.

private void flattenEqualsExpression(final BinaryExpr expr, final List<BinaryExpr> results) {
    // Assume that both sides of the binary expression are the same type
    final Type leftType = expr.left.accept(typeReconstructor);
    if (leftType instanceof ArrayType) {
        flattenArrayEquality(expr, (ArrayType) leftType, results);
    } else if (leftType instanceof RecordType) {
        flattenRecordEquality(expr, (RecordType) leftType, results);
    } else if (leftType instanceof NamedType) {
        // Flatten both sides of the expression
        final Expr newLeft = flattenExpression(expr.left);
        final Expr newRight = flattenExpression(expr.right);
        if (newLeft != null && newRight != null) {
            results.add(new BinaryExpr(newLeft, expr.op, newRight));
        }
    }
}
Also used : ArrayType(jkind.lustre.ArrayType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) RecordExpr(jkind.lustre.RecordExpr) IntExpr(jkind.lustre.IntExpr) NamedType(jkind.lustre.NamedType) BinaryExpr(jkind.lustre.BinaryExpr)

Example 2 with ArrayType

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

the class AGREESimulationStateElementFactory method addChildElementsForVariable.

private static void addChildElementsForVariable(final Collection<AGREESimulationStateElement> elements, final AGREESimulationStateElement parent, final String variableName, jkind.lustre.Type variableType, final Expr lustreExpr, final Map<String, jkind.lustre.Type> typeIdToTypeMap, final FeatureInstance featureInstance, final EObject declReference, final boolean hidden) {
    assert elements != null;
    assert variableName != null;
    assert variableType != null;
    assert lustreExpr != null;
    variableType = resolveType(variableType, typeIdToTypeMap);
    if (variableType == NamedType.INT || variableType == NamedType.REAL || variableType == NamedType.BOOL) {
        elements.add(new AGREESimulationStateElement(parent, variableName, lustreTypeToSimType(variableType), lustreExpr, featureInstance, declReference, hidden));
    } else if (variableType instanceof RecordType) {
        final AGREESimulationStateElement newElement = new AGREESimulationStateElement(parent, variableName, edu.uah.rsesc.aadlsimulator.VariableType.NONE, null, featureInstance, declReference, hidden);
        final RecordType recordType = (RecordType) variableType;
        final List<AGREESimulationStateElement> recordElements = new ArrayList<AGREESimulationStateElement>();
        for (final Entry<String, jkind.lustre.Type> field : recordType.fields.entrySet()) {
            addChildElementsForVariable(recordElements, newElement, field.getKey(), field.getValue(), new RecordAccessExpr(lustreExpr, field.getKey()), typeIdToTypeMap, null, null, hidden);
        }
        newElement.setChildren(recordElements);
        elements.add(newElement);
    } else if (variableType instanceof ArrayType) {
        final ArrayType arrayType = (ArrayType) variableType;
        final Type elementType = arrayType.base;
        for (int i = 0; i < arrayType.size; i++) {
            // Offset array origin since AGREE/AADL arrays are one based and JKind arrays are 0 based
            final String indexStr = "[" + (i + 1) + "]";
            addChildElementsForVariable(elements, parent, variableName + indexStr, elementType, new ArrayAccessExpr(lustreExpr, i), typeIdToTypeMap, featureInstance, declReference, hidden);
        }
    } else {
        throw new RuntimeException("Unsupported variable type: " + variableType);
    }
}
Also used : RecordAccessExpr(jkind.lustre.RecordAccessExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayType(jkind.lustre.ArrayType) Entry(java.util.Map.Entry) SimulationProgramType(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ArrayType

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

the class TypeTable method getLustreType.

public Type getLustreType(AgreeTypeSystem.TypeDef agreeType) {
    if (agreeType == AgreeTypeSystem.Prim.IntTypeDef) {
        return NamedType.INT;
    } else if (agreeType == AgreeTypeSystem.Prim.RealTypeDef) {
        return NamedType.REAL;
    } else if (agreeType == AgreeTypeSystem.Prim.BoolTypeDef) {
        return NamedType.BOOL;
    } else if (agreeType instanceof AgreeTypeSystem.RangeIntTypeDef) {
        return NamedType.INT;
    } else if (agreeType instanceof AgreeTypeSystem.RangeRealTypeDef) {
        return NamedType.REAL;
    } else if (agreeType instanceof AgreeTypeSystem.RecordTypeDef) {
        String name = ((AgreeTypeSystem.RecordTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
        Map<String, AgreeTypeSystem.TypeDef> agreeFields = ((AgreeTypeSystem.RecordTypeDef) agreeType).fields;
        Map<String, Type> lustreFields = new HashMap<>();
        for (Entry<String, AgreeTypeSystem.TypeDef> entry : agreeFields.entrySet()) {
            String key = entry.getKey();
            Type lt = updateLustreTypeMap(entry.getValue());
            if (lt != null) {
                lustreFields.put(key, lt);
            }
        }
        RecordType lustreRecType = new RecordType(name, lustreFields);
        return lustreRecType;
    } else if (agreeType instanceof AgreeTypeSystem.EnumTypeDef) {
        String name = ((AgreeTypeSystem.EnumTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
        List<String> enumValues = new ArrayList<String>();
        for (String raw : ((AgreeTypeSystem.EnumTypeDef) agreeType).values) {
            String enumValue = raw.replace("::", "__").replace(".", "__");
            enumValues.add(enumValue);
        }
        EnumType lustreEnumType = new EnumType(name, enumValues);
        return lustreEnumType;
    } else if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        AgreeTypeSystem.TypeDef agreeBaseType = ((AgreeTypeSystem.ArrayTypeDef) agreeType).stemType;
        int dimension = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
        Type lustreBaseType = updateLustreTypeMap(agreeBaseType);
        if (lustreBaseType != null) {
            ArrayType lustreArrayType = new ArrayType(lustreBaseType, dimension);
            return lustreArrayType;
        }
    }
    // Jkind does not reason over this.
    return null;
}
Also used : ArrayList(java.util.ArrayList) ArrayType(jkind.lustre.ArrayType) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) Entry(java.util.Map.Entry) EnumType(jkind.lustre.EnumType) NamedType(jkind.lustre.NamedType) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayType (jkind.lustre.ArrayType)3 NamedType (jkind.lustre.NamedType)3 RecordType (jkind.lustre.RecordType)3 Type (jkind.lustre.Type)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 RecordAccessExpr (jkind.lustre.RecordAccessExpr)2 AgreeTypeSystem (com.rockwellcollins.atc.agree.AgreeTypeSystem)1 SimulationProgramType (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ArrayExpr (jkind.lustre.ArrayExpr)1 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)1 BinaryExpr (jkind.lustre.BinaryExpr)1 EnumType (jkind.lustre.EnumType)1 Expr (jkind.lustre.Expr)1 IntExpr (jkind.lustre.IntExpr)1 RecordExpr (jkind.lustre.RecordExpr)1