Search in sources :

Example 1 with AssumeStatement

use of com.rockwellcollins.atc.agree.agree.AssumeStatement in project VERDICT by ge-high-assurance.

the class Agree2Vdm method translateAgreeAnnex.

private Model translateAgreeAnnex(List<SystemType> systemTypes, List<SystemImplementation> systemImpls, Model model, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl) {
    LustreProgram lustreProgram = new LustreProgram();
    // Initializing the lustre program in the VDM
    model.setDataflowCode(lustreProgram);
    // System.out.println("Processing "+systemTypes.size()+" SystemTypes for agree annexes");
    for (SystemType sysType : systemTypes) {
        // unpacking sysType
        for (AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("agree")) {
                // annex is of type DefaultAnnexSubclause
                DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
                // AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
                AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
                // populating agree contracts in the vdm component type -- SHOULD ADD THIS CODE TO AADL2VDM
                verdict.vdm.vdm_lustre.ContractSpec contractSpec = new verdict.vdm.vdm_lustre.ContractSpec();
                EList<EObject> annexContents = agreeAnnex.eContents();
                if (annexContents.isEmpty()) {
                    System.out.println("Empty Agree Annex.");
                }
                for (EObject clause : annexContents) {
                    // mapping to AgreeContractclause
                    AgreeContract agreeContract = (AgreeContract) clause;
                    // getting specStatements
                    EList<SpecStatement> specStatements = agreeContract.getSpecs();
                    for (SpecStatement specStatement : specStatements) {
                        if (specStatement instanceof EqStatement) {
                            EqStatement eqStmt = (EqStatement) specStatement;
                            // translate EqStatement in Agree to SymbolDefinition in vdm
                            SymbolDefinition symbDef = translateEqStatement(eqStmt, model, dataTypeDecl, nodeDecl);
                            // Add agree variable/symbol definition to the contractSpec in vdm
                            contractSpec.getSymbol().add(symbDef);
                        } else if (specStatement instanceof GuaranteeStatement) {
                            GuaranteeStatement guaranteeStmt = (GuaranteeStatement) specStatement;
                            ContractItem contractItem = translateGuaranteeStatement(guaranteeStmt, dataTypeDecl, nodeDecl, model);
                            contractSpec.getGuarantee().add(contractItem);
                        } else if (specStatement instanceof AssumeStatement) {
                            AssumeStatement assumeStmt = (AssumeStatement) specStatement;
                            ContractItem contractItem = translateAssumeStatement(assumeStmt, dataTypeDecl, nodeDecl, model);
                            contractSpec.getAssume().add(contractItem);
                        } else {
                            if (!(specStatement instanceof ConstStatementImpl)) {
                                System.out.println("Element not recognizable" + clause.eContents().toString());
                            }
                        }
                    }
                }
                if (contractSpec != null) {
                    List<ComponentType> vdmComponentTypes = model.getComponentType();
                    for (ComponentType vdmComponentType : vdmComponentTypes) {
                        // populating agree contract details in the corresponding componentType instance in vdm
                        if (vdmComponentType.getName().equalsIgnoreCase(sysType.getName())) {
                            vdmComponentType.setContract(contractSpec);
                        }
                    }
                // populating agree contract details in the componentType instance in vdm
                // packComponent.setContract(contractSpec);
                }
            }
        }
    // End of unpacking sysType
    }
    for (SystemImplementation sysImpl : systemImpls) {
        // unpacking sysType
        for (AnnexSubclause annex : sysImpl.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("agree")) {
                // annex is of type DefaultAnnexSubclause
                DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
                // AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
                AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
                // populating agree contracts in the vdm node body for component implementation type
                verdict.vdm.vdm_lustre.NodeBody nodeBody = new verdict.vdm.vdm_lustre.NodeBody();
                ;
                EList<EObject> annexContents = agreeAnnex.eContents();
                if (annexContents.isEmpty()) {
                    System.out.println("Empty Agree Annex.");
                }
                for (EObject clause : annexContents) {
                    // mapping to AgreeContractclause
                    AgreeContract agreeContract = (AgreeContract) clause;
                    // getting specStatements
                    EList<SpecStatement> specStatements = agreeContract.getSpecs();
                    for (SpecStatement specStatement : specStatements) {
                        if (specStatement instanceof ConstStatementImpl) {
                            ConstStatementImpl constStmtImpl = (ConstStatementImpl) specStatement;
                            ConstantDeclaration constDecl = translateConstStatementImpl(constStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getConstantDeclaration().add(constDecl);
                        } else if (specStatement instanceof EqStatementImpl) {
                            EqStatementImpl eqStmtImpl = (EqStatementImpl) specStatement;
                            nodeBody = translateEqStatementImpl(eqStmtImpl, dataTypeDecl, nodeDecl, model, nodeBody);
                        } else if (specStatement instanceof AssignStatementImpl) {
                            AssignStatementImpl assignStmtImpl = (AssignStatementImpl) specStatement;
                            NodeEquation nodeEquation = translateAssignStatementImpl(assignStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getEquation().add(nodeEquation);
                        } else if (specStatement instanceof AssertStatementImpl) {
                            AssertStatementImpl assertStmtImpl = (AssertStatementImpl) specStatement;
                            Expression assertion = translateAssertStatementImpl(assertStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getAssertion().add(assertion);
                        } else {
                            System.out.println("Element not recognizable" + clause.eContents().toString());
                        }
                    }
                }
                List<ComponentImpl> vdmComponentImpls = model.getComponentImpl();
                for (ComponentImpl vdmComponentImpl : vdmComponentImpls) {
                    // populating agree contract details in the corresponding componentImplType instance in vdm
                    if (vdmComponentImpl.getName().equalsIgnoreCase(sysImpl.getName())) {
                        vdmComponentImpl.setDataflowImpl(nodeBody);
                    }
                }
            }
        }
    }
    return model;
}
Also used : ConstStatementImpl(com.rockwellcollins.atc.agree.agree.impl.ConstStatementImpl) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) SystemType(org.osate.aadl2.SystemType) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ContractItem(verdict.vdm.vdm_lustre.ContractItem) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AssertStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssertStatementImpl) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition) NodeBody(verdict.vdm.vdm_lustre.NodeBody) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) EqStatementImpl(com.rockwellcollins.atc.agree.agree.impl.EqStatementImpl) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) ComponentType(verdict.vdm.vdm_model.ComponentType) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) NodeBody(verdict.vdm.vdm_lustre.NodeBody) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) PropertyExpression(org.osate.aadl2.PropertyExpression) Expression(verdict.vdm.vdm_lustre.Expression) LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) SystemImplementation(org.osate.aadl2.SystemImplementation) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) AssignStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssignStatementImpl) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause)

Example 2 with AssumeStatement

use of com.rockwellcollins.atc.agree.agree.AssumeStatement in project AGREE by loonwerks.

the class TestCaseGeneratorMenuListener method addResultsLinkingMenu.

private void addResultsLinkingMenu(IMenuManager manager, AnalysisResult result) {
    if (result instanceof PropertyResult) {
        PropertyResult pr = (PropertyResult) result;
        Map<String, EObject> refMap = ((TcgRenaming) linker.getRenaming(result.getParent())).getTcgRefMap();
        if (refMap != null) {
            EObject property = refMap.get(pr.getName());
            if (property instanceof GuaranteeStatement) {
                manager.add(createHyperlinkAction("Go To Guarantee", property));
            }
            if (property instanceof LemmaStatement) {
                manager.add(createHyperlinkAction("Go To Lemma", property));
            }
            if (property instanceof AssumeStatement) {
                manager.add(createHyperlinkAction("Go To Assumption", property));
            }
            if (property instanceof CallExpr) {
                manager.add(createHyperlinkAction("Go To Node Call", property));
            }
        }
    }
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EObject(org.eclipse.emf.ecore.EObject) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) TcgRenaming(com.rockwellcollins.atc.tcg.obligations.ufc.TcgRenaming) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) PropertyResult(jkind.api.results.PropertyResult)

Example 3 with AssumeStatement

use of com.rockwellcollins.atc.agree.agree.AssumeStatement in project AGREE by loonwerks.

the class LustreAstBuilder method addHistoricalAssumptionConstraint.

private static void addHistoricalAssumptionConstraint(AgreeNode agreeNode, String prefix, Expr clockExpr, List<AgreeStatement> assertions, Node lustreNode) {
    Expr assumConj = new BoolExpr(true);
    for (VarDecl lustreVar : lustreNode.inputs) {
        AgreeVar var = (AgreeVar) lustreVar;
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            Expr varId = new IdExpr(prefix + var.id);
            assumConj = LustreExprFactory.makeANDExpr(varId, assumConj);
        }
    }
    // assumConj = new BinaryExpr(clockExpr, BinaryOp.IMPLIES, assumConj);
    Expr histCall = new NodeCallExpr(historyNodeName, assumConj);
    Expr assertExpr = new BinaryExpr(new IdExpr(prefix + assumeSuffix + "__HIST"), BinaryOp.EQUAL, histCall);
    assertions.add(new AgreeStatement("", assertExpr, null));
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 4 with AssumeStatement

use of com.rockwellcollins.atc.agree.agree.AssumeStatement in project AGREE by loonwerks.

the class LustreContractAstBuilder method addInitConstraint.

protected static void addInitConstraint(AgreeNode agreeNode, List<AgreeVar> outputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    if (agreeNode.timing != TimingModel.SYNC) {
        String tickedName = subAgreeNode.id + "___TICKED";
        outputs.add(new AgreeVar(tickedName, NamedType.BOOL, null, agreeNode.compInst, null));
        Expr tickedId = new IdExpr(tickedName);
        Expr preTicked = new UnaryExpr(UnaryOp.PRE, tickedId);
        Expr tickedOrPre = new BinaryExpr(clockExpr, BinaryOp.OR, preTicked);
        Expr initOrTicked = new BinaryExpr(clockExpr, BinaryOp.ARROW, tickedOrPre);
        Expr tickedEq = new BinaryExpr(tickedId, BinaryOp.EQUAL, initOrTicked);
        assertions.add(new AgreeStatement("", tickedEq, null));
        // we have two re-write the ids in the initial expressions
        IdRewriter rewriter = id -> new IdExpr(prefix + id.id);
        Expr newInit = subAgreeNode.initialConstraint.accept(new IdRewriteVisitor(rewriter));
        Expr initConstr = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, newInit);
        assertions.add(new AgreeStatement("", initConstr, null));
        // we also need to add hold expressions for the assumptions and
        // lemmas
        Expr assumeLemmaTrue = new BoolExpr(true);
        for (VarDecl lustreVar : lustreNode.inputs) {
            AgreeVar var = (AgreeVar) lustreVar;
            if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
                assumeLemmaTrue = new BinaryExpr(assumeLemmaTrue, BinaryOp.AND, new IdExpr(prefix + var.id));
            }
        }
        assumeLemmaTrue = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, assumeLemmaTrue);
        assertions.add(new AgreeStatement("", assumeLemmaTrue, null));
    }
}
Also used : IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) Program(jkind.lustre.Program) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeBuilder(jkind.lustre.builders.NodeBuilder) CondactExpr(jkind.lustre.CondactExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) Expr(jkind.lustre.Expr) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BinaryOp(jkind.lustre.BinaryOp) UnaryOp(jkind.lustre.UnaryOp) IdExpr(jkind.lustre.IdExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) Contract(jkind.lustre.Contract) NamedType(jkind.lustre.NamedType) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Equation(jkind.lustre.Equation) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) Node(jkind.lustre.Node) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) TypeDef(jkind.lustre.TypeDef) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) BinaryExpr(jkind.lustre.BinaryExpr) IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) UnaryExpr(jkind.lustre.UnaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl)

Example 5 with AssumeStatement

use of com.rockwellcollins.atc.agree.agree.AssumeStatement in project AGREE by loonwerks.

the class LustreContractAstBuilder method getContractLustreProgram.

public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<Expr> requires = new ArrayList<>();
    List<Expr> ensures = new ArrayList<>();
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    for (AgreeStatement assumption : flatNode.assumptions) {
        requires.add(assumption.expr);
    }
    for (AgreeStatement guarantee : flatNode.lemmas) {
        ensures.add(guarantee.expr);
    }
    for (AgreeStatement guarantee : flatNode.guarantees) {
        ensures.add(guarantee.expr);
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        outputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            throw new AgreeException("This shouldn't happen");
        }
    }
    Contract contract = new Contract(requires, ensures);
    NodeBuilder builder = new NodeBuilder("_TOP");
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setContract(contract);
    Node main = builder.build();
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(main);
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TypeDef(jkind.lustre.TypeDef) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Contract(jkind.lustre.Contract)

Aggregations

AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)11 LemmaStatement (com.rockwellcollins.atc.agree.agree.LemmaStatement)8 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)7 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)6 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)6 VarDecl (jkind.lustre.VarDecl)6 BinaryExpr (jkind.lustre.BinaryExpr)5 Expr (jkind.lustre.Expr)5 IdExpr (jkind.lustre.IdExpr)5 Node (jkind.lustre.Node)5 Program (jkind.lustre.Program)5 UnaryExpr (jkind.lustre.UnaryExpr)5 EObject (org.eclipse.emf.ecore.EObject)5 ArrayList (java.util.ArrayList)4 Equation (jkind.lustre.Equation)4 NodeBuilder (jkind.lustre.builders.NodeBuilder)4 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)4 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)3 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)3 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)3