Search in sources :

Example 11 with DataType

use of org.osate.aadl2.DataType in project VERDICT by ge-high-assurance.

the class Agree2Vdm method getDataTypeName.

private String getDataTypeName(Type type) {
    String dtype = "";
    if (type instanceof PrimType) {
        PrimType primType = (PrimType) type;
        verdict.vdm.vdm_data.PlainType plaintype = verdict.vdm.vdm_data.PlainType.fromValue(primType.getName());
        dtype = plaintype.value();
    } else if (type instanceof DoubleDotRef) {
        DoubleDotRef ddrefType = (DoubleDotRef) type;
        if (ddrefType.getElm() instanceof DataImplementation) {
            // if it is a AADL data implementation definition
            DataImplementation dataImplementation = (DataImplementation) ddrefType.getElm();
            dtype = dataImplementation.getName();
        } else if (ddrefType.getElm() instanceof org.osate.aadl2.DataType) {
            // if it is a AADL data implementation definition
            org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) ddrefType.getElm();
            dtype = aadlDataType.getName();
        } else {
            System.out.println("Unresolved data type " + ddrefType.getElm().getName() + " in doubledotref. Not AADL DataImplementation or DataType type.");
        }
    } else {
        System.out.println("Unresolved type value is " + type.toString());
    }
    return dtype;
}
Also used : DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataImplementation(org.osate.aadl2.DataImplementation)

Example 12 with DataType

use of org.osate.aadl2.DataType in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method createVdmConnectionPort.

/**
 * Creates a new Vdm Port object and returns
 * Populates "name", "mode" and "type"
 * @param portName
 * @param modeString
 * @param dSubCompType
 * @return vdm port
 */
verdict.vdm.vdm_model.Port createVdmConnectionPort(String portName, String modeString, String qualifiedname, DataSubcomponentType dSubCompType, Model model, HashSet<String> dataTypeDecl) {
    // fetching data type information
    verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
    if (dSubCompType instanceof DataTypeImpl) {
        org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
        dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
    } else if (dSubCompType instanceof DataImplementationImpl) {
        org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
        dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
    } else {
        System.out.println("Unresolved/unexpected Named Element.");
    }
    verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
    newPort.setProbe(false);
    newPort.setId(qualifiedname);
    newPort.setName(portName);
    newPort.setMode(convertToVdmPortMode(modeString));
    newPort.setType(dtype);
    return newPort;
}
Also used : DataImplementationImpl(org.osate.aadl2.impl.DataImplementationImpl) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) DataImplementation(org.osate.aadl2.DataImplementation) Port(verdict.vdm.vdm_model.Port) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataType(org.osate.aadl2.DataType) DataType(org.osate.aadl2.DataType)

Example 13 with DataType

use of org.osate.aadl2.DataType 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 14 with DataType

use of org.osate.aadl2.DataType 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 15 with DataType

use of org.osate.aadl2.DataType in project VERDICT by ge-high-assurance.

the class Agree2Vdm method updateVDMDatatypeUsingProperties.

/**
 *  @param vdm dataType,
 * 	@param list of property associations
 *  this method checks if the property indicates if it is an enum definition
 *  and gets information from the properties to define the enum in the VDM
 *  *
 */
public boolean updateVDMDatatypeUsingProperties(verdict.vdm.vdm_data.DataType dtype, EList<PropertyAssociation> properties) {
    if (properties.size() == 2) {
        // check if the property specifies it is enum type
        PropertyAssociation firstProperty = properties.get(0);
        EList<ModalPropertyValue> firstPropertyValues = firstProperty.getOwnedValues();
        if (firstPropertyValues.size() == 1) {
            PropertyExpression ownedval = firstPropertyValues.get(0).getOwnedValue();
            if (ownedval instanceof NamedValueImpl) {
                NamedValue namedVal = (NamedValue) ownedval;
                if (namedVal.getNamedValue() instanceof EnumerationLiteralImpl) {
                    EnumerationLiteral namedValEnumLit = (EnumerationLiteral) namedVal.getNamedValue();
                    if (namedValEnumLit.getName().equalsIgnoreCase("Enum")) {
                        EnumType vdmEnumType = new EnumType();
                        // Fetch the enum values which are defined as the next property
                        PropertyAssociation secondProperty = properties.get(1);
                        EList<ModalPropertyValue> secondPropertyValues = secondProperty.getOwnedValues();
                        if (firstPropertyValues.size() == 1) {
                            PropertyExpression secPropValue = secondPropertyValues.get(0).getOwnedValue();
                            // enum should have multiple values so check if a list of values are defined
                            if (secPropValue instanceof ListValueImpl) {
                                ListValueImpl listValueImpl = (ListValueImpl) secPropValue;
                                EList<PropertyExpression> listOfValues = listValueImpl.getOwnedListElements();
                                for (PropertyExpression enumvalue : listOfValues) {
                                    if (enumvalue instanceof StringLiteralImpl) {
                                        StringLiteralImpl stringEnumVal = (StringLiteralImpl) enumvalue;
                                        vdmEnumType.getEnumValue().add(stringEnumVal.getValue());
                                    } else {
                                        System.out.println("Unexpected non-string value for data type of type enum.");
                                    }
                                }
                                dtype.setEnumType(vdmEnumType);
                                return true;
                            } else {
                                System.out.println("The second property of the data definition is not of ListValueImp type");
                            }
                        } else {
                            System.out.println("Unresolved data property. The first property of the data definition has no values or multiple values.");
                        }
                    } else {
                        System.out.println("Unresolved data property value. Property's owned value's named value does not contain Enum");
                    }
                } else {
                    System.out.println("Unresolved data property value. Property's owned value's named value is not EnumerationLiteralImpl type.");
                }
            } else {
                System.out.println("Unresolved data property value. Property's owned value is not NamedValueImpl type.");
            }
        } else {
            System.out.println("Unresolved data property with no values or multiple values.");
        }
    } else {
        System.out.println("Unresolved data property. Data definition has 0 or more than 2 properties associated with it");
    }
    return false;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteralImpl(org.osate.aadl2.impl.StringLiteralImpl) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EnumType(verdict.vdm.vdm_data.EnumType) NamedValueImpl(org.osate.aadl2.impl.NamedValueImpl) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) EnumerationLiteralImpl(org.osate.aadl2.impl.EnumerationLiteralImpl)

Aggregations

DataType (com.serotonin.m2m2.DataType)14 DataImplementation (org.osate.aadl2.DataImplementation)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6 Array (ucar.ma2.Array)6 File (java.io.File)5 IOException (java.io.IOException)5 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)5 PropertyAssociation (org.osate.aadl2.PropertyAssociation)5 Dimension (ucar.nc2.Dimension)5 DataPort (org.osate.aadl2.DataPort)4 EventDataPort (org.osate.aadl2.EventDataPort)4 EventPort (org.osate.aadl2.EventPort)4 DataTypeImpl (org.osate.aadl2.impl.DataTypeImpl)4 ArrayFloat (ucar.ma2.ArrayFloat)4