use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel in project AGREE by loonwerks.
the class AGREESimulationStateElementFactory method createVariableStateElements.
private static List<AGREESimulationStateElement> createVariableStateElements(final AGREESimulationStateElement parent, final SimulationProgramType programType, final ComponentInstance componentInstance, final TimingModel parentTimingModel, final Map<ComponentInstance, Collection<SimulationVariable>> componentInstanceToVariablesMap, final Map<String, jkind.lustre.Type> typeIdToTypeMap, final Map<ComponentInstance, AgreeNode> componentInstanceToAgreeNodeMap, boolean includeSubcomponents) {
assert componentInstance != null;
assert componentInstanceToVariablesMap != null;
assert typeIdToTypeMap != null;
final List<AGREESimulationStateElement> elements = new ArrayList<AGREESimulationStateElement>();
// Get the timing model for the component instance
final AgreeNode agreeNode = componentInstanceToAgreeNodeMap.get(componentInstance);
final TimingModel timingModel = agreeNode == null ? null : agreeNode.timing;
// Create elements for subcomponents
if (includeSubcomponents) {
for (final ComponentInstance child : componentInstance.getComponentInstances()) {
final AGREESimulationStateElement newElement = new AGREESimulationStateElement(parent, child.getFullName(), edu.uah.rsesc.aadlsimulator.VariableType.NONE, null, child, child.getSubcomponent(), false);
newElement.setChildren(createVariableStateElements(newElement, programType, child, timingModel, componentInstanceToVariablesMap, typeIdToTypeMap, componentInstanceToAgreeNodeMap, programType.isMonolithic()));
elements.add(newElement);
}
}
// Create elements for simulation variables
final Collection<SimulationVariable> variables = componentInstanceToVariablesMap.get(componentInstance);
if (variables != null) {
final boolean showClockVariables = parentTimingModel == TimingModel.ASYNC;
for (SimulationVariable var : variables) {
final boolean isClock = var.getLustreId().endsWith(AgreeASTBuilder.clockIDSuffix);
boolean hidden = (var.getLustreId().contains("___") || var.getLustreId().startsWith("_")) && (!isClock || !showClockVariables);
addChildElementsForVariable(elements, parent, var.getName(), var.getType(), new IdExpr(var.getLustreId()), typeIdToTypeMap, var.getFeatureInstance(), var.getDeclarativeReference(), hidden);
}
}
return elements;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeNode visit(AgreeNode e) {
String id = e.id;
List<AgreeVar> inputs = new ArrayList<>();
for (AgreeVar input : e.inputs) {
inputs.add(this.visit(input));
}
List<AgreeVar> outputs = new ArrayList<>();
for (AgreeVar output : e.outputs) {
outputs.add(this.visit(output));
}
List<AgreeVar> locals = new ArrayList<>();
for (AgreeVar local : e.locals) {
locals.add(this.visit(local));
}
// Note that nodes and connections contain cross-references to each
// other. But, valid model structure requires that connections
// refer only to features on the this node and the sub-nodes. Thus,
// we may visit the sub-nodes first, and then use the result of that
// in visiting the connections.
//
List<AgreeNode> subNodes = new ArrayList<>();
for (AgreeNode subnode : e.subNodes) {
subNodes.add(this.visit(subnode));
}
List<AgreeConnection> connections = new ArrayList<>();
for (AgreeConnection conn : e.connections) {
connections.add(this.visit(conn));
}
List<AgreeStatement> assertions = new ArrayList<>();
for (AgreeStatement stmt : e.assertions) {
assertions.add(this.visit(stmt));
}
List<AgreeStatement> assumptions = new ArrayList<>();
for (AgreeStatement stmt : e.assumptions) {
assumptions.add(this.visit(stmt));
}
List<AgreeStatement> guarantees = new ArrayList<>();
for (AgreeStatement stmt : e.guarantees) {
guarantees.add(this.visit(stmt));
}
List<AgreeStatement> lemmas = new ArrayList<>();
for (AgreeStatement stmt : e.lemmas) {
lemmas.add(this.visit(stmt));
}
List<AgreeStatement> patternProps = new ArrayList<>();
for (AgreeStatement stmt : e.patternProps) {
patternProps.add(this.visit(stmt));
}
List<AgreeEquation> localEqs = new ArrayList<>();
for (AgreeEquation eq : e.localEquations) {
localEqs.add(this.visit(eq));
}
Expr clockConstraint = e.clockConstraint.accept(this);
Expr initialConstraint = e.initialConstraint.accept(this);
AgreeVar clockVar = this.visit(e.clockVar);
EObject reference = e.reference;
TimingModel timing = e.timing;
// ComponentInstance compinst = e.compInst;
AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addConnection(connections);
builder.addSubNode(subNodes);
builder.addAssertion(assertions);
builder.addAssumption(assumptions);
builder.addGuarantee(guarantees);
builder.addLemma(lemmas);
builder.addLocalEquation(localEqs);
builder.addPatternProp(patternProps);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
builder.setReference(reference);
builder.setTiming(timing);
builder.setCompInst(e.compInst);
builder.addTimeFall(e.timeFallMap);
builder.addTimeRise(e.timeRiseMap);
builder.addTimeOf(e.timeOfMap);
AgreeNode result = builder.build();
visitedNodes.put(e.compInst, result);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel 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);
}
Aggregations