Search in sources :

Example 1 with ModeBuilder

use of edu.uiowa.cs.clc.kind2.lustre.ModeBuilder in project VERDICT by ge-high-assurance.

the class VDMLustre2Kind2 method visit.

/**
 * Translate VDM model contract specification to Kind 2 Lustre contract body.
 *
 * @param modelSpec the VDM model contract spec
 * @return the Kind 2 Lustre contract body builder
 */
private static ContractBodyBuilder visit(ContractSpec modelSpec) {
    ContractBodyBuilder cbb = new ContractBodyBuilder();
    for (ContractImport contractImport : modelSpec.getImport()) {
        cbb.importContract(contractImport.getContractId(), contractImport.getInputArgument().stream().map(input -> (IdExpr) visit(input)).collect(Collectors.toList()), contractImport.getOutputArgument().stream().map(output -> (IdExpr) visit(output)).collect(Collectors.toList()));
    }
    for (SymbolDefinition symbol : modelSpec.getSymbol()) {
        if (symbol.isIsConstant() != null && symbol.isIsConstant()) {
            if (symbol.getDataType() != null) {
                if (symbol.getDefinition() != null) {
                    cbb.createConstant(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
                } else {
                    cbb.createConstant(symbol.getName(), visit(symbol.getDataType()));
                }
            } else {
                cbb.createConstant(symbol.getName(), visit(symbol.getDefinition()));
            }
        } else {
            cbb.createVarDef(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
        }
    }
    for (ContractItem assumption : modelSpec.getWeaklyassume()) {
        cbb.weaklyAssume(assumption.getName(), visit(assumption.getExpression()));
    }
    for (ContractItem assumption : modelSpec.getAssume()) {
        cbb.assume(assumption.getName(), visit(assumption.getExpression()));
    }
    for (ContractItem guarantee : modelSpec.getGuarantee()) {
        cbb.guarantee(guarantee.getName(), visit(guarantee.getExpression()));
    }
    for (ContractMode mode : modelSpec.getMode()) {
        ModeBuilder mb = new ModeBuilder(mode.getName());
        for (ContractItem require : mode.getRequire()) {
            mb.require(require.getName(), visit(require.getExpression()));
        }
        for (ContractItem ensure : mode.getEnsure()) {
            mb.ensure(ensure.getName(), visit(ensure.getExpression()));
        }
        cbb.addMode(mb);
    }
    return cbb;
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) ContractImport(verdict.vdm.vdm_lustre.ContractImport) ContractMode(verdict.vdm.vdm_lustre.ContractMode) ModeBuilder(edu.uiowa.cs.clc.kind2.lustre.ModeBuilder) ContractBodyBuilder(edu.uiowa.cs.clc.kind2.lustre.ContractBodyBuilder) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Aggregations

ContractBodyBuilder (edu.uiowa.cs.clc.kind2.lustre.ContractBodyBuilder)1 ModeBuilder (edu.uiowa.cs.clc.kind2.lustre.ModeBuilder)1 ContractImport (verdict.vdm.vdm_lustre.ContractImport)1 ContractItem (verdict.vdm.vdm_lustre.ContractItem)1 ContractMode (verdict.vdm.vdm_lustre.ContractMode)1 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)1