Search in sources :

Example 6 with TypeDeclaration

use of verdict.vdm.vdm_data.TypeDeclaration in project VERDICT by ge-high-assurance.

the class VDM2Lustre method getEventType.

protected DataType getEventType(DataType dataType, LustreProgram lustreProgram) {
    // LustreProgram lustreProgram = vdm_model.getDataflowCode();
    DataType eventType = new DataType();
    TypeDeclaration eventTypeDeclaration = defineEventDeclaration(dataType);
    String eventTypeName = eventTypeDeclaration.getName();
    eventType.setUserDefinedType(eventTypeName);
    if (!typeDeclarations.containsKey(eventTypeName)) {
        typeDeclarations.put(eventTypeName, eventTypeDeclaration);
        lustreProgram.getTypeDeclaration().add(eventTypeDeclaration);
    }
    return eventType;
}
Also used : DataType(verdict.vdm.vdm_data.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 7 with TypeDeclaration

use of verdict.vdm.vdm_data.TypeDeclaration 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 8 with TypeDeclaration

use of verdict.vdm.vdm_data.TypeDeclaration in project VERDICT by ge-high-assurance.

the class VerdictLustreListener method exitOneTypeDecl.

/**
 * Extract a type declaration.
 */
@Override
public void exitOneTypeDecl(LustreParser.OneTypeDeclContext ctx) {
    TypeDeclaration typeDeclaration = new TypeDeclaration();
    if (ctx.type() != null) {
        typeDeclaration.setDefinition(ctx.type().dataType);
    }
    if (ctx.ID() != null) {
        String name = ctx.ID().getText();
        typeDeclaration.setName(name);
        typeDeclarations.put(name, typeDeclaration);
    }
    LustreProgram program = model.getDataflowCode();
    program.getTypeDeclaration().add(typeDeclaration);
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 9 with TypeDeclaration

use of verdict.vdm.vdm_data.TypeDeclaration in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method defineDataImplementationType.

/**
 * @author Vidhya Tekken Valapil
 * populate information related to data implementation types in the vdm
 */
private void defineDataImplementationType(DataImplementation dataImplementation, Model model, HashSet<String> dataTypeDecl) {
    // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
    String dataImplementationName = dataImplementation.getName();
    if (!dataTypeDecl.contains(dataImplementationName)) {
        dataTypeDecl.add(dataImplementationName);
        // vdm data type declaration
        TypeDeclaration dataTypeVdm = new TypeDeclaration();
        dataTypeVdm.setName(dataImplementationName);
        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 = dataImplementation.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;
                    Agree2Vdm agree2vdm = new Agree2Vdm();
                    verdict.vdm.vdm_data.DataType recFieldDtype = agree2vdm.getVdmTypeFromAADLType(aadlDataType);
                    recField.setType(recFieldDtype);
                    resolveAADLDataType(aadlDataType, model, dataTypeDecl);
                    recType.getRecordField().add(recField);
                } else if (dataSubCompType instanceof DataImplementation) {
                    DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
                    verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
                    recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
                    recField.setType(recFieldDtype);
                    defineDataImplementationType(dataSubCompDataImplementation, model, dataTypeDecl);
                    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);
                dataTypeVdm.setDefinition(dtype);
            }
        } else {
            // if the dataType is base type boolean or integer or char or string
            System.out.println("Data implementation type has no subcomponents");
        }
        // 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) DataType(org.osate.aadl2.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) DataType(org.osate.aadl2.DataType)

Aggregations

TypeDeclaration (verdict.vdm.vdm_data.TypeDeclaration)9 RecordType (verdict.vdm.vdm_data.RecordType)3 DataImplementation (org.osate.aadl2.DataImplementation)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)2 DataType (org.osate.aadl2.DataType)2 DataType (verdict.vdm.vdm_data.DataType)2 RecordField (verdict.vdm.vdm_data.RecordField)2 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EList (org.eclipse.emf.common.util.EList)1 PropertyAssociation (org.osate.aadl2.PropertyAssociation)1 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)1 Contract (verdict.vdm.vdm_lustre.Contract)1 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)1 Node (verdict.vdm.vdm_lustre.Node)1 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)1 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)1 ComponentType (verdict.vdm.vdm_model.ComponentType)1