use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class FaultASTBuilder method createCommNode.
/**
* Create Lustre node for asymmetric fault connection nodes.
*
* @param node AgreeNode corresponds to the "sender" node that has the fan out connections.
* This is needed to access the type of connection for input/output of this node.
* @param fstmt FaultStatement associated with the sender component output.
* @param fault Fault built from fault statement.
* @param nodeName Name of asymmetric node.
* @param connNumber How many connections from sender to receivers (used in naming).
* @return Node : lustre node of this communication node.
*/
private Node createCommNode(AgreeNode node, FaultStatement fstmt, Fault fault, String nodeName, int connNumber) {
// 1. Create unique node name
NodeBuilder newNode = new NodeBuilder(nodeName);
// 2. Get the output/input type from the node and the fstmt
List<AgreeVar> nodeOutputs = node.outputs;
AgreeVar outputOfInterest = null;
// Assume asymmetric fault first in list.
// Will have to display this to user somewhere.
List<NamedElement> nomFaultConn = new ArrayList<NamedElement>();
// Get the nominal connection
for (FaultSubcomponent fs : fstmt.getFaultDefinitions()) {
if (fs instanceof OutputStatement) {
nomFaultConn = ((OutputStatement) fs).getNom_conn();
}
}
// Get the agree node output that this fault is connected to
for (AgreeVar agreeVar : nodeOutputs) {
String temp = agreeVar.id;
if (temp.contentEquals(nomFaultConn.get(0).getName())) {
// This agreeVar is the sender var we want to save for the
// later mapping to the receiver var.
outputOfInterest = agreeVar;
}
}
// Now the same type on the AgreeNode outputOfInterest
// is the same as what we will create for the type of
// both input and output of commNode.
Type type = outputOfInterest.type;
newNode = createInputForCommNode(newNode, fault, outputOfInterest.type, nodeName);
newNode = createOutputForCommNode(newNode);
newNode = createLocalsForCommNode(newNode, fault);
newNode = createEquationsForCommNode(newNode, fault, type, nodeName);
return newNode.build();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AsymFaultASTBuilder method addFaultsToCommNode.
/**
* Creates a lustre node with all fault node calls defined for a particular agree
* node output. Returns completed Lustre node.
*
* @param agreeNode The AgreeNode which has the fault list associated with an output.
* @param faults The List<Fault> that is on an output of the agree node.
* @param senderOutput DataPortImpl is the agreeNode output that these faults are connected to.
* @param nodeName String of the name of the node to be created.
* @param i The unique id number associated with the node to be created.
* @return Node to be inserted into Lustre.
*/
private Node addFaultsToCommNode(AgreeNode agreeNode, List<Fault> faults, DataPortImpl senderOutput, String nodeName, int i) {
// Create unique node name
NodeBuilder newNode = new NodeBuilder(nodeName);
List<AgreeVar> nodeOutputs = agreeNode.outputs;
AgreeVar outputOfInterest = null;
// Get name of output according to senderOutput data port impl
String nameOfOutput = senderOutput.getName();
// Find the output in agree node outputs in order to access type.
for (AgreeVar agreeVar : nodeOutputs) {
String temp = agreeVar.id;
if (temp.contentEquals(nameOfOutput)) {
// This agreeVar is the sender var we want to save for the
// later mapping to the receiver var.
outputOfInterest = agreeVar;
}
}
if (outputOfInterest == null) {
new SafetyException("Cannot locate output for asymmetric fault in Agree: " + senderOutput.getName());
}
// Now the same type on the AgreeNode outputOfInterest
// is the same as what we will create for the type of
// both input and output of commNode.
Type type = outputOfInterest.type;
newNode = createInputForCommNode(agreeNode, newNode, faults, outputOfInterest.type, nodeName);
newNode = super.createOutputForCommNode(newNode);
newNode = createLocalsForCommNode(newNode, faults);
newNode = createEquationsForCommNode(newNode, faults, type, nodeName);
return newNode.build();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class AsymFaultASTBuilder method addFaultNodeArgsToList.
/**
* Goes through the fault and adds all arguments to the fault node into a local list.
* These are saved in the order the node must be called.
* The list is also saved in the class list of list: nodeArguments. These are used
* in the node call expression formation.
*
* @param newNode NodeBuilder has inputs created in this method corresponding to the
* fault node arguments it uses.
* @param fault Fault that holds fault node definition.
* @return
*/
private List<AgreeVar> addFaultNodeArgsToList(NodeBuilder newNode, Fault fault) {
List<AgreeVar> localsForCommNode = new ArrayList<AgreeVar>();
List<Expr> nodeArgList = new ArrayList<Expr>();
// Double check size of faultInputList, must be more than 1.
if (fault.faultInputMap.size() <= 0) {
return localsForCommNode;
} else {
for (VarDecl inputVar : fault.faultNode.inputs) {
String key = inputVar.id;
if (key.equals("trigger")) {
continue;
}
if (key.equalsIgnoreCase("val_in")) {
// First add nominal output to argument list.
nodeArgList.add(new IdExpr("__fault__nominal__output"));
} else {
// The value is the same as the fault output type.
if (fault.faultInputMap.get(key) instanceof IdExpr) {
IdExpr value = (IdExpr) fault.faultInputMap.get(key);
// Get type by accessing this in fault node input list.
Type type = null;
for (VarDecl vars : fault.faultNode.inputs) {
if (value.id.equals(vars.id)) {
type = vars.type;
break;
}
}
// be a safety eq statement.
if (type == null) {
for (AgreeVar vars : fault.safetyEqVars) {
if (value.id.equals(vars.id)) {
type = vars.type;
break;
}
}
}
// There must have been an error.
if (type == null) {
new SafetyException("Error in defining fault node arguments for fault " + fault.id);
}
AgreeVar local = new AgreeVar(value.id, type, fault.faultStatement);
IdExpr newIdForList = new IdExpr(local.id);
nodeArgList.add(newIdForList);
localsForCommNode.add(local);
newNode.createInput(local.id, type);
} else {
// If it is not IdExpr, assume that it is Real/Bool/IntExpr
// Added directly to fault node call.
nodeArgList.add(fault.faultInputMap.get(key));
}
}
}
}
// Lastly, add the trigger
nodeArgList.add(new IdExpr("__fault__trigger__" + fault.id));
nodeArguments.put(fault, nodeArgList);
return localsForCommNode;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.
the class FaultASTBuilder method addInputListAndEqAsserts.
/**
* In the case when the fault node has multiple arguments, these must be added
* to the locals list for this commNode, added to the list of locals for main node
* information, and all safetyEqAsserts corresponding to them added to equations as well.
* This method performs those actions.
*
* Size of fault.faultInputMap was checked before this method was called.
* That means that there are more than two arguments to the fault node.
* The first argument is taken care of previously (__fault__nominal__output).
* The last argument is also taken care of (fault__trigger).
* We do the rest here.
*
* @param node NodeBuilder will have input added to it.
* @param fault Fault that was made from this fstmt.
* @return List<AgreeVar> List of ordered args for the node call.
*/
private List<AgreeVar> addInputListAndEqAsserts(NodeBuilder node, Fault fault) {
List<AgreeVar> localsForCommNode = new ArrayList<AgreeVar>();
nodeArgs.clear();
// Double check size of faultInputList, must be more than 1.
if (fault.faultInputMap.size() <= 0) {
return localsForCommNode;
} else {
for (VarDecl inputVar : fault.faultNode.inputs) {
String key = inputVar.id;
if (key.equals("trigger")) {
continue;
}
if (key.equalsIgnoreCase("val_in")) {
// First add nominal output to argument list.
nodeArgs.add(new IdExpr("__fault__nominal__output"));
} else {
// The value is the same as the fault output type.
if (fault.faultInputMap.get(key) instanceof IdExpr) {
IdExpr value = (IdExpr) fault.faultInputMap.get(key);
// Get type by accessing this in fault node input list.
Type type = null;
for (VarDecl vars : fault.faultNode.inputs) {
if (value.id.equals(vars.id)) {
type = vars.type;
break;
}
}
// be a safety eq statement.
if (type == null) {
for (AgreeVar vars : fault.safetyEqVars) {
if (value.id.equals(vars.id)) {
type = vars.type;
break;
}
}
}
// There must have been an error.
if (type == null) {
new SafetyException("Error in defining fault node arguments for the fault " + fault.id + ".");
}
AgreeVar local = new AgreeVar(value.id, type, fault.faultStatement);
IdExpr newIdForList = new IdExpr(local.id);
nodeArgs.add(newIdForList);
localsForCommNode.add(local);
node.createInput(local.id, type);
} else {
// If it is not IdExpr, assume that it is Real/Bool/IntExpr
// Added directly to fault node call.
nodeArgs.add(fault.faultInputMap.get(key));
}
}
}
}
// Check for any SafetyEqStmts and add these to input
if (!fault.safetyEqVars.isEmpty()) {
for (AgreeVar eqVar : fault.safetyEqVars) {
AgreeVar newIn = new AgreeVar(eqVar.id, eqVar.type, fault.faultStatement);
if (!localsForCommNode.contains(newIn)) {
localsForCommNode.add(newIn);
node.createInput(eqVar.id, eqVar.type);
}
}
}
// Lastly, add the trigger
nodeArgs.add(new IdExpr("fault__trigger__" + fault.id));
return localsForCommNode;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LinearizationAgreeASTVisitor method linearizeStatement.
private LinearizationResult linearizeStatement(AgreeNode parent, AgreeStatement stmt, jkind.lustre.BinaryOp connective) {
contextStack.push(new LinearizationContext(parent.compInst));
List<AgreeVar> addedLocals = new ArrayList<>();
List<AgreeStatement> addedAssertions = new ArrayList<>();
AgreeStatement linearizedStatement = this.visit(stmt);
// Incorporate the additions resulting from the linearization
LinearizationContext ctx = contextStack.peek();
addedLocals.addAll(contextStack.peek().addedVars);
for (int index = 0; index < ctx.liftedConstraintExprs.size(); ++index) {
AgreeVar ephemeral = ctx.addedVars.get(index);
String statementName = stmt.string + " (linearize constraint " + ephemeral.id + ")";
addedAssertions.add(new AgreeStatement(statementName, ctx.liftedConstraintExprs.get(index), null));
}
contextStack.pop();
return new LinearizationResult(addedLocals, addedAssertions, linearizedStatement);
}
Aggregations