Search in sources :

Example 1 with TypeDeclaration

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

the class Aadl2Vdm method defineDataType.

/**
 * @author Vidhya Tekken Valapil
 * populate information related to data types in the vdm
 */
private void defineDataType(DataType aadlDataType, Model model, HashSet<String> dataTypeDecl) {
    // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
    String aadlDataTypeName = aadlDataType.getName();
    if (!dataTypeDecl.contains(aadlDataTypeName)) {
        dataTypeDecl.add(aadlDataType.getName());
        // vdm data type declaration
        TypeDeclaration dataTypeVdm = new TypeDeclaration();
        dataTypeVdm.setName(aadlDataType.getName());
        verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
        if (!(aadlDataType.getAllPropertyAssociations().isEmpty())) {
            // if the dataType definition has properties
            EList<PropertyAssociation> properties = aadlDataType.getAllPropertyAssociations();
            Agree2Vdm agree2vdm = new Agree2Vdm();
            boolean setPropInDataType = agree2vdm.updateVDMDatatypeUsingProperties(dtype, properties);
            if (setPropInDataType) {
                dataTypeVdm.setDefinition(dtype);
            }
        }
        // add the typeDeclaration to the model
        model.getTypeDeclaration().add(dataTypeVdm);
    }
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) DataType(org.osate.aadl2.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 2 with TypeDeclaration

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

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

the class Agree2Vdm method getTypeDeclarationsAsHashSet.

private HashSet<String> getTypeDeclarationsAsHashSet(Model model) {
    HashSet<String> dataTypeDecl = new HashSet<String>();
    List<TypeDeclaration> typeDeclarations = model.getTypeDeclaration();
    for (TypeDeclaration typeDeclaration : typeDeclarations) {
        dataTypeDecl.add(typeDeclaration.getName());
    }
    return dataTypeDecl;
}
Also used : TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) HashSet(java.util.HashSet)

Example 4 with TypeDeclaration

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

the class Agree2Vdm method resolveAADLDataType.

private void resolveAADLDataType(org.osate.aadl2.DataType aadlDataType, HashSet<String> dataTypeDecl, Model model) {
    verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
    if (aadlDataType.getName().contentEquals("Float") || aadlDataType.getName().contentEquals("Float_32") || aadlDataType.getName().contentEquals("Float_64")) {
        dtype.setPlainType(verdict.vdm.vdm_data.PlainType.fromValue("real"));
    } else if (aadlDataType.getName().contentEquals("Integer") || aadlDataType.getName().contentEquals("Integer_8") || aadlDataType.getName().contentEquals("Integer_16") || aadlDataType.getName().contentEquals("Integer_32") || aadlDataType.getName().contentEquals("Integer_64") || aadlDataType.getName().contentEquals("Unsigned_8") || aadlDataType.getName().contentEquals("Unsigned_16") || aadlDataType.getName().contentEquals("Unsigned_32") || aadlDataType.getName().contentEquals("Unsigned_64") || aadlDataType.getName().contentEquals("Natural")) {
        dtype.setPlainType(verdict.vdm.vdm_data.PlainType.fromValue("int"));
    } else if (aadlDataType.getName().contentEquals("Boolean")) {
        dtype.setPlainType(verdict.vdm.vdm_data.PlainType.fromValue("bool"));
    } else if (!(aadlDataType.getAllPropertyAssociations().isEmpty())) {
        // if the dataType definition has properties
        EList<PropertyAssociation> properties = aadlDataType.getAllPropertyAssociations();
        updateVDMDatatypeUsingProperties(dtype, properties);
    } else {
        // not float or int or bool or enum
        dtype.setUserDefinedType(aadlDataType.getName());
    // System.out.println("Unresolved AADL Data type value is "+aadlDataType.getName());
    }
    // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
    String aadlDataTypeName = aadlDataType.getName();
    if (!dataTypeDecl.contains(aadlDataTypeName) && (!aadlDataTypeName.equalsIgnoreCase("Float")) && (!aadlDataTypeName.equalsIgnoreCase("Integer")) && (!aadlDataTypeName.equalsIgnoreCase("Boolean"))) {
        dataTypeDecl.add(aadlDataTypeName);
        // vdm data type declaration
        TypeDeclaration dataTypeVdm = new TypeDeclaration();
        dataTypeVdm.setName(aadlDataTypeName);
        dataTypeVdm.setDefinition(dtype);
        // add the typeDeclaration to the model
        model.getTypeDeclaration().add(dataTypeVdm);
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 5 with TypeDeclaration

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

the class VDM2Lustre method defineEventDeclaration.

protected TypeDeclaration defineEventDeclaration(DataType dataType) {
    TypeDeclaration eventTypeDeclaration = new TypeDeclaration();
    if (dataType != null) {
        String user_defined_type = dataType.getUserDefinedType();
        user_defined_type = user_defined_type.replace(".", "_dot_");
        user_defined_type = user_defined_type.replace("::", "_double_colon_");
        boolean implemented_type = typeDeclarations.containsKey(user_defined_type);
        if (implemented_type) {
            TypeDeclaration baseType = typeDeclarations.get(user_defined_type);
            user_defined_type = baseType.getName();
            String definedType = user_defined_type.replace("_dot_", "Event_");
            eventTypeDeclaration.setName(definedType);
            DataType eventDefinition = new DataType();
            RecordType eventRecord = getEventrecord(user_defined_type);
            eventDefinition.setRecordType(eventRecord);
            eventTypeDeclaration.setDefinition(eventDefinition);
            eventTypeDeclaration.setName(definedType);
        }
    } else {
        // None DataType
        String definedType = "EventDataType";
        eventTypeDeclaration.setName(definedType);
        DataType eventDefinition = new DataType();
        RecordType eventRecord = getEventrecord(null);
        eventDefinition.setRecordType(eventRecord);
        eventTypeDeclaration.setDefinition(eventDefinition);
        eventTypeDeclaration.setName(definedType);
    }
    return eventTypeDeclaration;
}
Also used : RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

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