Search in sources :

Example 1 with RecordAccessExpr

use of jkind.lustre.RecordAccessExpr in project AMASE by loonwerks.

the class AsymFaultASTBuilder method createEquationsForCommNode.

/**
 * Creates equation between fault nominal output and input and an equation
 * regarding the comm node output and the fault node output.
 *
 * @param newNode NodeBuilder for comm node that needs these equations added.
 * @param faults List of faults to traverse for this comm node.
 * @param type The type on the agree node output.
 * @param nodeName The name of this comm node.
 * @return NodeBuilder with these equations added.
 */
private NodeBuilder createEquationsForCommNode(NodeBuilder newNode, List<Fault> faults, Type type, String nodeName) {
    // assign __GUARANTEE0 : fault__nominal__output = input
    // Simple case is when it is bool, real. Otherwise if it is a record
    // type, we need to access the field of the fault node input and append
    // that to the expression (i.e. __fault__nominal__output.VAL = input.VAL)
    String dotField = "";
    if (type instanceof RecordType) {
        for (Expr faultOutput : faults.get(0).faultOutputMap.keySet()) {
            if (faultOutput instanceof RecordAccessExpr) {
                RecordAccessExpr rac = (RecordAccessExpr) faultOutput;
                dotField = "." + rac.field;
            }
        }
    }
    IdExpr faultNominalOut = new IdExpr("__fault__nominal__output" + dotField);
    Expr binEx = new BinaryExpr(faultNominalOut, BinaryOp.EQUAL, new IdExpr("input" + dotField));
    IdExpr guar = new IdExpr("__GUARANTEE0");
    // This links fault nominal with node input :
    // assert (__fault__nominal__output.NODE_VAL = input.NODE_VAL)
    newNode.addEquation(guar, binEx);
    BinaryExpr binAssumeAndTrue = super.createAssumeHistStmt(guar);
    Expr assertStmt = null;
    IdExpr output = null;
    // If record type, need to reference "output.VAL"
    if (type instanceof RecordType) {
        output = new IdExpr("output" + dotField);
    } else {
        output = new IdExpr("output");
    }
    // Go through trigger list and add a nested if-then-else stmt
    // that enforces mutual exclusivity.
    Expr nested = createNestedIfThenElseExpr(triggerList, new IdExpr("__fault__nominal__output"), 0);
    BinaryExpr outputEqualsValout = new BinaryExpr(output, BinaryOp.EQUAL, nested);
    BinaryExpr finalExpr1 = new BinaryExpr(binAssumeAndTrue, BinaryOp.AND, outputEqualsValout);
    // Before finishing the assert, check to see if we have safetyEqAsserts in the fault
    // and add those to the finalExpr with "and"
    assertStmt = addSafetyEqStmts(newNode, faults, new BoolExpr(true));
    BinaryExpr finalExpr2 = new BinaryExpr(finalExpr1, BinaryOp.AND, assertStmt);
    // Assert:
    // __ASSERT = (output = (fault_node_val_out))
    // and (__ASSUME__HIST => (__GUARANTEE0 and true)))
    newNode.addEquation(new IdExpr("__ASSERT"), finalExpr2);
    // Construct the node call expression
    // If record type, add to fault nominal expression
    constructNodeCalls(newNode, dotField);
    triggerList.clear();
    return newNode;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) RecordType(jkind.lustre.RecordType) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr)

Example 2 with RecordAccessExpr

use of jkind.lustre.RecordAccessExpr in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method replPathIdExpr.

/**
 * Replaces original expression with a nested record update expr. ex:
 * fault__nominal -> output{val:= fault__nominal}
 *
 * @param original Original expression
 * @param toAssign What needs to be replaced and assigned in original
 * @return returns completed expression
 */
private Expr replPathIdExpr(Expr original, Expr toAssign) {
    if (original instanceof IdExpr) {
        return toAssign;
    } else if (original instanceof RecordAccessExpr) {
        RecordAccessExpr rae = (RecordAccessExpr) original;
        Expr newBase = replPathIdExpr(rae.record, toAssign);
        return new RecordAccessExpr(newBase, rae.field);
    } else if (original instanceof ArrayAccessExpr) {
        ArrayAccessExpr aae = (ArrayAccessExpr) original;
        Expr newBase = replPathIdExpr(aae.array, aae.index);
        return new ArrayAccessExpr(newBase, aae.index);
    } else {
        new Exception("Problem with record expressions in safety analysis");
        return null;
    }
}
Also used : RecordAccessExpr(jkind.lustre.RecordAccessExpr) IdExpr(jkind.lustre.IdExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 3 with RecordAccessExpr

use of jkind.lustre.RecordAccessExpr in project AMASE by loonwerks.

the class FaultASTBuilder method createEquationsForCommNode.

/**
 * creates equations for new communication node.
 *
 * @param node NodeBuilder
 * @param fault Fault
 * @param type Type on faulty output
 * @param nodeName Name of the communication node
 * @return NodeBuilder with equations added
 */
private NodeBuilder createEquationsForCommNode(NodeBuilder node, Fault fault, Type type, String nodeName) {
    // assign __GUARANTEE0 : fault__nominal__output = input
    // Simple case is when it is bool, real. Otherwise if it is a record
    // type, we need to access the field of the fault node input and append
    // that to the expression (i.e. __fault__nominal__output.VAL = input.VAL)
    String field = "";
    String dotField = "";
    if (type instanceof RecordType) {
        for (Expr faultOutput : fault.faultOutputMap.keySet()) {
            if (faultOutput instanceof RecordAccessExpr) {
                RecordAccessExpr rac = (RecordAccessExpr) faultOutput;
                dotField = "." + rac.field;
                field = rac.field;
            }
        }
    }
    IdExpr faultNominalOut = new IdExpr("__fault__nominal__output" + dotField);
    Expr binEx = new BinaryExpr(faultNominalOut, BinaryOp.EQUAL, new IdExpr("input" + dotField));
    IdExpr guar = new IdExpr("__GUARANTEE0");
    // This links fault nominal with node input :
    // assert (__fault__nominal__output.NODE_VAL = input.NODE_VAL)
    node.addEquation(guar, binEx);
    BinaryExpr binAssumeAndTrue = createAssumeHistStmt(guar);
    // output = (fault_node_val_out)
    // If record type, need to reference "output.VAL"
    IdExpr toAssign = null;
    toAssign = new IdExpr(getFaultNodeOutputId(fault));
    IdExpr output;
    if (type instanceof RecordType) {
        output = new IdExpr("output" + dotField);
    } else {
        output = new IdExpr("output");
    }
    // output = val_out
    BinaryExpr outputEqualsValout = new BinaryExpr(output, BinaryOp.EQUAL, toAssign);
    // Final expression
    BinaryExpr finalExpr = new BinaryExpr(binAssumeAndTrue, BinaryOp.AND, outputEqualsValout);
    // Before finishing the assert, check to see if we have safetyEqAsserts in the fault
    // and add those to the finalExpr with "and"
    addSafetyEqAssertStmts(node, fault, finalExpr);
    // Construct the node call expression
    // If record type, add to fault nominal expression
    constructNodeCallExpr(node, fault, dotField);
    return node;
}
Also used : RecordAccessExpr(jkind.lustre.RecordAccessExpr) RecordType(jkind.lustre.RecordType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr)

Example 4 with RecordAccessExpr

use of jkind.lustre.RecordAccessExpr 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 5 with RecordAccessExpr

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

the class ExpressionFlattener method flattenRecordExpression.

private static void flattenRecordExpression(final Expr expr, final RecordType recordType, final Map<String, Expr> results) {
    if (expr instanceof RecordUpdateExpr) {
        final RecordUpdateExpr updateExpr = (RecordUpdateExpr) expr;
        // Handle base record
        flattenRecordExpression(updateExpr.record, recordType, results);
        // Handle the update
        results.put(updateExpr.field, updateExpr.value);
    } else if (expr instanceof RecordExpr) {
        final RecordExpr recordExpr = (RecordExpr) expr;
        results.putAll(recordExpr.fields);
    } else {
        // IdExpr
        for (final String field : recordType.fields.keySet()) {
            results.put(field, new RecordAccessExpr(expr, field));
        }
    }
}
Also used : RecordAccessExpr(jkind.lustre.RecordAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) RecordExpr(jkind.lustre.RecordExpr)

Aggregations

RecordAccessExpr (jkind.lustre.RecordAccessExpr)5 BinaryExpr (jkind.lustre.BinaryExpr)3 BoolExpr (jkind.lustre.BoolExpr)3 Expr (jkind.lustre.Expr)3 IdExpr (jkind.lustre.IdExpr)3 NodeCallExpr (jkind.lustre.NodeCallExpr)3 RecordType (jkind.lustre.RecordType)3 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 IfThenElseExpr (jkind.lustre.IfThenElseExpr)2 SimulationProgramType (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType)1 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 ArrayType (jkind.lustre.ArrayType)1 IntExpr (jkind.lustre.IntExpr)1 NamedType (jkind.lustre.NamedType)1 RecordExpr (jkind.lustre.RecordExpr)1 RecordUpdateExpr (jkind.lustre.RecordUpdateExpr)1 TupleExpr (jkind.lustre.TupleExpr)1