Search in sources :

Example 1 with Node

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

the class PrettyPrinter method visit.

// @Override
public void visit(LustreProgram program) {
    // ContractDeclarataions
    for (Contract contract : program.getContractDeclaration()) {
        visit(contract);
        sb.append(NL);
    }
    sb.append(NL);
    for (Node node : program.getNodeDeclaration()) {
        if (node != null) {
            visit(node);
            sb.append(NL);
        }
    }
// for (LustreNode node : cNodes) {
// node.accept(this);
// sb.append(NL).append(NL);
// }
}
Also used : Node(verdict.vdm.vdm_lustre.Node) Contract(verdict.vdm.vdm_lustre.Contract)

Example 2 with Node

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

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

the class VDM2Lustre method visit.

public void visit(Model vdm_model, LustreProgram program) {
    // A) Copying Type Declaration + amend name '_Impl
    for (TypeDeclaration typeDec : vdm_model.getTypeDeclaration()) {
        visit(typeDec, program);
    }
    // Copying over Constant Declarations
    for (ConstantDeclaration constDec : program.getConstantDeclaration()) {
        String constName = constDec.getName();
        constName = constName.replace(".", "_dot_");
        constName = constName.replace("::", "_double_colon_");
        constDec.setName(constName);
        visit(constDec);
    }
    // Event Ports
    for (ComponentType componentType : vdm_model.getComponentType()) {
        // Collect Node with no output
        Port mPort = markPort(componentType);
        if (mPort == null) {
            // Event Ports to Data Ports;
            for (Port port : componentType.getPort()) {
                // Update event_ports
                visit(port, program);
            }
        } else {
            System.out.println("Ignoring Node:" + componentType.getName());
            System.out.println("Ignoring Port:" + mPort.getName());
            this.marked_types.add(componentType);
            this.marked_ports.add(mPort);
        }
    }
    // B) Component Type
    Node cmp_node = null;
    Node impl_node = null;
    String inst_cmp = "(.+)_Inst_.*";
    Pattern inst_pattern = Pattern.compile(inst_cmp);
    for (ComponentType componentType : vdm_model.getComponentType()) {
        boolean is_declared = false;
        if (!this.marked_types.contains(componentType)) {
            for (ComponentImpl componentImpl : vdm_model.getComponentImpl()) {
                if (componentType == componentImpl.getType()) {
                    impl_node = visit(componentType, true);
                    visit(componentImpl, impl_node);
                    is_declared = true;
                    break;
                }
            }
            if (is_declared) {
                cmp_node = visit(componentType, false);
                Matcher m = inst_pattern.matcher(cmp_node.getName());
                if (m.matches() == false) {
                    program.getNodeDeclaration().add(cmp_node);
                }
                program.getNodeDeclaration().add(impl_node);
            } else {
                cmp_node = visit(componentType, false);
                program.getNodeDeclaration().add(cmp_node);
            }
        }
    }
    // Copying over Node Declarations.
    for (Node node_dec : program.getNodeDeclaration()) {
        visit(node_dec, program);
    }
    // Copy over Contract Spec.
    for (Contract contract : program.getContractDeclaration()) {
        visit(contract, program);
    }
}
Also used : Pattern(java.util.regex.Pattern) ComponentType(verdict.vdm.vdm_model.ComponentType) Matcher(java.util.regex.Matcher) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) Node(verdict.vdm.vdm_lustre.Node) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) Contract(verdict.vdm.vdm_lustre.Contract)

Example 4 with Node

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

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

the class VerdictLustreListener method exitImportedNode.

/**
 * Extract an imported node declaration.
 */
@Override
public void exitImportedNode(LustreParser.ImportedNodeContext ctx) {
    Node node = new Node();
    node.setIsImported(true);
    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.inlineContract() != null) {
        node.setContract(ctx.inlineContract().spec);
    }
    LustreProgram program = model.getDataflowCode();
    program.getNodeDeclaration().add(node);
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) Node(verdict.vdm.vdm_lustre.Node)

Aggregations

Node (verdict.vdm.vdm_lustre.Node)6 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)3 Contract (verdict.vdm.vdm_lustre.Contract)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)2 Port (verdict.vdm.vdm_model.Port)2 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)1 NodeEq (com.rockwellcollins.atc.agree.agree.NodeEq)1 NodeStmt (com.rockwellcollins.atc.agree.agree.NodeStmt)1 NodeEqImpl (com.rockwellcollins.atc.agree.agree.impl.NodeEqImpl)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 TypeDeclaration (verdict.vdm.vdm_data.TypeDeclaration)1 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)1 ContractItem (verdict.vdm.vdm_lustre.ContractItem)1 Expression (verdict.vdm.vdm_lustre.Expression)1 NodeBody (verdict.vdm.vdm_lustre.NodeBody)1 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)1 NodeEquationLHS (verdict.vdm.vdm_lustre.NodeEquationLHS)1