use of jkind.lustre.BoolExpr 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.BoolExpr in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addAssumeHistStmts.
/**
* Method is used to assert that the assume hist statements for each comm node
* is true. This is added to main. Ex: assert
* (asym_node_0__Sender__sender_out____ASSUME__HIST = __HIST(true));
*
* @param nb NodeBuilder that will have these assertions added.
*/
private void addAssumeHistStmts(AgreeNodeBuilder nb) {
for (String commNodes : mapCommNodeToInputs.keySet()) {
List<AgreeVar> inputs = mapCommNodeToInputs.get(commNodes);
for (AgreeVar input : inputs) {
if (input.id.contains("__ASSUME__HIST")) {
NodeCallExpr nodeCall = new NodeCallExpr("__HIST", new BoolExpr(true));
Expr eq = new BinaryExpr(new IdExpr(input.id), BinaryOp.EQUAL, nodeCall);
nb.addAssertion(new AgreeStatement("", eq, topNode.reference));
break;
}
}
}
}
use of jkind.lustre.BoolExpr in project AMASE by loonwerks.
the class FaultASTBuilder method createAssumeHistStmt.
/**
* Creates expr: (__ASSUME__HIST => (__GUARANTEE0 and true)) and true)
*
* @param guar Reference to the guarantee within this statement
* @return BinaryExpr assume hist statement
*/
protected BinaryExpr createAssumeHistStmt(Expr guar) {
// (__ASSUME__HIST => (__GUARANTEE0 and true)) and true)
IdExpr assumeHist = new IdExpr("__ASSUME__HIST");
BoolExpr trueExpr = new BoolExpr(true);
BinaryExpr binGuar = new BinaryExpr(guar, BinaryOp.AND, trueExpr);
BinaryExpr binAssume = new BinaryExpr(assumeHist, BinaryOp.IMPLIES, binGuar);
BinaryExpr binAssumeAndTrue = new BinaryExpr(binAssume, BinaryOp.AND, trueExpr);
return binAssumeAndTrue;
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method getAgreeNode.
private AgreeNode getAgreeNode(ComponentInstance compInst, boolean isTop) {
List<AgreeVar> inputs = new ArrayList<>();
List<AgreeVar> outputs = new ArrayList<>();
List<AgreeVar> locals = new ArrayList<>();
List<AgreeAADLConnection> aadlConnections = new ArrayList<>();
List<AgreeOverriddenConnection> userDefinedConections = new ArrayList<>();
List<AgreeConnection> connections = new ArrayList<>();
List<AgreeNode> subNodes = new ArrayList<>();
List<AgreeStatement> assertions = new ArrayList<>();
List<AgreeStatement> assumptions = new ArrayList<>();
List<AgreeStatement> guarantees = new ArrayList<>();
List<AgreeStatement> lemmas = new ArrayList<>();
List<AgreeEquation> localEquations = new ArrayList<>();
List<AgreeStatement> patternProps = Collections.emptyList();
timeOfVarMap = new HashMap<>();
timeRiseVarMap = new HashMap<>();
timeFallVarMap = new HashMap<>();
unspecifiedAadlProperties = new HashMap<>();
Expr clockConstraint = new BoolExpr(true);
Expr initialConstraint = new BoolExpr(true);
String id = compInst.getName();
AgreeVar clockVar = new AgreeVar(id + clockIDSuffix, NamedType.BOOL, compInst.getSubcomponent(), compInst, null);
EObject reference = isTop ? compInst.getComponentClassifier() : compInst.getSubcomponent();
TimingModel timing = null;
boolean foundSubNode = false;
boolean hasDirectAnnex = false;
boolean hasSubcomponents = false;
ComponentClassifier compClass = compInst.getComponentClassifier();
Set<ComponentType> effectiveTypes = new HashSet<>();
Map<String, jkind.lustre.Expr> portRewriteMap = new HashMap<>();
if (compClass instanceof ComponentImplementation) {
boolean latched = false;
ComponentImplementation cc = (ComponentImplementation) compClass;
effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
if (isTop || isMonolithic) {
while (cc != null) {
AgreeContractSubclause annex = getAgreeAnnex(cc);
for (ComponentInstance subInst : compInst.getComponentInstances()) {
hasSubcomponents = true;
curInst = subInst;
AgreeNode subNode = getAgreeNode(subInst, false);
if (subNode != null && subNodes.stream().noneMatch(it -> it.reference.equals(subNode.reference))) {
foundSubNode = true;
subNodes.add(subNode);
}
}
if (annex != null) {
hasDirectAnnex = true;
AgreeContract contract = (AgreeContract) annex.getContract();
curInst = compInst;
assertions.addAll(getAssertionStatements(contract.getSpecs()));
getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
assertions.addAll(getPropertyStatements(contract.getSpecs()));
assertions.addAll(getAssignmentStatements(contract.getSpecs()));
userDefinedConections.addAll(getConnectionStatements(contract.getSpecs()));
lemmas.addAll(getLemmaStatements(contract.getSpecs()));
lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
addLustreNodes(contract.getSpecs());
gatherLustreTypes(contract.getSpecs());
// the clock constraints contain other nodes that we add
clockConstraint = getClockConstraint(contract.getSpecs(), subNodes);
timing = getTimingModel(contract.getSpecs());
outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LatchedStatement) {
latched = true;
break;
}
}
}
// Find extended effective types
effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
cc = cc.getExtended();
}
EList<ConnectionInstance> connectionInstances = compInst.getAllEnclosingConnectionInstances();
List<ConnectionInstance> foo = new ArrayList<>();
compInst.getAllComponentInstances().forEach(ci -> ci.allEnclosingConnectionInstances().forEach(foo::add));
aadlConnections.addAll(getConnectionsFromInstances(connectionInstances, compInst, subNodes, latched));
connections.addAll(filterConnections(aadlConnections, userDefinedConections));
}
ComponentType compType = ((ComponentImplementation) compClass).getType();
AgreeContractSubclause compImpAnnex = getAgreeAnnex(compClass);
if (compImpAnnex != null) {
AgreeContract contract = (AgreeContract) compImpAnnex.getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LiftContractStatement) {
Subcomponent sub = ((ComponentImplementation) compClass).getOwnedSubcomponents().get(0);
ComponentType ct = sub.getComponentType();
for (Connection conn : ((ComponentImplementation) compClass).getAllConnections()) {
NamedElement sourceNe = conn.getSource().getConnectionEnd();
NamedElement destNe = conn.getDestination().getConnectionEnd();
String sourceStr = sourceNe.getName().replace("::", "__");
String destStr = destNe.getName().replace("::", "__");
if (ct == sourceNe.getContainingClassifier()) {
portRewriteMap.put(sourceStr, new IdExpr(destStr));
} else if (ct == destNe.getContainingClassifier()) {
portRewriteMap.put(destStr, new IdExpr(sourceStr));
}
}
effectiveTypes.addAll(getEffectiveComponentTypes(ct));
}
}
}
// make compClass the type so we can get it's other contract elements
compClass = compType;
} else if (compClass instanceof ComponentType) {
effectiveTypes.addAll(getEffectiveComponentTypes((ComponentType) compClass));
} else {
throw new AgreeException("Internal error: attempt to run AGREE analysis on instance " + compInst.getFullName() + " not instance of ComponentImplementation or ComponentType.");
}
curInst = compInst;
if (timing == null) {
timing = TimingModel.SYNC;
}
for (ComponentType compType : effectiveTypes) {
AgreeContractSubclause annex = getAgreeAnnex(compType);
if (annex != null) {
hasDirectAnnex = true;
AgreeContract contract = (AgreeContract) annex.getContract();
// this makes files for monolithic verification a bit smaller
if (!isMonolithic || isTop || !hasSubcomponents) {
assumptions.addAll(getAssumptionStatements(contract.getSpecs(), portRewriteMap));
guarantees.addAll(getGuaranteeStatements(contract.getSpecs(), portRewriteMap));
lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
}
// Count eq statements with expressions as assertions
getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
assertions.addAll(getPropertyStatements(contract.getSpecs()));
outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
getAgreeInputVars(contract.getSpecs(), compInst).addAllTo(inputs, assumptions, guarantees);
initialConstraint = getInitialConstraint(contract.getSpecs());
addLustreNodes(contract.getSpecs());
gatherLustreTypes(contract.getSpecs());
}
}
gatherUnspecifiedAadlProperties(unspecifiedAadlProperties, inputs, assumptions, guarantees);
if (!(foundSubNode || hasDirectAnnex)) {
return null;
}
gatherOutputsInputsAndTypes(outputs, inputs, compInst.getFeatureInstances(), assumptions, guarantees);
AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addLocalEquation(localEquations);
builder.addConnection(connections);
builder.addSubNode(subNodes);
// Clean up any vacuous true predicates
Predicate<AgreeStatement> isBoolExprAndisTrue = st -> (st.expr instanceof BoolExpr) && ((BoolExpr) st.expr).value;
assertions.removeIf(isBoolExprAndisTrue);
assumptions.removeIf(isBoolExprAndisTrue);
guarantees.removeIf(isBoolExprAndisTrue);
builder.addAssertion(assertions);
builder.addAssumption(assumptions);
builder.addGuarantee(guarantees);
builder.addLemma(lemmas);
builder.addPatternProp(patternProps);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
builder.setReference(reference);
builder.setTiming(timing);
builder.setCompInst(compInst);
builder.addTimeOf(timeOfVarMap);
builder.addTimeRise(timeRiseVarMap);
builder.addTimeFall(timeFallVarMap);
AgreeNode result = builder.build();
renamings.put(id, compInst.getName());
refMap.put(id, compInst);
return linearizationRewriter.visit(result);
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseForallExpr.
@Override
public Expr caseForallExpr(ForallExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseForallExpr - '" + agreeType.getClass() + "' not handled");
}
NamedID binding = expr.getBinding();
Expr final_expr = new BoolExpr(true);
for (int i = 0; i < size; ++i) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
final_expr = LustreExprFactory.makeANDExpr(final_expr, body);
}
return final_expr;
}
Aggregations