Search in sources :

Example 6 with LustreProgram

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

the class VerdictLustreListener method exitOneConstDecl.

/**
 * Extract a constant declaration.
 */
@Override
public void exitOneConstDecl(LustreParser.OneConstDeclContext ctx) {
    LustreProgram program = model.getDataflowCode();
    ctx.ID().forEach(id -> {
        ConstantDeclaration constantDeclaration = new ConstantDeclaration();
        if (ctx.type() != null) {
            constantDeclaration.setDataType(ctx.type().dataType);
        }
        if (ctx.expr() != null) {
            constantDeclaration.setDefinition(ctx.expr().expression);
        }
        String name = id.getText();
        constantDeclaration.setName(name);
        constantDeclarations.put(name, constantDeclaration);
        program.getConstantDeclaration().add(constantDeclaration);
    });
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration)

Example 7 with LustreProgram

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

the class VerdictLustreListener method exitOneTypeDecl.

/**
 * Extract a type declaration.
 */
@Override
public void exitOneTypeDecl(LustreParser.OneTypeDeclContext ctx) {
    TypeDeclaration typeDeclaration = new TypeDeclaration();
    if (ctx.type() != null) {
        typeDeclaration.setDefinition(ctx.type().dataType);
    }
    if (ctx.ID() != null) {
        String name = ctx.ID().getText();
        typeDeclaration.setName(name);
        typeDeclarations.put(name, typeDeclaration);
    }
    LustreProgram program = model.getDataflowCode();
    program.getTypeDeclaration().add(typeDeclaration);
}
Also used : LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 8 with LustreProgram

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

Example 9 with LustreProgram

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

Example 10 with LustreProgram

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

Aggregations

LustreProgram (verdict.vdm.vdm_lustre.LustreProgram)10 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)4 Expression (verdict.vdm.vdm_lustre.Expression)3 Node (verdict.vdm.vdm_lustre.Node)3 ComponentType (verdict.vdm.vdm_model.ComponentType)3 Arg (com.rockwellcollins.atc.agree.agree.Arg)2 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)2 PropertyExpression (org.osate.aadl2.PropertyExpression)2 SystemType (org.osate.aadl2.SystemType)2 ContractItem (verdict.vdm.vdm_lustre.ContractItem)2 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)1 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1