Search in sources :

Example 21 with ComponentType

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

the class VDMInstrumentor method getBlockID.

protected BlockImpl getBlockID(String componentID) {
    BlockImpl blockImpl = null;
    for (ComponentImpl cmpImpl : vdm_model.getComponentImpl()) {
        if (cmpImpl.getBlockImpl() != null) {
            blockImpl = cmpImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (componentID.equalsIgnoreCase(enumType.getId())) {
                    return blockImpl;
                }
            }
        }
    }
    return blockImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 22 with ComponentType

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

the class VDMInstrumentor method retrieve_cmp_impl.

// protected ComponentImpl retrieve_cmp_impl(ComponentType componentType) {
// ComponentImpl componentImpl = null;
// for (ComponentImpl cImpl : vdm_model.getComponentImpl()) {
// ComponentType cmpType = cImpl.getType();
// if (cmpType.getId().equalsIgnoreCase(componentType.getId())) {
// componentImpl = cImpl;
// }
// }
// return componentImpl;
// }
protected ComponentImpl retrieve_cmp_impl(String componentID) {
    ComponentImpl componentImpl = null;
    BlockImpl blockImpl = null;
    for (ComponentImpl cImpl : vdm_model.getComponentImpl()) {
        if (cImpl.getBlockImpl() != null) {
            blockImpl = cImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (componentID.equals(enumType.getId())) {
                    componentImpl = cImpl;
                    return cImpl;
                }
            }
        }
    }
    return componentImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 23 with ComponentType

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

the class VDM2Lustre method visit.

public void visit(Model vdm_model, LustreProgram program) {
    // A) Copying Type Declaration + amend name '_Impl
    for (TypeDeclaration typeDec : vdm_model.getTypeDeclaration()) {
        visit(typeDec, program);
    }
    // Copying over Constant Declarations
    for (ConstantDeclaration constDec : program.getConstantDeclaration()) {
        String constName = constDec.getName();
        constName = constName.replace(".", "_dot_");
        constName = constName.replace("::", "_double_colon_");
        constDec.setName(constName);
        visit(constDec);
    }
    // Event Ports
    for (ComponentType componentType : vdm_model.getComponentType()) {
        // Collect Node with no output
        Port mPort = markPort(componentType);
        if (mPort == null) {
            // Event Ports to Data Ports;
            for (Port port : componentType.getPort()) {
                // Update event_ports
                visit(port, program);
            }
        } else {
            System.out.println("Ignoring Node:" + componentType.getName());
            System.out.println("Ignoring Port:" + mPort.getName());
            this.marked_types.add(componentType);
            this.marked_ports.add(mPort);
        }
    }
    // B) Component Type
    Node cmp_node = null;
    Node impl_node = null;
    String inst_cmp = "(.+)_Inst_.*";
    Pattern inst_pattern = Pattern.compile(inst_cmp);
    for (ComponentType componentType : vdm_model.getComponentType()) {
        boolean is_declared = false;
        if (!this.marked_types.contains(componentType)) {
            for (ComponentImpl componentImpl : vdm_model.getComponentImpl()) {
                if (componentType == componentImpl.getType()) {
                    impl_node = visit(componentType, true);
                    visit(componentImpl, impl_node);
                    is_declared = true;
                    break;
                }
            }
            if (is_declared) {
                cmp_node = visit(componentType, false);
                Matcher m = inst_pattern.matcher(cmp_node.getName());
                if (m.matches() == false) {
                    program.getNodeDeclaration().add(cmp_node);
                }
                program.getNodeDeclaration().add(impl_node);
            } else {
                cmp_node = visit(componentType, false);
                program.getNodeDeclaration().add(cmp_node);
            }
        }
    }
    // Copying over Node Declarations.
    for (Node node_dec : program.getNodeDeclaration()) {
        visit(node_dec, program);
    }
    // Copy over Contract Spec.
    for (Contract contract : program.getContractDeclaration()) {
        visit(contract, program);
    }
}
Also used : Pattern(java.util.regex.Pattern) ComponentType(verdict.vdm.vdm_model.ComponentType) Matcher(java.util.regex.Matcher) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) Node(verdict.vdm.vdm_lustre.Node) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) Contract(verdict.vdm.vdm_lustre.Contract)

Example 24 with ComponentType

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

the class VDM2Lustre method retrieve_block.

protected BlockImpl retrieve_block(ComponentImpl compImpl) {
    BlockImpl blockImpl = null;
    String cmpID = compImpl.getType().getId();
    for (ComponentImpl cmpImpl : vdm_model.getComponentImpl()) {
        if (cmpImpl.getBlockImpl() != null) {
            blockImpl = cmpImpl.getBlockImpl();
            for (ComponentInstance cmpInstance : blockImpl.getSubcomponent()) {
                ComponentImpl impl = cmpInstance.getImplementation();
                ComponentType enumType = null;
                if (impl != null) {
                    enumType = impl.getType();
                } else {
                    enumType = cmpInstance.getSpecification();
                }
                if (cmpID.equals(enumType.getId())) {
                    return blockImpl;
                }
            }
        }
    }
    return blockImpl;
}
Also used : BlockImpl(verdict.vdm.vdm_model.BlockImpl) ComponentType(verdict.vdm.vdm_model.ComponentType) ComponentInstance(verdict.vdm.vdm_model.ComponentInstance) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl)

Example 25 with ComponentType

use of verdict.vdm.vdm_model.ComponentType 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

ComponentType (verdict.vdm.vdm_model.ComponentType)27 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)24 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)21 BlockImpl (verdict.vdm.vdm_model.BlockImpl)16 HashSet (java.util.HashSet)9 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)9 Port (verdict.vdm.vdm_model.Port)9 GenericAttribute (verdict.vdm.vdm_data.GenericAttribute)6 Expression (verdict.vdm.vdm_lustre.Expression)5 Connection (verdict.vdm.vdm_model.Connection)5 ConnectionEnd (verdict.vdm.vdm_model.ConnectionEnd)5 ContractItem (verdict.vdm.vdm_lustre.ContractItem)4 ArrayList (java.util.ArrayList)3 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)3 NodeBody (verdict.vdm.vdm_lustre.NodeBody)3 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)3 PortMode (verdict.vdm.vdm_model.PortMode)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2