Search in sources :

Example 6 with RecordType

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

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