Search in sources :

Example 6 with DataType

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);
    }
}
Also used : DataType(verdict.vdm.vdm_data.DataType)

Example 7 with DataType

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);
}
Also used : TupleType(verdict.vdm.vdm_data.TupleType) DataType(verdict.vdm.vdm_data.DataType)

Example 8 with DataType

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);
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType)

Example 9 with DataType

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;
}
Also used : RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 10 with DataType

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);
    }
}
Also used : NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) NodeCall(verdict.vdm.vdm_lustre.NodeCall) Expression(verdict.vdm.vdm_lustre.Expression) PortMode(verdict.vdm.vdm_model.PortMode) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) NodeEquationLHS(verdict.vdm.vdm_lustre.NodeEquationLHS) DataType(verdict.vdm.vdm_data.DataType) VariableDeclaration(verdict.vdm.vdm_lustre.VariableDeclaration)

Aggregations

DataType (verdict.vdm.vdm_data.DataType)26 Expression (verdict.vdm.vdm_lustre.Expression)6 RecordType (verdict.vdm.vdm_data.RecordType)4 RecordField (verdict.vdm.vdm_data.RecordField)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 TypeDeclaration (verdict.vdm.vdm_data.TypeDeclaration)2 ContractItem (verdict.vdm.vdm_lustre.ContractItem)2 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)2 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)2 VariableDeclaration (verdict.vdm.vdm_lustre.VariableDeclaration)2 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)2 Port (verdict.vdm.vdm_model.Port)2 PortMode (verdict.vdm.vdm_model.PortMode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Stack (java.util.Stack)1 ArrayType (verdict.vdm.vdm_data.ArrayType)1