Search in sources :

Example 1 with RecordField

use of verdict.vdm.vdm_data.RecordField 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 2 with RecordField

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

the class VerdictLustreListener method exitRecordType.

/**
 * Extract a record type.
 */
@Override
public void exitRecordType(LustreParser.RecordTypeContext ctx) {
    RecordType recordType = new RecordType();
    ctx.field().forEach(field -> {
        field.ID().forEach(id -> {
            RecordField recordField = new RecordField();
            String name = id.getText();
            recordField.setName(name);
            recordField.setType(field.type().dataType);
            recordType.getRecordField().add(recordField);
        });
    });
    ctx.dataType = new DataType();
    ctx.dataType.setRecordType(recordType);
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType)

Example 3 with RecordField

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

the class VDM2Lustre method visit.

// Copying Type Declaration.
public void visit(TypeDeclaration typeDeclaration, LustreProgram program) {
    String identifier = typeDeclaration.getName();
    // Renaming dot[.] in Type Declaration Identifier.
    identifier = identifier.replace(".", "_dot_");
    identifier = identifier.replace("::", "_double_colon_");
    typeDeclaration.setName(identifier);
    DataType data_type = typeDeclaration.getDefinition();
    if (data_type != null) {
        RecordType record_type = data_type.getRecordType();
        if (record_type != null) {
            // identifier = identifier + "_Impl";
            List<RecordField> record_fields = record_type.getRecordField();
            for (RecordField record_field : record_fields) {
                // String identifier = record_field.getName();
                data_type = record_field.getType();
                if (data_type == null) {
                    data_type = defaultType();
                    record_field.setType(data_type);
                }
                String user_defined_type = data_type.getUserDefinedType();
                if (user_defined_type != null) {
                    String updated_defined_type = user_defined_type.replace(".", "_dot_");
                    updated_defined_type = updated_defined_type.replace("::", "_double_colon_");
                    // for (TypeDeclaration type_declaration :
                    // program.getTypeDeclaration()) {
                    // if
                    // (user_defined_type.equals(type_declaration.getName())) {
                    data_type.setUserDefinedType(updated_defined_type);
                // }
                // }
                }
            }
            // Updating TypeName_Impl
            typeDeclaration.setName(identifier);
        }
    }
    typeDeclarations.put(identifier, typeDeclaration);
    program.getTypeDeclaration().add(typeDeclaration);
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType)

Example 4 with RecordField

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

the class VDM2Lustre method getEventrecord.

protected RecordType getEventrecord(String userDefineType) {
    // Define a Record
    RecordType eventRecord = new RecordType();
    // is_present: bool
    RecordField eventField = new RecordField();
    DataType boolType = new DataType();
    boolType.setPlainType(PlainType.BOOL);
    eventField.setName("is_present");
    eventField.setType(boolType);
    eventRecord.getRecordField().add(eventField);
    // value: UserDefined
    if (userDefineType != null) {
        RecordField eventValue = new RecordField();
        DataType valueType = new DataType();
        valueType.setUserDefinedType(userDefineType);
        eventValue.setName("value");
        eventValue.setType(valueType);
        eventRecord.getRecordField().add(eventValue);
    }
    return eventRecord;
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType)

Example 5 with RecordField

use of verdict.vdm.vdm_data.RecordField 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

RecordField (verdict.vdm.vdm_data.RecordField)5 RecordType (verdict.vdm.vdm_data.RecordType)5 DataType (verdict.vdm.vdm_data.DataType)3 DataImplementation (org.osate.aadl2.DataImplementation)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)2 TypeDeclaration (verdict.vdm.vdm_data.TypeDeclaration)2 DataType (org.osate.aadl2.DataType)1