Search in sources :

Example 6 with SymbolDefinition

use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method dec_var_const.

protected void dec_var_const(Map<String, List<String>> connection_comp_map) {
    Set<String> vars = connection_comp_map.keySet();
    List<SymbolDefinition> vars_dec = new ArrayList<SymbolDefinition>();
    for (String var : vars) {
        // Declaration global variables for instrumented links.
        List<String> connections = connection_comp_map.get(var);
        String id = var.replace("::", "_double_colon_");
        SymbolDefinition var_dec = add_vars_assume(id, connections);
        vars_dec.add(var_dec);
    }
    ComponentImpl compImpl = retrieve_main_cmp_impl();
    // if (compImpl.getBlockImpl() == null) {
    compImpl = retrieve_block_impl(compImpl);
    // }
    ContractSpec contractSpec = compImpl.getType().getContract();
    contractSpec.getSymbol().addAll(vars_dec);
}
Also used : ArrayList(java.util.ArrayList) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Example 7 with SymbolDefinition

use of verdict.vdm.vdm_lustre.SymbolDefinition 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)

Example 8 with SymbolDefinition

use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method add_vars_assume.

protected SymbolDefinition add_vars_assume(String var, List<String> connections) {
    SymbolDefinition var_dec = new SymbolDefinition();
    Expression var_expr = new Expression();
    Stack<Expression> var_stack = new Stack<Expression>();
    for (String con : connections) {
        Expression expr = new Expression();
        expr.setIdentifier(con);
        var_stack.push(expr);
    }
    if (!var_stack.isEmpty()) {
        var_expr = or_expr(var_stack);
    }
    if (var_expr == null) {
        var_expr = new Expression();
        var_expr.setIdentifier(var);
    }
    var_dec.setDefinition(var_expr);
    var_dec.setName(var);
    DataType dataType = new DataType();
    dataType.setPlainType(PlainType.BOOL);
    var_dec.setDataType(dataType);
    return var_dec;
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) DataType(verdict.vdm.vdm_data.DataType) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition) Stack(java.util.Stack)

Example 9 with SymbolDefinition

use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.

the class PrettyPrinter method visit.

public void visit(ContractSpec contractSpec) {
    // Symbols
    for (SymbolDefinition symbolDef : contractSpec.getSymbol()) {
        sb.append(TAB);
        sb.append("var ");
        visit(symbolDef);
        sb.append(";");
        sb.append(NL);
    }
    // Assumuptions
    for (ContractItem contractItem : contractSpec.getAssume()) {
        sb.append(TAB).append("assume ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
    sb.append(NL);
    // Guarantees
    for (ContractItem contractItem : contractSpec.getGuarantee()) {
        sb.append(TAB).append("guarantee ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
    sb.append(NL);
    // Modes
    for (ContractMode contractMode : contractSpec.getMode()) {
        sb.append(TAB).append("mode ");
        sb.append(TAB).append(" (");
        sb.append(TAB).append(NL);
        visit(contractMode);
        sb.append(";");
        sb.append(NL);
    }
    // Imports
    for (ContractImport contractImport : contractSpec.getImport()) {
        sb.append(TAB);
        sb.append("import ");
        visit(contractImport);
        sb.append(";");
        sb.append(NL);
    }
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) ContractImport(verdict.vdm.vdm_lustre.ContractImport) ContractMode(verdict.vdm.vdm_lustre.ContractMode) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Aggregations

SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)9 ContractItem (verdict.vdm.vdm_lustre.ContractItem)5 Expression (verdict.vdm.vdm_lustre.Expression)5 ArrayList (java.util.ArrayList)3 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)3 PropertyExpression (org.osate.aadl2.PropertyExpression)2 ContractImport (verdict.vdm.vdm_lustre.ContractImport)2 ContractMode (verdict.vdm.vdm_lustre.ContractMode)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)1 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)1 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1