use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitUserType.
/**
* Extract an user defined type.
*/
@Override
public void exitUserType(LustreParser.UserTypeContext ctx) {
ctx.dataType = new DataType();
if (ctx.identifier() != null) {
String name = ctx.identifier().getText();
ctx.dataType.setUserDefinedType(name);
}
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitTupleType.
/**
* Extract a tuple type.
*/
@Override
public void exitTupleType(LustreParser.TupleTypeContext ctx) {
TupleType tupleType = new TupleType();
ctx.type().forEach(type -> tupleType.getDataType().add(type.dataType));
ctx.dataType = new DataType();
ctx.dataType.setTupleType(tupleType);
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitRecordType.
/**
* Extract a record type.
*/
@Override
public void exitRecordType(LustreParser.RecordTypeContext ctx) {
RecordType recordType = new RecordType();
ctx.field().forEach(field -> {
field.ID().forEach(id -> {
RecordField recordField = new RecordField();
String name = id.getText();
recordField.setName(name);
recordField.setType(field.type().dataType);
recordType.getRecordField().add(recordField);
});
});
ctx.dataType = new DataType();
ctx.dataType.setRecordType(recordType);
}
use of verdict.vdm.vdm_data.DataType 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;
}
use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
public void visit(ComponentType componentType, NodeBody nodeBody, String componentInstanceID, boolean impl_type) {
// Rename componentType
String cmpName = componentType.getName();
cmpName = cmpName.replace(".", "_dot_");
cmpName = cmpName.replace("::", "_double_colon_");
componentType.setName(cmpName);
// Node Equation
NodeEquation node_eq = new NodeEquation();
// Return variables
NodeEquationLHS eq_lhs = new NodeEquationLHS();
// Node Call
Expression node = new Expression();
NodeCall nodeCall = new NodeCall();
if (impl_type) {
nodeCall.setNodeId(componentType.getName() + "_dot_Impl");
} else {
nodeCall.setNodeId(componentType.getName());
}
// Port
for (Port port : componentType.getPort()) {
// //Event Port Definition
// for (Port port : componentType.getPort()) {
// visit(port);
// }
// MODE
PortMode port_mode = port.getMode();
if (port_mode == PortMode.IN) {
Expression arg = new Expression();
arg.setIdentifier(port.getName());
nodeCall.getArgument().add(arg);
}
if (port_mode == PortMode.OUT) {
VariableDeclaration var = new VariableDeclaration();
// Node Name
String output_name = port.getName();
String var_name = componentInstanceID + "_port_" + output_name;
var.setName(var_name);
// Node DataType
DataType dataType = port.getType();
var.setDataType(dataType);
nodeBody.getVariableDeclaration().add(var);
eq_lhs.getIdentifier().add(var_name);
}
}
// Ignore node call that do not have output
if (eq_lhs.getIdentifier() != null) {
node.setCall(nodeCall);
node_eq.setRhs(node);
node_eq.setLhs(eq_lhs);
nodeBody.getEquation().add(node_eq);
}
}
Aggregations