use of edu.umn.cs.crisys.safety.analysis.ast.SafetyNodeBuilder 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 edu.umn.cs.crisys.safety.analysis.ast.SafetyNodeBuilder in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method visit.
// ////////////////////////////////////////////////////////////////
//
// AGREE NODE TRAVERSAL STARTS HERE.
//
// /////////////////////////////////////////////////////////////////
@Override
public AgreeNode visit(AgreeNode node) {
Map<String, List<Pair>> parentFaultyVarsExpr = faultyVarsExpr;
boolean isTop = (node == this.topNode);
// Gather non-hardware (dependent) faults
List<Fault> faults = gatherFaults(globalLustreNodes, node, isTop);
// Gather HW faults
List<HWFault> hwFaults = gatherHWFaults(globalLustreNodes, node, isTop);
// Rename var names in faults: fault_varName
faults = renameFaultEqs(faults);
if (faultMap.containsKey(node.compInst) || hwfaultMap.containsKey(node.compInst)) {
throw new SafetyException("Node: " + node.id + " has been visited twice.");
}
faultMap.put(node.compInst, faults);
hwfaultMap.put(node.compInst, hwFaults);
faultyVarsExpr = gatherFaultyOutputs(faults, node);
// this will traverse through the child nodes
node = super.visit(node);
AgreeNodeBuilder nb = new AgreeNodeBuilder(node);
// Change this nodes flag to reflect fault tree generation or not.
if (AddFaultsToAgree.getIsGenMCS()) {
nb.setFaultTreeFlag(true);
}
// If asymmetric, only add fault triggers to agree node.
for (Fault f : faults) {
if ((f.propType == null) || (f.propType.getPty() instanceof symmetric)) {
addFaultInputs(f, nb);
addFaultLocalEqsAndAsserts(f, nb);
} else {
addFaultInputs(f, nb);
}
}
addHWFaultInputs(hwFaults, nb);
addToMutualExclusionList();
addNominalVars(node, nb);
addFaultNodeEqs(faults, nb);
if (isTop) {
topNodeVisit(nb, node);
}
node = nb.build();
faultyVarsExpr = parentFaultyVarsExpr;
// for asymmetric faults.
if (!this.mapSenderToReceiver.isEmpty() && isTop) {
SafetyNodeBuilder sb = changeTopNodeAsymConnections(nb, node);
return sb.build();
} else {
return node;
}
}
Aggregations