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;
}
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;
}
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);
}
}
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);
}
}
}
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;
}
Aggregations