use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getPropertyStatements.
private List<AgreeStatement> getPropertyStatements(EList<SpecStatement> specs) {
List<AgreeStatement> props = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof PropertyStatement) {
Expr expr = doSwitch(((PropertyStatement) spec).getExpr());
expr = new BinaryExpr(new IdExpr(((PropertyStatement) spec).getName()), BinaryOp.EQUAL, expr);
props.add(new AgreeStatement("", expr, spec));
}
}
return props;
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getAssumptionStatements.
private List<AgreeStatement> getAssumptionStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
List<AgreeStatement> assumptions = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof AssumeStatement) {
AssumeStatement assumption = (AssumeStatement) spec;
String str = assumption.getStr();
if (assumption.getExpr() != null) {
assumptions.add(new AgreeStatement(str, doSwitch(assumption.getExpr()).accept(new SubstitutionVisitor(rewriteMap)), assumption));
} else {
PatternStatement pattern = assumption.getPattern();
AgreeStatement patAssumption = new AgreePatternBuilder(str, assumption, this).doSwitch(pattern);
patAssumption.expr = patAssumption.expr.accept(new SubstitutionVisitor(rewriteMap));
assumptions.add(patAssumption);
}
}
}
return assumptions;
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getEquationVars.
private List<AgreeVar> getEquationVars(EList<SpecStatement> specs, ComponentInstance compInst) {
List<AgreeVar> agreeVars = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof EqStatement) {
EList<Arg> args = ((EqStatement) spec).getLhs();
List<VarDecl> vars = agreeVarsFromArgs(args, compInst);
for (VarDecl var : vars) {
agreeVars.add((AgreeVar) var);
}
} else if (spec instanceof PropertyStatement) {
agreeVars.add(new AgreeVar(((PropertyStatement) spec).getName(), NamedType.BOOL, spec, compInst, null));
}
}
return agreeVars;
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement 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 com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getEquationStatements.
private GatheredVariablesAndConstraints getEquationStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
for (SpecStatement spec : specs) {
if (spec instanceof EqStatement) {
EqStatement eq = (EqStatement) spec;
EList<Arg> lhs = eq.getLhs();
if (eq.getExpr() != null) {
Expr expr = doSwitch(eq.getExpr()).accept(new SubstitutionVisitor(rewriteMap));
if (lhs.size() != 1) {
List<Expr> ids = new ArrayList<>();
for (Arg arg : lhs) {
ids.add(new IdExpr(arg.getName()));
}
TupleExpr tuple = new TupleExpr(ids);
expr = new BinaryExpr(tuple, BinaryOp.EQUAL, expr);
} else {
expr = new BinaryExpr(new IdExpr(lhs.get(0).getName()), BinaryOp.EQUAL, expr);
}
result.assertions.add(new AgreeStatement("", expr, spec));
}
result.obligations.addAll(getConstraintsFromArgs(lhs, eq));
}
}
return result;
}
Aggregations