Search in sources :

Example 1 with ConnectionType

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;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 2 with ConnectionType

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());
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreeAADLConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection) EObject(org.eclipse.emf.ecore.EObject) AgreeOverriddenConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeOverriddenConnection) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)2 ConnectionType (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType)2 AgreeAADLConnection (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection)1 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)1 AgreeOverriddenConnection (com.rockwellcollins.atc.agree.analysis.ast.AgreeOverriddenConnection)1 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)1 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)1 ArrayList (java.util.ArrayList)1 EObject (org.eclipse.emf.ecore.EObject)1 ConnectionEnd (org.osate.aadl2.ConnectionEnd)1 DataSubcomponent (org.osate.aadl2.DataSubcomponent)1 FeatureGroup (org.osate.aadl2.FeatureGroup)1 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)1 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)1 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)1 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)1 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)1