Search in sources :

Example 6 with NodeEquation

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

the class VDM2Lustre method visit.

public void visit(NodeBody nodeBody, LustreProgram program) {
    for (VariableDeclaration var : nodeBody.getVariableDeclaration()) {
        DataType data_type = var.getDataType();
        String user_defined_type = null;
        if (data_type != null) {
            user_defined_type = data_type.getUserDefinedType();
        }
        if (user_defined_type != null) {
            // user_defined_type = user_defined_type + "_Impl";
            boolean implemented_type = typeDeclarations.containsKey(user_defined_type);
            if (implemented_type) {
                data_type.setUserDefinedType(user_defined_type);
            }
        }
    }
    for (NodeEquation node_equation : nodeBody.getEquation()) {
        visit(node_equation);
    }
// Update Expression related to Events
// for (NodeEquation node_equation : nodeBody.getEquation()) {
// visitNodeEq(node_equation);
// }
}
Also used : NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) DataType(verdict.vdm.vdm_data.DataType) VariableDeclaration(verdict.vdm.vdm_lustre.VariableDeclaration)

Example 7 with NodeEquation

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

the class PrettyPrinter method visit.

public void visit(NodeBody nodeBody) {
    sb.append("let");
    sb.append(NL);
    if (nodeBody.getVariableDeclaration().size() > 0) {
        sb.append("var");
        sb.append(NL);
    }
    for (VariableDeclaration var : nodeBody.getVariableDeclaration()) {
        visit(var);
        sb.append(NL);
        sb.append(";");
    }
    for (ConstantDeclaration constant : nodeBody.getConstantDeclaration()) {
        sb.append("const");
        visit(constant);
        sb.append(NL);
        sb.append(";");
    }
    for (Expression expr : nodeBody.getAssertion()) {
        visit(expr);
    }
    for (NodeEquation neq : nodeBody.getEquation()) {
        visit(neq);
    }
    for (NodeProperty property : nodeBody.getProperty()) {
        visit(property);
    }
    sb.append("tel");
}
Also used : NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) Expression(verdict.vdm.vdm_lustre.Expression) NodeProperty(verdict.vdm.vdm_lustre.NodeProperty) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) VariableDeclaration(verdict.vdm.vdm_lustre.VariableDeclaration)

Example 8 with NodeEquation

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

the class Agree2Vdm method addNodeDefToTypeDeclarations.

private void addNodeDefToTypeDeclarations(NodeDef nodeDef, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
    Node vdmNode = new Node();
    // String agreeNodeName = nodeDef.getName();
    String agreeNodeName = nodeDef.getQualifiedName();
    vdmNode.setName(agreeNodeName);
    // SETTING NODE INPUT PARAMETERS
    // get agree node's args and set them as input parameter
    EList<Arg> nodeInpArgs = nodeDef.getArgs();
    for (Arg arg : nodeInpArgs) {
        NodeParameter nodeParameter = new NodeParameter();
        nodeParameter.setName(arg.getName());
        // get types of each arg and define those types if needed -- will be done in getVdmTypeFromAgreeType()
        nodeParameter.setDataType(getVdmTypeFromAgreeType(arg.getType(), dataTypeDecl, model));
        vdmNode.getInputParameter().add(nodeParameter);
    }
    // SETTING NODE OUTPUT PARAMETERS
    EList<Arg> nodeReturnArgs = nodeDef.getRets();
    // get agree node's rets and set them as output parameter
    for (Arg arg : nodeReturnArgs) {
        NodeParameter nodeParameter = new NodeParameter();
        nodeParameter.setName(arg.getName());
        // get types of each arg and define those types if needed -- will be done in getVdmTypeFromAgreeType()
        nodeParameter.setDataType(getVdmTypeFromAgreeType(arg.getType(), dataTypeDecl, model));
        vdmNode.getOutputParameter().add(nodeParameter);
    }
    // SETTING NODE BODY
    NodeBody vdmNodeBody = new NodeBody();
    // get agree node's body
    NodeBodyExpr agreeNodeBody = nodeDef.getNodeBody();
    EList<NodeStmt> agreeNodeStmts = agreeNodeBody.getStmts();
    for (NodeStmt agreeNodeStmt : agreeNodeStmts) {
        if (agreeNodeStmt instanceof NodeEqImpl) {
            NodeEq agreeNodeEq = (NodeEq) agreeNodeStmt;
            // get all LHS identifiers in the statement and add it to the vdm node equation LHS
            NodeEquation vdmNodeEquation = new NodeEquation();
            EList<Arg> agreeLHSArgs = agreeNodeEq.getLhs();
            // this type is just a list of strings
            NodeEquationLHS vdmNodeEquationLHS = new NodeEquationLHS();
            for (Arg agreeLHSArg : agreeLHSArgs) {
                vdmNodeEquationLHS.getIdentifier().add(agreeLHSArg.getName());
            }
            vdmNodeEquation.setLhs(vdmNodeEquationLHS);
            // get the RHS i.e.expr of the agree NodeEq and set it as the vdm node equation's RHS
            vdmNodeEquation.setRhs(getVdmExpressionFromAgreeExpression(agreeNodeEq.getExpr(), dataTypeDecl, nodeDecl, model));
            vdmNodeBody.getEquation().add(vdmNodeEquation);
        } else {
            System.out.println("Node contains non-eq type statements");
        }
    }
    vdmNode.setBody(vdmNodeBody);
    vdmNode.setIsFunction(false);
    vdmNode.setIsImported(false);
    if (!nodeDecl.contains(agreeNodeName)) {
        nodeDecl.add(agreeNodeName);
        LustreProgram lustreProgram = model.getDataflowCode();
        lustreProgram.getNodeDeclaration().add(vdmNode);
        model.setDataflowCode(lustreProgram);
    }
}
Also used : NodeStmt(com.rockwellcollins.atc.agree.agree.NodeStmt) NodeBody(verdict.vdm.vdm_lustre.NodeBody) Node(verdict.vdm.vdm_lustre.Node) NodeEquationLHS(verdict.vdm.vdm_lustre.NodeEquationLHS) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) NodeParameter(verdict.vdm.vdm_lustre.NodeParameter) LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) Arg(com.rockwellcollins.atc.agree.agree.Arg) NodeEqImpl(com.rockwellcollins.atc.agree.agree.impl.NodeEqImpl)

Example 9 with NodeEquation

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

the class Agree2Vdm method translateAssignStatementImpl.

private NodeEquation translateAssignStatementImpl(AssignStatementImpl assignStmtImpl, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
    // get all LHS identifiers in the statement and add it to the vdm node equation LHS
    NodeEquation vdmNodeEquation = new NodeEquation();
    // this type is just a list of strings
    NodeEquationLHS vdmNodeEquationLHS = new NodeEquationLHS();
    vdmNodeEquationLHS.getIdentifier().add(assignStmtImpl.getId().getName());
    vdmNodeEquation.setLhs(vdmNodeEquationLHS);
    // get the RHS i.e.expr of the agree NodeEq and set it as the vdm node equation's RHS
    vdmNodeEquation.setRhs(getVdmExpressionFromAgreeExpression(assignStmtImpl.getExpr(), dataTypeDecl, nodeDecl, model));
    return vdmNodeEquation;
}
Also used : NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) NodeEquationLHS(verdict.vdm.vdm_lustre.NodeEquationLHS)

Aggregations

NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)9 NodeEquationLHS (verdict.vdm.vdm_lustre.NodeEquationLHS)6 Expression (verdict.vdm.vdm_lustre.Expression)5 VariableDeclaration (verdict.vdm.vdm_lustre.VariableDeclaration)5 NodeBody (verdict.vdm.vdm_lustre.NodeBody)3 NodeCall (verdict.vdm.vdm_lustre.NodeCall)3 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)3 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)3 ComponentType (verdict.vdm.vdm_model.ComponentType)3 Port (verdict.vdm.vdm_model.Port)3 Arg (com.rockwellcollins.atc.agree.agree.Arg)2 DataType (verdict.vdm.vdm_data.DataType)2 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)2 ContractItem (verdict.vdm.vdm_lustre.ContractItem)2 IfThenElse (verdict.vdm.vdm_lustre.IfThenElse)2 LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)2 ComponentInstance (verdict.vdm.vdm_model.ComponentInstance)2 ConnectionEnd (verdict.vdm.vdm_model.ConnectionEnd)2 PortMode (verdict.vdm.vdm_model.PortMode)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1