use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method changeTopNodeAsymConnections.
/**
* Method changes top level connections to reflect communication nodes for
* asymmetric faults. Finds old connections from sender to receiver and removes
* them. Then adds new connections from sender to communication nodes and from
* communication nodes to receivers.
*
* @param nb NodeBuilder for this top node.
* @param node The top node of the program.
* @return SafetyNodeBuilder with connections changed.
*/
private SafetyNodeBuilder changeTopNodeAsymConnections(AgreeNodeBuilder nb, AgreeNode node) {
SafetyNodeBuilder sb = new SafetyNodeBuilder(node);
List<AgreeConnection> agreeConns = new ArrayList<AgreeConnection>();
int i = 0;
// Make sure we have AgreeAADLConnection and cast to access AgreeVar
for (AgreeConnection ac : sb.getConnections()) {
if (ac instanceof AgreeAADLConnection) {
AgreeAADLConnection aac = (AgreeAADLConnection) ac;
AgreeVar sourceName = aac.sourceVarName;
AgreeVar destName = aac.destinationVarName;
// cannot perform this removal of connections.
if ((sourceName.compInst == null) || (destName.compInst == null)) {
continue;
}
String senderName = sourceName.compInst.getName() + "." + sourceName.id;
String receiverName = destName.compInst.getName() + "." + destName.id;
// remove that element from agreeConns.
for (String sendKey : mapSenderToReceiver.keySet()) {
if (senderName.contentEquals(sendKey)) {
for (String receiveVal : mapSenderToReceiver.get(sendKey)) {
if (receiverName.equals(receiveVal)) {
agreeConns.add(ac);
break;
}
}
}
}
}
i++;
}
List<AgreeConnection> connList = sb.getConnections();
for (AgreeConnection j : agreeConns) {
connList.remove(j);
}
FaultASTBuilder.resetAsymMaps();
return sb;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addAsymNodeCalls.
/**
* Method adds the asym communication node calls into main node in lustre.
*
* @param nb NodeBuilder has these node calls added.
*/
private void addAsymNodeCalls(AgreeNodeBuilder nb) {
// For each key in map, get name of node and list of lustre inputs.
List<Expr> tempIds = new ArrayList<>();
for (String nodeName : mapCommNodeToInputs.keySet()) {
for (AgreeVar av : mapCommNodeToInputs.get(nodeName)) {
IdExpr id = new IdExpr(av.id);
tempIds.add(id);
}
// Create node call expression
NodeCallExpr nodeCall = new NodeCallExpr(nodeName, tempIds);
nb.addAssertion(new AgreeStatement("", nodeCall, this.topNode.reference));
tempIds.clear();
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addTopLevelMaxFaultOccurrenceConstraint.
/**
* Method adds count constraints to top level assertions.
*
* @param maxFaults No. of faults allowed in count.
* @param topNode This node (main)
* @param builder node builder will have constraints added.
*/
public void addTopLevelMaxFaultOccurrenceConstraint(int maxFaults, AgreeNode topNode, AgreeNodeBuilder builder) {
// add a global fault count
String id = "__fault__global_count";
builder.addInput(new AgreeVar(id, NamedType.INT, topNode.reference));
// assign it.
List<Expr> sumExprs = new ArrayList<>();
// getFaultCountExprList(topNode, new ArrayList<>(), sumExprs);
getFaultCountExprList(topNode, sumExprs);
Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
builder.addAssertion(new AgreeStatement("", equate, topNode.reference));
// add assertions that the mutually exclusive fault activations
for (FaultPair curPair : mutualExclusiveFaults) {
// assert that the pair cannot both be true
// get fault triggers
String ft1Trigger = this.getMainNodeFaultIndepStr(curPair.ft1);
String ft2Trigger = this.getMainNodeFaultIndepStr(curPair.ft2);
Expr ft1False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft1Trigger));
Expr ft2False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft2Trigger));
Expr ft1FalseOrft2False = new BinaryExpr(ft1False, BinaryOp.OR, ft2False);
builder.addAssertion(new AgreeStatement("", ft1FalseOrft2False, topNode.reference));
}
// assert that the value is <= maxFaults
Expr lessEqual = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(maxFaults));
builder.addAssertion(new AgreeStatement("", lessEqual, topNode.reference));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method renameEqId.
/**
* Renames eq var id to match lustre name. Ex: eq some_var : bool;
* Sender_fault_1_some_var : bool;
*
* @param f Fault with safety eq var stmts.
* @param idMap Map<String, String> from user defined var to lustre name.
* @return Returns fault with var renamed.
*/
public Fault renameEqId(Fault f, Map<String, String> idMap) {
Fault newFault = new Fault(f);
newFault.safetyEqVars.clear();
newFault.safetyEqAsserts.clear();
newFault.faultOutputMap.clear();
newFault.faultInputMap.clear();
if (!f.triggers.isEmpty()) {
throw new SafetyException("User-defined triggers are currently unsupported.");
}
// update the variable declarations
for (AgreeVar eq : f.safetyEqVars) {
if (idMap.containsKey(eq.id)) {
eq = new AgreeVar(idMap.get(eq.id), eq.type, eq.reference);
}
newFault.safetyEqVars.add(eq);
}
ReplaceIdVisitor visitor = new ReplaceIdVisitor(idMap);
for (AgreeStatement s : f.safetyEqAsserts) {
newFault.safetyEqAsserts.add(visitor.visit(s));
}
for (Map.Entry<Expr, String> element : f.faultOutputMap.entrySet()) {
newFault.faultOutputMap.put(element.getKey().accept(visitor), element.getValue());
}
for (Map.Entry<String, Expr> element : f.faultInputMap.entrySet()) {
newFault.faultInputMap.put(element.getKey(), element.getValue().accept(visitor));
}
return newFault;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addAsymCountConstraints.
/**
* Method adds the local variable for the count of asymmetric faults.
* Constraints for this count are added in assertions. Ex:
* __fault__Sender__fault_1_count : int; (as local in main)
*
* assert (__fault__Sender__fault_1_count = ((if
* asym_node_0__fault__trigger__Sender__fault_1 then 1 else 0)
*
* assert (__fault__Sender__fault_1_count <= 3); (where 3 is total no. of
* connections)
*
* @param nb NodeBuilder that will have this information added.
*/
private void addAsymCountConstraints(AgreeNodeBuilder nb) {
// Make local map saving said count with its fault.
for (Fault f : mapAsymFaultToCommNodes.keySet()) {
String id = "__fault__" + f.id + "_count";
AgreeVar count = new AgreeVar(id, NamedType.INT, topNode.reference);
nb.addInput(count);
// Get nodes to build assert stmts
List<String> nodes = mapAsymFaultToCommNodes.get(f);
List<Expr> sumExprs = new ArrayList<>();
for (String n : nodes) {
sumExprs.add(createSumExpr(new IdExpr(n + "__fault__trigger__" + f.id)));
}
// Add the constraints associated with the count.
Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
nb.addAssertion(new AgreeStatement("", equate, topNode.reference));
// Restrict to less than the total number of connections
Expr restrict = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(nodes.size()));
nb.addAssertion(new AgreeStatement("", restrict, topNode.reference));
}
}
Aggregations