Search in sources :

Example 11 with DataType

use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.

the class VDM2Lustre method defaultType.

private DataType defaultType() {
    DataType dataType = new DataType();
    dataType.setPlainType(PlainType.INT);
    return dataType;
}
Also used : DataType(verdict.vdm.vdm_data.DataType)

Example 12 with DataType

use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

public void visit(ContractSpec contractSpec) {
    for (SymbolDefinition symbol : contractSpec.getSymbol()) {
        DataType data_type = symbol.getDataType();
        String user_defined_type = data_type.getUserDefinedType();
        if (user_defined_type != null) {
            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) {
                data_type.setUserDefinedType(user_defined_type);
            }
        }
        Expression expr = symbol.getDefinition();
        expr = visitExpression(expr);
        symbol.setDefinition(expr);
        recordLiteral(expr);
    }
    String mbas_fml = "((.+):(.+):(.+))|((.+):Formula$)";
    Pattern fml_pattern = Pattern.compile(mbas_fml);
    List<ContractItem> mbas_guarantee = new ArrayList<ContractItem>();
    // guarantee
    for (ContractItem contractItem : contractSpec.getGuarantee()) {
        if (contractItem.getName() != null) {
            Matcher m = fml_pattern.matcher(contractItem.getName());
            if (m.find()) {
                mbas_guarantee.add(contractItem);
            } else {
                // Normal Formula
                visit(contractItem);
            }
        } else {
            visit(contractItem);
        }
    }
    // remove MBAS guarantee
    contractSpec.getGuarantee().removeAll(mbas_guarantee);
}
Also used : Pattern(java.util.regex.Pattern) Expression(verdict.vdm.vdm_lustre.Expression) ContractItem(verdict.vdm.vdm_lustre.ContractItem) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DataType(verdict.vdm.vdm_data.DataType) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Example 13 with DataType

use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

public void visit(ConstantDeclaration constantDeclaration) {
    // String identifier = constantDeclaration.getName();
    DataType data_type = constantDeclaration.getDataType();
    String user_defined_type = data_type.getUserDefinedType();
    if (user_defined_type != null) {
        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) {
            data_type.setUserDefinedType(user_defined_type);
        }
        Expression expr = constantDeclaration.getDefinition();
        recordLiteral(expr);
    }
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) DataType(verdict.vdm.vdm_data.DataType)

Example 14 with DataType

use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

// Copying Type Declaration.
public void visit(TypeDeclaration typeDeclaration, LustreProgram program) {
    String identifier = typeDeclaration.getName();
    // Renaming dot[.] in Type Declaration Identifier.
    identifier = identifier.replace(".", "_dot_");
    identifier = identifier.replace("::", "_double_colon_");
    typeDeclaration.setName(identifier);
    DataType data_type = typeDeclaration.getDefinition();
    if (data_type != null) {
        RecordType record_type = data_type.getRecordType();
        if (record_type != null) {
            // identifier = identifier + "_Impl";
            List<RecordField> record_fields = record_type.getRecordField();
            for (RecordField record_field : record_fields) {
                // String identifier = record_field.getName();
                data_type = record_field.getType();
                if (data_type == null) {
                    data_type = defaultType();
                    record_field.setType(data_type);
                }
                String user_defined_type = data_type.getUserDefinedType();
                if (user_defined_type != null) {
                    String updated_defined_type = user_defined_type.replace(".", "_dot_");
                    updated_defined_type = updated_defined_type.replace("::", "_double_colon_");
                    // for (TypeDeclaration type_declaration :
                    // program.getTypeDeclaration()) {
                    // if
                    // (user_defined_type.equals(type_declaration.getName())) {
                    data_type.setUserDefinedType(updated_defined_type);
                // }
                // }
                }
            }
            // Updating TypeName_Impl
            typeDeclaration.setName(identifier);
        }
    }
    typeDeclarations.put(identifier, typeDeclaration);
    program.getTypeDeclaration().add(typeDeclaration);
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) RecordType(verdict.vdm.vdm_data.RecordType) DataType(verdict.vdm.vdm_data.DataType)

Example 15 with DataType

use of verdict.vdm.vdm_data.DataType in project VERDICT by ge-high-assurance.

the class PrettyPrinter method visit.

public void visit(ConstantDeclaration constant) {
    String var_name = constant.getName();
    sb.append(var_name);
    sb.append(" : ");
    DataType dataType = constant.getDataType();
    sb.append(dataType);
}
Also used : DataType(verdict.vdm.vdm_data.DataType)

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