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;
}
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;
}
}
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;
}
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);
}
}
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));
}
}
}
Aggregations