use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addAsymFaultAssertions.
/**
* Method adds assertions associated with the asym fault event. Adds triggers
* for the communication node faults: __fault__trigger__Sender__fault_1 : bool;
* Adds trigger expression linking fault of sender node to the comm node
* behavior: output = if __fault__trigger__Sender__fault_1 then
* Sender__fault_1__node__val_out else __fault__nominal__output
*
* @param nb NodeBuilder that will have these assertions added.
*/
private void addAsymFaultAssertions(AgreeNodeBuilder nb) {
// List of idExpr holding dep ids and list for indep ids
List<Expr> triggerList = new ArrayList<>();
for (Fault fault : mapAsymFaultToCommNodes.keySet()) {
for (String nodeName : mapAsymFaultToCommNodes.get(fault)) {
// Create trigger statements for each of the faults comm nodes
IdExpr trigger = new IdExpr(nodeName + "__fault__trigger__" + fault.id);
triggerList.add(trigger);
}
// Create trigger expression that links fault of sender node to comm node
// trigger.
String compName = mapAsymFaultToCompName.get(fault);
IdExpr trigger = new IdExpr(compName + "__fault__trigger__" + fault.id);
Expr bigOrExpr = buildBigOrExpr(triggerList, 0);
Expr notBigOrExpr = new UnaryExpr(UnaryOp.NOT, bigOrExpr);
Expr ifThenElse = new IfThenElseExpr(trigger, bigOrExpr, notBigOrExpr);
nb.addAssertion(new AgreeStatement("", ifThenElse, this.topNode.reference));
triggerList.clear();
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement 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.AgreeStatement 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));
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method changeAsymConnections.
/**
* Method will remove the previous connections in the main lustre node from
* sender to receivers and add in the new connections from sender to commNode
* and from commNode to receiver. Ex: What used to be: Sender_out = reciever1.in
* Sender_out = reciever2.in Sender_out = reciever3.in Is now: Sender_out =
* asym0.in Sender_out = asym1.in Sender_out = asym2.in asym0.out = reciever1.in
* asym1.out = reciever2.in asym2.out = reciever3.in
*
* @param nb NodeBuilder for the main lustre node.
*/
private void changeAsymConnections(AgreeNodeBuilder nb) {
// Insert connections sender_output = commNode_input
for (String output : mapAsymCompOutputToCommNodeIn.keySet()) {
for (String nodeName : mapAsymCompOutputToCommNodeIn.get(output)) {
Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, new IdExpr(nodeName));
nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
}
}
// Insert connections commNode_output = receiver_input.
for (String output : mapCommNodeOutputToConnections.keySet()) {
String featureName = "";
String componentName = "";
// First access name of receiving component and its input
if (mapCommNodeOutputToConnections.get(output).eContainer() instanceof SystemInstanceImpl) {
FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
componentName = "";
featureName = fi.getName();
} else if (mapCommNodeOutputToConnections.get(output) instanceof FeatureInstanceImpl) {
FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
featureName = fi.getName();
if (fi.eContainer() instanceof ComponentInstanceImpl) {
ComponentInstanceImpl ci = (ComponentInstanceImpl) fi.eContainer();
componentName = ci.getName() + "__";
} else {
new SafetyException("Asymmetric fault must be connected to a component instance.");
}
} else {
new SafetyException("Asymmetric fault must have an allowable connection.");
}
// Create lustre connection name, add to builder.
IdExpr connectionName = new IdExpr(componentName + featureName);
Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, connectionName);
nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
}
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement 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();
}
}
Aggregations