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