use of com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType in project AGREE by loonwerks.
the class AgreeASTBuilder method getConnectionsFromInstances.
private List<AgreeAADLConnection> getConnectionsFromInstances(EList<ConnectionInstance> connectionInstances, ComponentInstance compInst, List<AgreeNode> subnodes, boolean latched) {
List<AgreeAADLConnection> result = new ArrayList<>();
for (ConnectionInstance connectionInstance : connectionInstances) {
boolean isDelayed = isDelayed(connectionInstance, compInst);
for (ConnectionReference connectionReference : connectionInstance.getConnectionReferences()) {
ConnectionInstanceEnd sourceEndInstance = connectionReference.getSource();
ConnectionInstanceEnd destinationEndInstance = connectionReference.getDestination();
ComponentInstance sourceComponentInstance = sourceEndInstance.getComponentInstance();
ComponentInstance destinationComponentInstance = destinationEndInstance.getComponentInstance();
if (!compInst.equals(sourceComponentInstance) && !compInst.getComponentInstances().contains(sourceComponentInstance)) {
// This connection reference connects to component instances not germane to this level of hierarchy
continue;
}
if (!compInst.equals(destinationComponentInstance) && !compInst.getComponentInstances().contains(destinationComponentInstance)) {
// This connection reference connects to component instances not germane to this level of hierarchy
continue;
}
// make connections only to subcomponents that have annexes
if (!compInst.equals(sourceComponentInstance) && compInst.getAllComponentInstances().contains(sourceComponentInstance)) {
if (!AgreeUtils.containsTransitiveAgreeAnnex(sourceComponentInstance, isMonolithic)) {
continue;
}
}
if (!compInst.equals(destinationComponentInstance) && compInst.getAllComponentInstances().contains(destinationComponentInstance)) {
if (!AgreeUtils.containsTransitiveAgreeAnnex(destinationComponentInstance, isMonolithic)) {
continue;
}
}
AgreeNode sourceNode = agreeNodeFromNamedEl(subnodes, sourceComponentInstance);
AgreeNode destinationNode = agreeNodeFromNamedEl(subnodes, destinationComponentInstance);
ConnectionEnd sourceConnectionEnd;
if (sourceEndInstance instanceof FeatureInstance) {
sourceConnectionEnd = ((FeatureInstance) sourceEndInstance).getFeature();
} else {
AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects from a " + sourceEndInstance.getClass().getName());
continue;
}
ConnectionEnd destinationConnectionEnd;
if (destinationEndInstance instanceof FeatureInstance) {
destinationConnectionEnd = ((FeatureInstance) destinationEndInstance).getFeature();
} else {
AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a " + destinationEndInstance.getClass().getName());
continue;
}
// TODO: Paranoia? Is this redundant with the previous lines?
if (sourceConnectionEnd instanceof DataSubcomponent || destinationConnectionEnd instanceof DataSubcomponent) {
AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a data subcomponent");
continue;
}
// Handle prefixing elements of feature groups
String sourcePrefix = null;
if (sourceConnectionEnd instanceof FeatureGroup) {
sourcePrefix = sourceConnectionEnd.getName();
}
String destinationPrefix = null;
if (destinationConnectionEnd instanceof FeatureGroup) {
destinationPrefix = destinationConnectionEnd.getName();
}
List<AgreeVar> sourceVars = getAgreePortNames(sourceConnectionEnd, sourcePrefix, sourceNode == null ? null : sourceNode.compInst);
List<AgreeVar> destinationVars = getAgreePortNames(destinationConnectionEnd, destinationPrefix, destinationNode == null ? null : destinationNode.compInst);
if (sourceVars.size() != destinationVars.size()) {
throw new AgreeException("The number of AGREE variables differ for connection '" + connectionInstance.getQualifiedName() + "'. Do the types of the source and destination differ? Perhaps one is an implementation and the other is a type?");
}
for (int i = 0; i < sourceVars.size(); i++) {
AgreeVar sourceVar = sourceVars.get(i);
AgreeVar destinationVar = destinationVars.get(i);
if (!matches((ConnectionEnd) sourceVar.reference, (ConnectionEnd) destinationVar.reference)) {
AgreeLogger.logWarning("Connection '" + connectionInstance.getQualifiedName() + "' has ports '" + sourceVar.id.replace(dotChar, ".") + "' and '" + destinationVar.id.replace(dotChar, ".") + "' of differing type");
continue;
}
if (!sourceVar.type.equals(destinationVar.type)) {
throw new AgreeException("Type mismatch during connection generation");
}
ConnectionType connType;
if (sourceVar.id.endsWith(eventSuffix)) {
connType = ConnectionType.EVENT;
} else {
connType = ConnectionType.DATA;
}
AgreeAADLConnection agreeConnection = new AgreeAADLConnection(sourceNode, destinationNode, sourceVar, destinationVar, connType, latched, isDelayed, connectionReference.getConnection());
result.add(agreeConnection);
}
}
}
return result;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeConnection visit(AgreeConnection e) {
if (e instanceof AgreeAADLConnection) {
AgreeAADLConnection aadlConn = (AgreeAADLConnection) e;
AgreeNode sourceNode = null;
if (aadlConn.sourceNode != null) {
sourceNode = visitedNodes.get(aadlConn.sourceNode.compInst);
}
AgreeNode destinationNode = null;
if (aadlConn.destinationNode != null) {
destinationNode = visitedNodes.get(aadlConn.destinationNode.compInst);
}
AgreeVar sourVar = visit(aadlConn.sourceVarName);
AgreeVar destVar = visit(aadlConn.destinationVarName);
ConnectionType type = aadlConn.type;
boolean latched = aadlConn.latched;
boolean delayed = aadlConn.delayed;
EObject reference = aadlConn.reference;
return new AgreeAADLConnection(sourceNode, destinationNode, sourVar, destVar, type, latched, delayed, reference);
} else if (e instanceof AgreeOverriddenConnection) {
AgreeOverriddenConnection overriddenCon = (AgreeOverriddenConnection) e;
AgreeStatement statement = visit(overriddenCon.statement);
return new AgreeOverriddenConnection(statement, overriddenCon.aadlConn);
}
throw new AgreeException("Unhandled Agree connection type " + e.getClass());
}
Aggregations