Search in sources :

Example 6 with ContractItem

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

the class VerdictLustreListener method exitGuarantee.

/**
 * Extract a guarantee contract item.
 */
@Override
public void exitGuarantee(LustreParser.GuaranteeContext ctx) {
    ctx.item = new ContractItem();
    if (ctx.STRING() != null) {
        ctx.item.setName(ctx.STRING().getText());
    }
    ctx.item.setExpression(ctx.expr().expression);
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem)

Example 7 with ContractItem

use of verdict.vdm.vdm_lustre.ContractItem 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 8 with ContractItem

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

the class VDM2Lustre method visit.

// 1) Node signature +/- contract
// a) Imported Node (Contract, no Implementation)
// b) Node Impl
// c) Node Impl + contract
// d) @TODO: no Contract, no Implementation -- (*@contract gurantee true*)
public Node visit(ComponentType componentType, boolean is_implemented) {
    Node node = new Node();
    String identifier = componentType.getName();
    // Replace dot identifier to support lustre naming compliance
    identifier = identifier.replace(".", "_dot_");
    identifier = identifier.replace("::", "_double_colon_");
    if (is_implemented) {
        identifier += "_dot_Impl";
    } else {
        // Imported Node
        node.setIsImported(true);
    // System.out.println("Imported Nodes:" +identifier );
    }
    node.setName(identifier);
    for (Port port : componentType.getPort()) {
        if (port.isEvent() != null && port.isEvent()) {
            this.eventDeclarations.put(port.getName(), port.getType());
        }
        visit(port, node);
    }
    // + Contract (Optional)
    ContractSpec contractSpec = componentType.getContract();
    if (is_implemented == false && contractSpec == null) {
        // Rename output renaming to avoid Duplicate.
        // List<NodeParameter> node_parameters = node.getOutputParameter();
        // for (NodeParameter instrumented_param : node_parameters) {
        // String param_identifier = instrumented_param.getName();
        // instrumented_param.setName(param_identifier + "_intrumented");
        // }
        ContractItem true_guarantee_item = new ContractItem();
        Expression true_expr = new Expression();
        Boolean true_lit = Boolean.TRUE;
        true_expr.setBoolLiteral(true_lit);
        true_guarantee_item.setExpression(true_expr);
        contractSpec = new ContractSpec();
        contractSpec.getGuarantee().add(true_guarantee_item);
        componentType.setContract(contractSpec);
    }
    if (contractSpec != null) {
        visit(contractSpec);
        if (contractSpec.getGuarantee().size() != 0) {
            node.setContract(contractSpec);
            this.eventDeclarations.clear();
        }
    }
    return node;
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) Expression(verdict.vdm.vdm_lustre.Expression) Node(verdict.vdm.vdm_lustre.Node) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 9 with ContractItem

use of verdict.vdm.vdm_lustre.ContractItem 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 10 with ContractItem

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

the class VerdictLustreListener method exitAssume.

/**
 * Extract an assume contract item.
 */
@Override
public void exitAssume(LustreParser.AssumeContext ctx) {
    ctx.item = new ContractItem();
    ctx.item.setExpression(ctx.expr().expression);
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem)

Aggregations

ContractItem (verdict.vdm.vdm_lustre.ContractItem)15 Expression (verdict.vdm.vdm_lustre.Expression)9 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)5 ArrayList (java.util.ArrayList)4 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)4 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)4 ComponentType (verdict.vdm.vdm_model.ComponentType)4 PropertyExpression (org.osate.aadl2.PropertyExpression)3 ContractMode (verdict.vdm.vdm_lustre.ContractMode)3 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)3 Port (verdict.vdm.vdm_model.Port)3 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)2 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)2 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)2 Expr (com.rockwellcollins.atc.agree.agree.Expr)2 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)2 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2