Search in sources :

Example 6 with ArrayAccessExpr

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

the class AgreeASTBuilder method caseFoldLeftExpr.

@Override
public Expr caseFoldLeftExpr(FoldLeftExpr expr) {
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseFoldLeftExpr");
    }
    Expr array = doSwitch(expr.getArray());
    Expr accExpr = doSwitch(expr.getInitial());
    NamedID binding = expr.getBinding();
    NamedID accBinding = expr.getAccumulator();
    for (int i = 0; i < size; i++) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
    }
    return accExpr;
}
Also used : AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedID(com.rockwellcollins.atc.agree.agree.NamedID)

Example 7 with ArrayAccessExpr

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

the class AgreeASTBuilder method caseForallExpr.

@Override
public Expr caseForallExpr(ForallExpr expr) {
    com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
    Expr array = doSwitch(arrayExpr);
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseForallExpr - '" + agreeType.getClass() + "' not handled");
    }
    NamedID binding = expr.getBinding();
    Expr final_expr = new BoolExpr(true);
    for (int i = 0; i < size; ++i) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
        final_expr = LustreExprFactory.makeANDExpr(final_expr, body);
    }
    return final_expr;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) 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) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 8 with ArrayAccessExpr

use of jkind.lustre.ArrayAccessExpr 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 9 with ArrayAccessExpr

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

ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)9 IntExpr (jkind.lustre.IntExpr)8 RecordAccessExpr (jkind.lustre.RecordAccessExpr)8 ArrayExpr (jkind.lustre.ArrayExpr)7 BinaryExpr (jkind.lustre.BinaryExpr)7 BoolExpr (jkind.lustre.BoolExpr)7 Expr (jkind.lustre.Expr)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