Search in sources :

Example 1 with Contract

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

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

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

the class VerdictLustreListener method exitContractNode.

/**
 * Extract a contract.
 */
@Override
public void exitContractNode(LustreParser.ContractNodeContext ctx) {
    Contract contract = new Contract();
    contract.setName(ctx.ID().getText());
    if (ctx.input != null) {
        contract.getInputParameter().addAll(ctx.input.nodeParameters);
    }
    if (ctx.output != null) {
        contract.getOutputParameter().addAll(ctx.output.nodeParameters);
    }
    contract.getSpecification().add(ctx.contractSpec().spec);
    LustreProgram program = model.getDataflowCode();
    program.getContractDeclaration().add(contract);
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) Contract(verdict.vdm.vdm_lustre.Contract)

Aggregations

Contract (verdict.vdm.vdm_lustre.Contract)3 Node (verdict.vdm.vdm_lustre.Node)2 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 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)1 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)1 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)1 ComponentType (verdict.vdm.vdm_model.ComponentType)1 Port (verdict.vdm.vdm_model.Port)1