Search in sources :

Example 1 with Subcomponent

use of org.osate.aadl2.Subcomponent in project VERDICT by ge-high-assurance.

the class Aadl2CsvTranslator method buildScnCompPropsTable.

/**
 * @return a scenario component properties table
 */
public Table buildScnCompPropsTable() {
    // "Scenario", "Comp", "Impl", "CompInstance"
    List<String> headers = new ArrayList<String>(Arrays.asList("Scenario", "Comp", "Impl", "CompInstance"));
    headers.addAll(componentPropertyToName.values());
    // for(Map.Entry<String, List<Property>> entry : propSetNameToCompProps.entrySet()) {
    // for(Property prop : entry.getValue()) {
    // headers.add(prop.getName());
    // }
    // }
    Table scnCompPropsTable = new Table(headers);
    for (ComponentImplementation sysImpl : compImpls) {
        if (sysImpl.getOwnedSubcomponents() != null && !sysImpl.getOwnedSubcomponents().isEmpty()) {
            for (Subcomponent subcomp : sysImpl.getOwnedSubcomponents()) {
                String subcompCompTypeName = subcomp.getComponentType().getName();
                String subcompTypeName = subcomp.getSubcomponentType().getName();
                String compCatName = subcomp.getCategory().getName().toLowerCase();
                scnCompPropsTable.addValue(scenario);
                scnCompPropsTable.addValue(subcomp.getComponentType().getName());
                scnCompPropsTable.addValue(subcompCompTypeName.equalsIgnoreCase(subcompTypeName) ? "" : subcompTypeName);
                scnCompPropsTable.addValue(subcomp.getName());
                for (Property prop : componentPropertyToName.keySet()) {
                    if (isApplicableToCat(prop, compCatName)) {
                        String value = "";
                        PropertyAcc propAcc = subcomp.getPropertyValue(prop);
                        PropertyExpression defPropExpr = prop.getDefaultValue();
                        int lastColon = prop.getName().lastIndexOf(":");
                        String propName = lastColon != -1 ? prop.getName().substring(lastColon + 1) : prop.getName();
                        if (synthesis && DefenseProperties.MBAA_COMP_DEFENSE_PROPERTIES_SET.contains(propName)) {
                            // this fools stem
                            value = "9";
                        } else if (propAcc != null && !propAcc.getAssociations().isEmpty()) {
                            value = getStrRepofPropVal(subcomp.getPropertyValue(prop));
                        } else if (defPropExpr != null) {
                            value = getStrRepofExpr(defPropExpr)[0];
                        }
                        scnCompPropsTable.addValue(value);
                    } else {
                        scnCompPropsTable.addValue("");
                    }
                }
                scnCompPropsTable.capRow();
            }
        }
    }
    return scnCompPropsTable;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) BusSubcomponent(org.osate.aadl2.BusSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) MemorySubcomponent(org.osate.aadl2.MemorySubcomponent) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) ArrayList(java.util.ArrayList) PropertyAcc(org.osate.aadl2.properties.PropertyAcc) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 2 with Subcomponent

use of org.osate.aadl2.Subcomponent in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method translateComponentImplObjects.

// End of translateProcessorTypeObjects
/**
 * Analyzing each component implementation
 * @param comImpls
 * @param m2
 * @return
 */
public Model translateComponentImplObjects(List<ComponentImplementation> comImpls, Map<Property, String> componentPropertyToName, Map<Property, String> connPropertyToName, Model m2, HashSet<String> dataTypeDecl) {
    Map<String, String> connectionToBusMap = new HashMap<>();
    // creating an object for each implementation first as we will need it later
    for (ComponentImplementation aSystemImpl : comImpls) {
        // to pack the sysImpl as a VDM componentImpl
        verdict.vdm.vdm_model.ComponentImpl packCompImpl = new verdict.vdm.vdm_model.ComponentImpl();
        // setting "name" field of packCompImpl, will need later
        packCompImpl.setName(aSystemImpl.getName());
        // Note: Will skip "Nodebody" field for now
        // ISSUE: No "id" field in Component implementations
        packCompImpl.setId(aSystemImpl.getQualifiedName());
        // adding object to "componentImpl" field of m2
        m2.getComponentImpl().add(packCompImpl);
        // update map (connection-name -> bus-Instance-Name)
        for (PropertyAssociation propAssoc : aSystemImpl.getOwnedPropertyAssociations()) {
            if (!(propAssoc.getProperty().getName().equalsIgnoreCase("Actual_Connection_Binding"))) {
                System.out.println("System Implementation contains property " + propAssoc.getProperty().getName() + " which is not currently handled.");
                continue;
            }
            if (propAssoc.getOwnedValues().size() != 1) {
                throw new RuntimeException("Unexpected number of property owned values: " + propAssoc.getOwnedValues().size());
            }
            if (!(propAssoc.getOwnedValues().get(0).getOwnedValue() instanceof ListValueImpl)) {
                throw new RuntimeException("Unexpected type of property owned value");
            } else {
                ListValueImpl listVal = (ListValueImpl) propAssoc.getOwnedValues().get(0).getOwnedValue();
                if (listVal.getOwnedListElements().size() != 1) {
                    throw new RuntimeException("Unexpected number of list elements are associated with the property owned value");
                } else if (!(listVal.getOwnedListElements().get(0) instanceof ReferenceValueImpl)) {
                    throw new RuntimeException("Unexpected number of list elements are associated with the property owned value");
                } else {
                    ReferenceValueImpl refVal = (ReferenceValueImpl) listVal.getOwnedListElements().get(0);
                    ContainmentPathElement pathEle = refVal.getPath();
                    while (!(pathEle.getNamedElement() instanceof BusSubcomponent)) {
                        pathEle = pathEle.getPath();
                    }
                    String busInstanceName = pathEle.getNamedElement().getQualifiedName();
                    for (ContainedNamedElement connection : propAssoc.getAppliesTos()) {
                        // updating map (connection name -> bus name)
                        connectionToBusMap.put(connection.getPath().getNamedElement().getQualifiedName(), busInstanceName);
                    }
                }
            }
        }
    }
    // Getting the reference of the object previously created and populating
    for (ComponentImplementation aCompImpl : comImpls) {
        // variable to refer to previously created object
        verdict.vdm.vdm_model.ComponentImpl packCompImpl = new verdict.vdm.vdm_model.ComponentImpl();
        // finding previously created object
        for (verdict.vdm.vdm_model.ComponentImpl anImplObj : m2.getComponentImpl()) {
            if (anImplObj.getId().equalsIgnoreCase(aCompImpl.getQualifiedName())) {
                packCompImpl = anImplObj;
            }
        }
        // setting "type" field of packCompImpl
        for (verdict.vdm.vdm_model.ComponentType cType : m2.getComponentType()) {
            if (aCompImpl.getType().getQualifiedName().equals(cType.getId())) {
                packCompImpl.setType(cType);
            }
        }
        // End of setting "type"
        // a BlockImpl object to pack all info for packCompImpl.blockImpl
        verdict.vdm.vdm_model.BlockImpl packBlockImpl = new verdict.vdm.vdm_model.BlockImpl();
        // adding all subcomponents to "subcomponent" field of packBlockImpl
        for (Subcomponent aSubComp : aCompImpl.getOwnedSubcomponents()) {
            // to pack all information of a subcomponent
            verdict.vdm.vdm_model.ComponentInstance packSubComp = new verdict.vdm.vdm_model.ComponentInstance();
            // ISSUE: No "id" field in subcomponents
            packSubComp.setId(aSubComp.getQualifiedName());
            // setting "name" field of packSubComp
            packSubComp.setName(aSubComp.getFullName());
            // setting "specification" field of packSubComp
            for (verdict.vdm.vdm_model.ComponentType cType : m2.getComponentType()) {
                if (aSubComp.getComponentType().getName().equals(cType.getName())) {
                    packSubComp.setSpecification(cType);
                }
            }
            // setting the "implementation" field of packSubComp
            for (verdict.vdm.vdm_model.ComponentImpl cImpl : m2.getComponentImpl()) {
                // if(aSubComp.getSubcomponentType().getName().equals(cImpl.getName())){
                if (aSubComp.getSubcomponentType().getQualifiedName().equals(cImpl.getId())) {
                    packSubComp.setImplementation(cImpl);
                }
            }
            // setting "attribute" field of packSubComp
            // category of subComponent
            String aSubCompCatName = aSubComp.getCategory().getName().toLowerCase();
            // checking all collected properties in componentPropertyToName
            for (Property prop : componentPropertyToName.keySet()) {
                if (isApplicableToCat(prop, aSubCompCatName)) {
                    // create a GenericAttribute object to pack the property
                    verdict.vdm.vdm_data.GenericAttribute anAttribute = new verdict.vdm.vdm_data.GenericAttribute();
                    String value = "";
                    PropertyAcc propAcc = aSubComp.getPropertyValue(prop);
                    PropertyExpression defPropExpr = prop.getDefaultValue();
                    if (propAcc != null && !propAcc.getAssociations().isEmpty()) {
                        value = getStrRepofPropVal(aSubComp.getPropertyValue(prop));
                    } else if (defPropExpr != null) {
                        value = getStrRepofExpr(defPropExpr)[0];
                    }
                    if (!value.equals("")) {
                        // setting the "name" and "value" field of anAttribute
                        anAttribute.setName(componentPropertyToName.get(prop));
                        anAttribute.setValue(value);
                        // get the property type
                        PropertyType propType = prop.getPropertyType();
                        QName type = new QName("String");
                        if (propType instanceof AadlBooleanImpl) {
                            type = new QName("Bool");
                        } else if (propType instanceof AadlIntegerImpl) {
                            type = new QName("Int");
                        } else if (propType instanceof EnumerationTypeImpl) {
                            type = new QName("String");
                        } else {
                            if (!(propType instanceof AadlStringImpl)) {
                                type = new QName(propType.toString());
                            }
                        }
                        // parse propertyType fetched using prop.getOwnedPropertyType() and map it to "Bool", "Int", or "String"
                        anAttribute.setType(type);
                        // adding asAttribute to packSubComp
                        packSubComp.getAttribute().add(anAttribute);
                    }
                } else {
                    // for outer if
                    continue;
                }
            }
            // adding packSubComp to packBlockImpl
            packBlockImpl.getSubcomponent().add(packSubComp);
            packCompImpl.setBlockImpl(packBlockImpl);
        }
        // adding all connections to "connections" field of packBlockImpl
        if (aCompImpl.getOwnedConnections() != null && !aCompImpl.getOwnedConnections().isEmpty()) {
            for (Connection aConn : aCompImpl.getOwnedConnections()) {
                // to pack all information of a connection
                verdict.vdm.vdm_model.Connection packConn = new verdict.vdm.vdm_model.Connection();
                // populate connectionKind
                packConn.setConnectionKind(getConnectionKind(aConn));
                // variables to unpack information from AADL object
                String srcCompInstName = "";
                String destCompInstName = "";
                Context srcConnContext = aConn.getAllSourceContext();
                Context destConnContext = aConn.getAllDestinationContext();
                ConnectionEnd srcConnectionEnd = aConn.getAllSource();
                ConnectionEnd destConnectionEnd = aConn.getAllDestination();
                if (srcConnContext != null) {
                    srcCompInstName = srcConnContext.getName();
                }
                if (destConnContext != null) {
                    destCompInstName = destConnContext.getName();
                }
                String srcPortTypeName = "";
                String destPortTypeName = "";
                String srcPortName = srcConnectionEnd.getName();
                String destPortName = destConnectionEnd.getName();
                // variables to capture data type information
                DataSubcomponentType srcDataSubCompType = null;
                DataSubcomponentType destDataSubCompType = null;
                if (srcConnectionEnd instanceof DataPort) {
                    srcPortTypeName = ((DataPort) srcConnectionEnd).isIn() ? (((DataPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
                    srcDataSubCompType = ((DataPort) srcConnectionEnd).getDataFeatureClassifier();
                } else if (srcConnectionEnd instanceof EventDataPort) {
                    srcPortTypeName = ((EventDataPort) srcConnectionEnd).isIn() ? (((EventDataPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
                    srcDataSubCompType = ((EventDataPort) srcConnectionEnd).getDataFeatureClassifier();
                } else if (srcConnectionEnd instanceof DataAccess) {
                    AccessType type = ((DataAccess) srcConnectionEnd).getKind();
                    if (type == AccessType.PROVIDES) {
                        srcPortTypeName = "providesDataAccess";
                    } else if (type == AccessType.REQUIRES) {
                        srcPortTypeName = "requiresDataAccess";
                    } else {
                        throw new RuntimeException("Unexpected access type: " + type);
                    }
                    srcDataSubCompType = ((DataAccess) srcConnectionEnd).getDataFeatureClassifier();
                } else if (srcConnectionEnd instanceof DataSubcomponent) {
                    srcDataSubCompType = ((DataSubcomponent) srcConnectionEnd).getDataSubcomponentType();
                    srcPortTypeName = "data";
                } else if (srcConnectionEnd instanceof BusAccess) {
                    // AccessType type = ((BusAccess) srcConnectionEnd).getKind();
                    // if(type == AccessType.PROVIDES) {
                    // srcPortTypeName = "providesBusAccess";
                    // } else if(type == AccessType.REQUIRES) {
                    // srcPortTypeName = "requiresBusAccess";
                    // } else {
                    // throw new RuntimeException("Unexpected access type: " + type);
                    // }
                    // BusFeatureClassifier busfeatureClassifier = ((BusAccess) srcConnectionEnd).getBusFeatureClassifier();
                    // if(busfeatureClassifier instanceof BusImplementation) {
                    // srcBusImpl = (BusImplementation)busfeatureClassifier;
                    // }
                    System.out.println("Warning: Unsupported AADL component element type: " + srcConnectionEnd);
                    continue;
                } else if (srcConnectionEnd instanceof BusSubcomponent) {
                    // srcBusSubCompType = ((BusSubcomponent)srcConnectionEnd).getBusSubcomponentType();
                    // srcPortTypeName = "bus";
                    System.out.println("Warning: Unsupported AADL component element type: " + srcConnectionEnd);
                    continue;
                } else if (srcConnectionEnd instanceof EventPort) {
                    srcPortTypeName = ((EventPort) srcConnectionEnd).isIn() ? (((EventPort) srcConnectionEnd).isOut() ? "inOut" : "in") : "out";
                } else {
                    throw new RuntimeException("Unsupported AADL component element type: " + srcConnectionEnd + "encountered while processing connections");
                }
                if (destConnectionEnd instanceof DataPort) {
                    destPortTypeName = ((DataPort) destConnectionEnd).isIn() ? (((DataPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
                    destDataSubCompType = ((DataPort) destConnectionEnd).getDataFeatureClassifier();
                } else if (destConnectionEnd instanceof EventDataPort) {
                    destPortTypeName = ((EventDataPort) destConnectionEnd).isIn() ? (((EventDataPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
                    destDataSubCompType = ((EventDataPort) destConnectionEnd).getDataFeatureClassifier();
                } else if (destConnectionEnd instanceof DataAccess) {
                    AccessType type = ((DataAccess) destConnectionEnd).getKind();
                    if (type == AccessType.PROVIDES) {
                        destPortTypeName = "providesDataAccess";
                    } else if (type == AccessType.REQUIRES) {
                        destPortTypeName = "requiresDataAccess";
                    }
                    destDataSubCompType = ((DataAccess) destConnectionEnd).getDataFeatureClassifier();
                } else if (destConnectionEnd instanceof DataSubcomponent) {
                    destDataSubCompType = ((DataSubcomponent) destConnectionEnd).getDataSubcomponentType();
                    destPortTypeName = "data";
                } else if (destConnectionEnd instanceof BusAccess) {
                    // AccessType type = ((BusAccess) destConnectionEnd).getKind();
                    // if(type == AccessType.PROVIDES) {
                    // destPortTypeName = "providesBusAccess";
                    // } else if(type == AccessType.REQUIRES) {
                    // destPortTypeName = "requiresBusAccess";
                    // } else {
                    // throw new RuntimeException("Unexpected access type: " + type);
                    // }
                    // BusFeatureClassifier busfeatureClassifier = ((BusAccess) destConnectionEnd).getBusFeatureClassifier();
                    // if(busfeatureClassifier instanceof BusImplementation) {
                    // destBusImpl = (BusImplementation)busfeatureClassifier;
                    // }
                    System.out.println("Warning: Unsupported AADL component element type: " + destConnectionEnd);
                    continue;
                } else if (destConnectionEnd instanceof BusSubcomponent) {
                    // destBusSubCompType = ((BusSubcomponent)destConnectionEnd).getBusSubcomponentType();
                    // destPortTypeName = "bus";
                    System.out.println("Warning: Unsupported AADL component element type: " + destConnectionEnd);
                    continue;
                } else if (destConnectionEnd instanceof EventPort) {
                    destPortTypeName = ((EventPort) destConnectionEnd).isIn() ? (((EventPort) destConnectionEnd).isOut() ? "inOut" : "in") : "out";
                } else {
                    throw new RuntimeException("Unsupported AADL component element type: " + destConnectionEnd + "encountered while processing connections");
                }
                // setting name
                packConn.setName(aConn.getFullName());
                packConn.setQualifiedName(aConn.getQualifiedName());
                if (connectionToBusMap.containsKey(aConn.getQualifiedName())) {
                    packConn.setActualConnectionBinding(connectionToBusMap.get(aConn.getQualifiedName()));
                }
                // --- Populate packConn below ---
                // to pack source
                verdict.vdm.vdm_model.ConnectionEnd packSrcEnd = new verdict.vdm.vdm_model.ConnectionEnd();
                // to pack "componentPort"  of packSrcEnd
                verdict.vdm.vdm_model.Port packSrcEndPort = new verdict.vdm.vdm_model.Port();
                // } else
                if (srcConnectionEnd instanceof EventPort) {
                    packSrcEndPort = createVdmConnectionEventPort(srcPortName, srcPortTypeName, srcConnectionEnd.getQualifiedName());
                } else {
                    // if not a bus access port or bus implementation port or event port
                    packSrcEndPort = createVdmConnectionPort(srcPortName, srcPortTypeName, srcConnectionEnd.getQualifiedName(), srcDataSubCompType, m2, dataTypeDecl);
                }
                // If source port is independent of a component instance
                if (srcCompInstName.equals("")) {
                    packSrcEnd.setComponentPort(packSrcEndPort);
                } else {
                    // to pack "subcomponentPort" of packSrcEnd
                    verdict.vdm.vdm_model.CompInstancePort packSrcEndCompInstPort = new verdict.vdm.vdm_model.CompInstancePort();
                    // putting a reference to appropriate "subcomponent" from packBlockImpl in "subcomponent" of packSrcEndCompInstPort
                    for (verdict.vdm.vdm_model.ComponentInstance checkCompInst : packBlockImpl.getSubcomponent()) {
                        if (checkCompInst.getName().equals(srcCompInstName)) {
                            packSrcEndCompInstPort.setSubcomponent(checkCompInst);
                            break;
                        } else {
                            continue;
                        }
                    }
                    packSrcEndCompInstPort.setPort(packSrcEndPort);
                    // setting "subcomponentPort" of packSrcEnd
                    packSrcEnd.setSubcomponentPort(packSrcEndCompInstPort);
                }
                // adding to "source" of packConn
                packConn.setSource(packSrcEnd);
                // to pack destination
                verdict.vdm.vdm_model.ConnectionEnd packDestEnd = new verdict.vdm.vdm_model.ConnectionEnd();
                // to pack "componentPort"  of packDestEnd
                verdict.vdm.vdm_model.Port packDestEndPort = new verdict.vdm.vdm_model.Port();
                // } else
                if (destConnectionEnd instanceof EventPort) {
                    packDestEndPort = createVdmConnectionEventPort(destPortName, destPortTypeName, destConnectionEnd.getQualifiedName());
                } else {
                    // if not a bus access port or bus implementation port or eventport
                    packDestEndPort = createVdmConnectionPort(destPortName, destPortTypeName, destConnectionEnd.getQualifiedName(), destDataSubCompType, m2, dataTypeDecl);
                }
                // If source port is independent of a component instance
                if (destCompInstName.equals("")) {
                    packDestEnd.setComponentPort(packDestEndPort);
                } else {
                    // to pack "subcomponentPort" of packSrcEnd
                    verdict.vdm.vdm_model.CompInstancePort packDestEndCompInstPort = new verdict.vdm.vdm_model.CompInstancePort();
                    // putting a reference to appropriate "subcomponent" from packBlockImpl in "subcomponent" of packSrcEndCompInstPort
                    for (verdict.vdm.vdm_model.ComponentInstance checkCompInst : packBlockImpl.getSubcomponent()) {
                        if (checkCompInst.getName().equals(destCompInstName)) {
                            packDestEndCompInstPort.setSubcomponent(checkCompInst);
                            break;
                        } else {
                            continue;
                        }
                    }
                    packDestEndCompInstPort.setPort(packDestEndPort);
                    // setting "subcomponentPort" of packDestEnd
                    packDestEnd.setSubcomponentPort(packDestEndCompInstPort);
                }
                // adding to "source" of packConn
                packConn.setDestination(packDestEnd);
                // adding connection properties from connProperty.ToName
                for (Property prop : connPropertyToName.keySet()) {
                    // create a GenericAttribute object to pack the property
                    verdict.vdm.vdm_data.GenericAttribute aConnAttribute = new verdict.vdm.vdm_data.GenericAttribute();
                    String value = "";
                    PropertyAcc propAcc = aConn.getPropertyValue(prop);
                    PropertyExpression defPropExpr = prop.getDefaultValue();
                    if (propAcc != null && !propAcc.getAssociations().isEmpty()) {
                        value = getStrRepofPropVal(propAcc);
                    } else if (defPropExpr != null) {
                        value = getStrRepofExpr(defPropExpr)[0];
                    }
                    if (!value.equals("")) {
                        // setting the "name" and "value" field of anAttribute
                        aConnAttribute.setName(connPropertyToName.get(prop));
                        aConnAttribute.setValue(value);
                        PropertyType propType = prop.getPropertyType();
                        QName type = new QName("String");
                        if (propType instanceof AadlBooleanImpl) {
                            type = new QName("Bool");
                        } else if (propType instanceof AadlIntegerImpl) {
                            type = new QName("Int");
                        } else if (propType instanceof EnumerationTypeImpl) {
                            type = new QName("String");
                        } else {
                            if (!(propType instanceof AadlStringImpl)) {
                                type = new QName(propType.toString());
                            }
                        }
                        // parse propertyType fetched using prop.getOwnedPropertyType() and map it to "Bool", "Int", or "String"
                        aConnAttribute.setType(type);
                        // adding asAttribute to packSubComp
                        packConn.getAttribute().add(aConnAttribute);
                    }
                }
                if (aConn.isBidirectional()) {
                    packConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("bidirectional"));
                    // to pack reverse connection
                    verdict.vdm.vdm_model.Connection packReverseConn = new verdict.vdm.vdm_model.Connection();
                    packReverseConn.setName(packConn.getName() + "_reverse");
                    packReverseConn.setSource(packConn.getDestination());
                    packReverseConn.setDestination(packConn.getSource());
                    for (verdict.vdm.vdm_data.GenericAttribute anAttribute : packConn.getAttribute()) {
                        packReverseConn.getAttribute().add(anAttribute);
                    }
                    packReverseConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("bidirectional"));
                    // add packReverseConn to packBlockImpl
                    packBlockImpl.getConnection().add(packReverseConn);
                } else {
                    packConn.setDirection(verdict.vdm.vdm_model.Direction.fromValue("unidirectional"));
                }
                // add packConn to packBlockImpl
                packBlockImpl.getConnection().add(packConn);
                packCompImpl.setBlockImpl(packBlockImpl);
            }
        }
    // End of adding all connections
    // setting "blackImpl" field of packCompImpl
    // packCompImpl.setBlockImpl(packBlockImpl);
    }
    // return populated Model
    return m2;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) PropertyType(org.osate.aadl2.PropertyType) Port(verdict.vdm.vdm_model.Port) DataAccess(org.osate.aadl2.DataAccess) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) BusSubcomponent(org.osate.aadl2.BusSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) MemorySubcomponent(org.osate.aadl2.MemorySubcomponent) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) PropertyAcc(org.osate.aadl2.properties.PropertyAcc) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) EventDataPort(org.osate.aadl2.EventDataPort) AccessType(org.osate.aadl2.AccessType) EnumerationTypeImpl(org.osate.aadl2.impl.EnumerationTypeImpl) BusSubcomponent(org.osate.aadl2.BusSubcomponent) ReferenceValueImpl(org.osate.aadl2.impl.ReferenceValueImpl) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ComponentImplementation(org.osate.aadl2.ComponentImplementation) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EventPort(org.osate.aadl2.EventPort) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property) Context(org.osate.aadl2.Context) BusAccess(org.osate.aadl2.BusAccess) AadlBooleanImpl(org.osate.aadl2.impl.AadlBooleanImpl) QName(javax.xml.namespace.QName) AadlStringImpl(org.osate.aadl2.impl.AadlStringImpl) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Connection(org.osate.aadl2.Connection) AadlIntegerImpl(org.osate.aadl2.impl.AadlIntegerImpl) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ConnectionEnd(org.osate.aadl2.ConnectionEnd)

Example 3 with Subcomponent

use of org.osate.aadl2.Subcomponent in project VERDICT by ge-high-assurance.

the class SynthesisAadlWriter method perform.

public static void perform(IProject project, File projectDir, ResultsInstance results) {
    if (!saveEditor())
        return;
    Map<String, Property> props = new LinkedHashMap<>();
    {
        List<EObject> objs = VerdictHandlersUtils.preprocessAadlFiles(projectDir);
        for (EObject obj : objs) {
            if (obj instanceof Property) {
                Property prop = (Property) obj;
                props.put(prop.getFullName(), prop);
            }
        }
    }
    Map<String, List<ResultsInstance.Item>> elemChanges = new LinkedHashMap<>();
    for (ResultsInstance.Item item : results.items) {
        if (!elemChanges.containsKey(item.component)) {
            elemChanges.put(item.component, new ArrayList<>());
        }
        elemChanges.get(item.component).add(item);
    }
    VerdictHandlersUtils.modifyAadlDocuments(project, (file, resource) -> {
        if (resource != null) {
            resource.getAllContents().forEachRemaining(obj -> {
                if (obj instanceof Subcomponent && !(obj instanceof DataSubcomponent)) {
                    Subcomponent comp = (Subcomponent) obj;
                    applyChangesToElem(comp, props, elemChanges);
                } else if (obj instanceof Connection) {
                    Connection conn = (Connection) obj;
                    applyChangesToElem(conn, props, elemChanges);
                }
            });
        } else {
            System.err.println("Error: resource is null for file: " + file);
        }
    });
}
Also used : Connection(org.osate.aadl2.Connection) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) EObject(org.eclipse.emf.ecore.EObject) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.osate.aadl2.Property)

Example 4 with Subcomponent

use of org.osate.aadl2.Subcomponent in project VERDICT by ge-high-assurance.

the class Agree2Vdm method resolveAADLDataImplementationType.

private void resolveAADLDataImplementationType(DataImplementation dataImplementationImpl, HashSet<String> dataTypeDecl, Model model) {
    verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
    // GET DETAILS OF THE DATA IMPLEMENTATION AND CREATE CORRESPONDING VDM DATATYPE
    EList<DataSubcomponent> subcomponents = dataImplementationImpl.getOwnedDataSubcomponents();
    if (!subcomponents.isEmpty()) {
        // if the dataType definition has subcomponents
        RecordType recType = new RecordType();
        for (DataSubcomponent dataSubComp : subcomponents) {
            RecordField recField = new RecordField();
            recField.setName(dataSubComp.getName());
            DataSubcomponentType dataSubCompType = dataSubComp.getDataSubcomponentType();
            if (dataSubCompType instanceof org.osate.aadl2.DataType) {
                org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) dataSubCompType;
                // the line below is just to ensure that the type's declaration is added to VDM
                resolveAADLDataType(aadlDataType, dataTypeDecl, model);
                verdict.vdm.vdm_data.DataType recFieldDtype = getVdmTypeFromAADLType(aadlDataType);
                recField.setType(recFieldDtype);
                recType.getRecordField().add(recField);
            } else if (dataSubCompType instanceof DataImplementation) {
                DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
                // the line below is just to ensure that the type's declaration is added to VDM
                resolveAADLDataImplementationType(dataSubCompDataImplementation, dataTypeDecl, model);
                verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
                recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
                recField.setType(recFieldDtype);
                recType.getRecordField().add(recField);
            } else {
                System.out.println("Unexpected Data Subcomponent that is not a DataTypeImpl or DataImplementatioImpl.");
            }
        }
        if (recType.getRecordField().size() != 0) {
            dtype.setRecordType(recType);
            // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
            String dataImplementationName = dataImplementationImpl.getName();
            if (!dataTypeDecl.contains(dataImplementationName)) {
                dataTypeDecl.add(dataImplementationName);
                // vdm data type declaration
                TypeDeclaration dataTypeVdm = new TypeDeclaration();
                dataTypeVdm.setName(dataImplementationName);
                dataTypeVdm.setDefinition(dtype);
                // add the typeDeclaration to the model
                model.getTypeDeclaration().add(dataTypeVdm);
            }
        }
    } else {
        // if the dataType is base type boolean or integer or char or string
        System.out.println("Unexpected data implementation type with no subcomponents");
        // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
        String dataImplementationName = dataImplementationImpl.getName();
        if (!dataTypeDecl.contains(dataImplementationName)) {
            dataTypeDecl.add(dataImplementationName);
            // vdm data type declaration
            TypeDeclaration dataTypeVdm = new TypeDeclaration();
            dataTypeVdm.setName(dataImplementationName);
            // add the typeDeclaration to the model
            model.getTypeDeclaration().add(dataTypeVdm);
        }
    }
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) DataImplementation(org.osate.aadl2.DataImplementation) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) RecordType(verdict.vdm.vdm_data.RecordType) DataSubcomponent(org.osate.aadl2.DataSubcomponent) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 5 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeASTBuilder method getMNSynchConstraint.

private Expr getMNSynchConstraint(MNSynchStatement sync) {
    Set<String> nodeNames = new HashSet<>();
    Expr clockAssertion = new BoolExpr(true);
    for (int i = 0; i < sync.getComp1().size(); i++) {
        Subcomponent maxComp = (Subcomponent) sync.getComp1().get(i);
        Subcomponent minComp = (Subcomponent) sync.getComp2().get(i);
        Expr maxClock = new IdExpr(maxComp.getName() + clockIDSuffix);
        Expr minClock = new IdExpr(minComp.getName() + clockIDSuffix);
        int max = Integer.valueOf(sync.getMax().get(i));
        int min = Integer.valueOf(sync.getMin().get(i));
        MNSynchronyElement elem = new MNSynchronyElement(maxClock, minClock, max, min);
        String nodeName = "__calendar_node_" + elem.max + "_" + elem.min;
        nodeName = getObjectLocationPrefix(sync) + nodeName;
        if (!nodeNames.contains(nodeName)) {
            nodeNames.add(nodeName);
            Node calNode = AgreeCalendarUtils.getMNCalendar(nodeName, elem.max, elem.min);
            addToNodeList(calNode);
        }
        NodeCallExpr nodeCall = new NodeCallExpr(nodeName, elem.maxClock, elem.minClock);
        clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
        nodeCall = new NodeCallExpr(nodeName, elem.minClock, elem.maxClock);
        clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
    }
    return clockAssertion;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Node(jkind.lustre.Node) HashSet(java.util.HashSet) MNSynchronyElement(com.rockwellcollins.atc.agree.analysis.MNSynchronyElement)

Aggregations

Subcomponent (org.osate.aadl2.Subcomponent)115 ComponentClassifier (org.osate.aadl2.ComponentClassifier)53 Classifier (org.osate.aadl2.Classifier)44 ComponentImplementation (org.osate.aadl2.ComponentImplementation)40 NamedElement (org.osate.aadl2.NamedElement)38 Feature (org.osate.aadl2.Feature)34 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)31 DataSubcomponent (org.osate.aadl2.DataSubcomponent)30 ArrayList (java.util.ArrayList)28 EObject (org.eclipse.emf.ecore.EObject)23 Connection (org.osate.aadl2.Connection)22 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)21 FeatureGroup (org.osate.aadl2.FeatureGroup)18 Property (org.osate.aadl2.Property)18 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)17 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)17 AadlPackage (org.osate.aadl2.AadlPackage)15 ComponentType (org.osate.aadl2.ComponentType)15 FeatureGroupType (org.osate.aadl2.FeatureGroupType)15 List (java.util.List)14