Search in sources :

Example 6 with ConnectionEnd

use of verdict.vdm.vdm_model.ConnectionEnd in project VERDICT by ge-high-assurance.

the class Vdm2Csv method preprocessCompImpls.

private void preprocessCompImpls(List<ComponentImpl> compImpls, String scenario, Map<String, HashSet<String>> propToConnections, Map<String, HashMap<String, String>> connectionAttributesMap, Map<String, String> compToCompImpl, Map<String, HashSet<String>> propToCompInsts, Map<String, HashMap<String, String>> compInstAttributesMap, Map<String, List<ConnectionEnd>> connectionDestToSourceMap) {
    for (ComponentImpl compImpl : compImpls) {
        if (compImpl.getBlockImpl() != null) {
            // process connections
            List<verdict.vdm.vdm_model.Connection> compConnections = compImpl.getBlockImpl().getConnection();
            for (verdict.vdm.vdm_model.Connection compConnection1 : compConnections) {
                // -- Get all property names associated with connections --> need it for headers in connections csv
                // -- Create a property name to set of connections with that property mapping
                List<GenericAttribute> connectionAttributes = compConnection1.getAttribute();
                for (GenericAttribute connectionAttribute : connectionAttributes) {
                    if (propToConnections.containsKey(connectionAttribute.getName())) {
                        String PropName = connectionAttribute.getName();
                        HashSet<String> propToConnection = propToConnections.get(PropName);
                        propToConnection.add(compConnection1.getName());
                        propToConnections.replace(PropName, propToConnection);
                    } else {
                        HashSet<String> propToConnection = new HashSet<>();
                        propToConnection.add(compConnection1.getName());
                        propToConnections.put(connectionAttribute.getName(), propToConnection);
                    }
                }
                // -- Create a map of connections that have a data-port as destination rather than subcomponent.data-port
                // this will be used for populating Missions Table
                verdict.vdm.vdm_model.ConnectionEnd dest = compConnection1.getDestination();
                if (dest.getComponentPort() != null) {
                    String destName = dest.getComponentPort().getName();
                    if (connectionDestToSourceMap.containsKey(destName)) {
                        List<ConnectionEnd> sources = connectionDestToSourceMap.get(destName);
                        sources.add(compConnection1.getSource());
                        connectionDestToSourceMap.replace(destName, sources);
                    } else {
                        List<ConnectionEnd> sources = new ArrayList<>();
                        sources.add(compConnection1.getSource());
                        connectionDestToSourceMap.put(destName, sources);
                    }
                }
                // --- Update connection attributes/properties map
                HashMap<String, String> connAttributes = new HashMap<>();
                List<GenericAttribute> connAttributesList = compConnection1.getAttribute();
                for (GenericAttribute attr : connAttributesList) {
                    connAttributes.put(attr.getName(), attr.getValue().toString());
                }
                connectionAttributesMap.put(compConnection1.getName(), connAttributes);
            }
            // --process component instances
            List<verdict.vdm.vdm_model.ComponentInstance> compInstances = compImpl.getBlockImpl().getSubcomponent();
            for (verdict.vdm.vdm_model.ComponentInstance compInst : compInstances) {
                List<GenericAttribute> compInstAttributesList = compInst.getAttribute();
                HashMap<String, String> compInstAttributes = new HashMap<>();
                for (GenericAttribute attr : compInstAttributesList) {
                    // --update attribute to attribute value mapping for each component attribute
                    compInstAttributes.put(attr.getName(), attr.getValue().toString());
                    // -- Create a property name to set of components with that property mapping
                    if (propToCompInsts.containsKey(attr.getName())) {
                        String PropName = attr.getName();
                        HashSet<String> propToCompInst = propToCompInsts.get(PropName);
                        propToCompInst.add(compInst.getId());
                        propToCompInsts.replace(PropName, propToCompInst);
                    } else {
                        HashSet<String> propToCompInst = new HashSet<>();
                        propToCompInst.add(compInst.getId());
                        propToCompInsts.put(attr.getName(), propToCompInst);
                    }
                }
                // Update component instances to attributes/properties map
                compInstAttributesMap.put(compInst.getId(), compInstAttributes);
            }
            // -- Create component to component-implementation mapping
            compToCompImpl.put(compImpl.getType().getName(), compImpl.getName());
        }
    }
}
Also used : HashMap(java.util.HashMap) GenericAttribute(verdict.vdm.vdm_data.GenericAttribute) ArrayList(java.util.ArrayList) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) HashSet(java.util.HashSet)

Example 7 with ConnectionEnd

use of verdict.vdm.vdm_model.ConnectionEnd in project VERDICT by ge-high-assurance.

the class Instrumentor method get_ports.

private HashSet<String> get_ports(Connection link) {
    HashSet<String> ports = new HashSet<String>();
    ConnectionEnd con_end = link.getSource();
    Port dest_port = con_end.getComponentPort();
    if (dest_port == null) {
        CompInstancePort instance_port = con_end.getSubcomponentPort();
        dest_port = instance_port.getPort();
    }
    ports.add(dest_port.getName());
    con_end = link.getDestination();
    dest_port = con_end.getComponentPort();
    if (dest_port == null) {
        CompInstancePort instance_port = con_end.getSubcomponentPort();
        dest_port = instance_port.getPort();
    }
    ports.add(dest_port.getName());
    return ports;
}
Also used : CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) HashSet(java.util.HashSet)

Example 8 with ConnectionEnd

use of verdict.vdm.vdm_model.ConnectionEnd in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method retrieve_links.

protected boolean retrieve_links(ComponentType component, Connection connection, Port instrumented_port) {
    // Default Block Implementation
    ComponentImpl compImpl = retrieve_cmp_impl(component);
    // R.H.S
    ConnectionEnd src = connection.getSource();
    ComponentInstance src_componentInstance = new ComponentInstance();
    // Source Connection
    Port src_port = src.getComponentPort();
    if (src_port != null) {
        String identifier = compImpl.getId();
        // identifier = identifier.replace(".I", "_I");
        identifier = identifier.replace(".", "_dot_");
        identifier = identifier.replace("::", "_double_colon_");
        src_componentInstance.setId(identifier);
        src_componentInstance.setName(identifier);
        src_componentInstance.setImplementation(compImpl);
    }
    // if (src_port == instrumented_port) {
    CompInstancePort compInstancePort = src.getSubcomponentPort();
    if (compInstancePort != null) {
        src_componentInstance = compInstancePort.getSubcomponent();
        src_port = compInstancePort.getPort();
    }
    if (instrumented_port == src_port) {
        return true;
    }
    return false;
}
Also used : CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 9 with ConnectionEnd

use of verdict.vdm.vdm_model.ConnectionEnd in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method ignoreMarkedLink.

// Ignore Connection or Marked Ports.
private boolean ignoreMarkedLink(Connection con) {
    ConnectionEnd srcConnection = con.getSource();
    ComponentType srcType = null;
    ConnectionEnd destConnection = con.getDestination();
    ComponentType destType = null;
    Port srcPort = srcConnection.getComponentPort();
    if (srcPort == null) {
        CompInstancePort compPort = srcConnection.getSubcomponentPort();
        srcPort = compPort.getPort();
        ComponentInstance srcCompInstance = compPort.getSubcomponent();
        srcType = srcCompInstance.getSpecification();
        if (srcType == null) {
            ComponentImpl compImpl = srcCompInstance.getImplementation();
            srcType = compImpl.getType();
        }
    }
    Port destPort = destConnection.getComponentPort();
    if (destPort == null) {
        CompInstancePort compPort = destConnection.getSubcomponentPort();
        destPort = compPort.getPort();
        ComponentInstance destCompInstance = compPort.getSubcomponent();
        destType = destCompInstance.getSpecification();
        if (destType == null) {
            ComponentImpl compImpl = destCompInstance.getImplementation();
            destType = compImpl.getType();
        }
    }
    if (this.marked_ports.contains(srcPort) || this.marked_ports.contains(destPort)) {
        System.out.println("Ignore Port Connection:" + con.getName());
        return true;
    }
    if (this.marked_types.contains(srcType) || this.marked_types.contains(destType)) {
        System.out.println("Ignore Instance Connection:" + con.getName());
        return true;
    }
    return false;
}
Also used : ComponentType(verdict.vdm.vdm_model.ComponentType) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 10 with ConnectionEnd

use of verdict.vdm.vdm_model.ConnectionEnd in project VERDICT by ge-high-assurance.

the class VDM2Lustre method ignoreConnection.

// Ignore Connection or Marked Ports.
private boolean ignoreConnection(Connection con) {
    ConnectionEnd srcConnection = con.getSource();
    ComponentType srcType = null;
    ConnectionEnd destConnection = con.getDestination();
    ComponentType destType = null;
    Port srcPort = srcConnection.getComponentPort();
    if (srcPort == null) {
        CompInstancePort compPort = srcConnection.getSubcomponentPort();
        // System.out.println(">>>>>>>>" + con.getName());
        srcPort = compPort.getPort();
        ComponentInstance srcCompInstance = compPort.getSubcomponent();
        srcType = srcCompInstance.getSpecification();
        if (srcType == null) {
            ComponentImpl compImpl = srcCompInstance.getImplementation();
            srcType = compImpl.getType();
        }
    }
    Port destPort = destConnection.getComponentPort();
    if (destPort == null) {
        CompInstancePort compPort = destConnection.getSubcomponentPort();
        destPort = compPort.getPort();
        ComponentInstance destCompInstance = compPort.getSubcomponent();
        destType = destCompInstance.getSpecification();
        if (destType == null) {
            ComponentImpl compImpl = destCompInstance.getImplementation();
            destType = compImpl.getType();
        }
    }
    if (this.marked_ports.contains(srcPort) || this.marked_ports.contains(destPort)) {
        System.out.println("Ignore Port Connection:" + con.getName());
        return true;
    }
    if (this.marked_types.contains(srcType) || this.marked_types.contains(destType)) {
        System.out.println("Ignore Instance Connection:" + con.getName());
        return true;
    }
    return false;
}
Also used : ComponentType(verdict.vdm.vdm_model.ComponentType) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ConnectionEnd(verdict.vdm.vdm_model.ConnectionEnd) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Aggregations

ConnectionEnd (verdict.vdm.vdm_model.ConnectionEnd)13 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)12 Port (verdict.vdm.vdm_model.Port)8 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)7 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)7 ComponentType (verdict.vdm.vdm_model.ComponentType)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Expression (verdict.vdm.vdm_lustre.Expression)3 HashMap (java.util.HashMap)2 ContractItem (verdict.vdm.vdm_lustre.ContractItem)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2 IfThenElse (verdict.vdm.vdm_lustre.IfThenElse)2 NodeCall (verdict.vdm.vdm_lustre.NodeCall)2 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)2 NodeEquationLHS (verdict.vdm.vdm_lustre.NodeEquationLHS)2 Connection (verdict.vdm.vdm_model.Connection)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1