Search in sources :

Example 6 with ContractSpec

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

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

the class VerdictLustreListener method exitContractSpec.

/**
 * Extract a contract spec.
 */
@Override
public void exitContractSpec(LustreParser.ContractSpecContext ctx) {
    ctx.spec = new ContractSpec();
    ctx.symbol().forEach(symbol -> ctx.spec.getSymbol().add(symbol.def));
    ctx.assume().forEach(assume -> ctx.spec.getAssume().add(assume.item));
    ctx.guarantee().forEach(guarantee -> ctx.spec.getGuarantee().add(guarantee.item));
    ctx.contractMode().forEach(contractMode -> ctx.spec.getMode().add(contractMode.mode));
    ctx.contractImport().forEach(contractImport -> ctx.spec.getImport().add(contractImport.imprt));
}
Also used : ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 8 with ContractSpec

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

the class VerdictLustreListener method exitNode.

/**
 * Extract a node declaration.
 */
@Override
public void exitNode(LustreParser.NodeContext ctx) {
    Node node = new Node();
    if ("function".equals(ctx.nodeType.getText())) {
        node.setIsFunction(true);
    }
    node.setName(ctx.ID().getText());
    if (ctx.input != null) {
        node.getInputParameter().addAll(ctx.input.nodeParameters);
    }
    if (ctx.output != null) {
        node.getOutputParameter().addAll(ctx.output.nodeParameters);
    }
    if (ctx.nodeBody() != null) {
        node.setBody(ctx.nodeBody().body);
    }
    if (ctx.inlineContract() != null) {
        node.setContract(ctx.inlineContract().spec);
    }
    if (!ctx.importedContract().isEmpty()) {
        if (node.getContract() == null) {
            node.setContract(new ContractSpec());
        }
        final ContractSpec spec = node.getContract();
        ctx.importedContract().forEach(importedContract -> spec.getImport().add(importedContract.imprt));
    }
    LustreProgram program = model.getDataflowCode();
    program.getNodeDeclaration().add(node);
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) Node(verdict.vdm.vdm_lustre.Node) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 9 with ContractSpec

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

the class PrettyPrinter method visit.

// @Override
public void visit(Contract contract) {
    sb.append("contract ").append(contract.getName());
    sb.append(" (").append(NL);
    for (NodeParameter param : contract.getInputParameter()) {
        visit(param);
    }
    sb.append(")").append(NL);
    sb.append("returns (").append(NL);
    for (NodeParameter param : contract.getInputParameter()) {
        visit(param);
    }
    sb.append(");").append(NL);
    // Specifications
    sb.append("let").append(NL);
    for (ContractSpec contractSpec : contract.getSpecification()) {
        visit(contractSpec);
    }
    sb.append("tel");
    sb.append(NL);
}
Also used : NodeParameter(verdict.vdm.vdm_lustre.NodeParameter) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 10 with ContractSpec

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

the class PrettyPrinter method visit.

public void visit(Node node) {
    sb.append("node ");
    // if (node.isIsImported()) {
    sb.append("imported ");
    // }
    sb.append(node.getName());
    sb.append("(");
    sb.append(NL);
    for (NodeParameter param : node.getInputParameter()) {
        visit(param);
    }
    sb.append(")");
    sb.append(NL);
    sb.append("returns (");
    sb.append(NL);
    for (NodeParameter param : node.getOutputParameter()) {
        visit(param);
    }
    sb.append(");");
    sb.append(NL);
    ContractSpec contractSpec = node.getContract();
    if (contractSpec != null) {
        sb.append("(*@contract ");
        visit(contractSpec);
        sb.append("*)");
    // sb.append(NL);
    }
    // if (node.isIsFunction()) {
    NodeBody nodeBody = node.getBody();
    if (nodeBody != null) {
        // sb.append("{");
        sb.append(NL);
        visit(nodeBody);
        // sb.append("}");
        sb.append(NL);
    }
// }
}
Also used : NodeParameter(verdict.vdm.vdm_lustre.NodeParameter) NodeBody(verdict.vdm.vdm_lustre.NodeBody) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Aggregations

ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)10 ContractItem (verdict.vdm.vdm_lustre.ContractItem)4 Expression (verdict.vdm.vdm_lustre.Expression)4 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)4 ArrayList (java.util.ArrayList)3 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)3 Port (verdict.vdm.vdm_model.Port)3 HashSet (java.util.HashSet)2 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)2 Node (verdict.vdm.vdm_lustre.Node)2 NodeBody (verdict.vdm.vdm_lustre.NodeBody)2 NodeParameter (verdict.vdm.vdm_lustre.NodeParameter)2 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)2 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)2 ComponentType (verdict.vdm.vdm_model.ComponentType)2 Connection (verdict.vdm.vdm_model.Connection)2 ConnectionEnd (verdict.vdm.vdm_model.ConnectionEnd)2 HashMap (java.util.HashMap)1 List (java.util.List)1 DataType (verdict.vdm.vdm_data.DataType)1