Search in sources :

Example 1 with GuaranteeStatement

use of com.rockwellcollins.atc.agree.agree.GuaranteeStatement 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 GuaranteeStatement

use of com.rockwellcollins.atc.agree.agree.GuaranteeStatement 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 GuaranteeStatement

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

the class AgreeASTBuilder method getGuaranteeStatements.

private List<AgreeStatement> getGuaranteeStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
    List<AgreeStatement> guarantees = new ArrayList<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof GuaranteeStatement) {
            GuaranteeStatement guarantee = (GuaranteeStatement) spec;
            String str = guarantee.getStr();
            if (guarantee.getExpr() != null) {
                guarantees.add(new AgreeStatement(str, doSwitch(guarantee.getExpr()).accept(new SubstitutionVisitor(rewriteMap)), guarantee));
            } else {
                PatternStatement pattern = guarantee.getPattern();
                AgreeStatement patStatement = new AgreePatternBuilder(str, guarantee, this).doSwitch(pattern);
                patStatement.expr = patStatement.expr.accept(new SubstitutionVisitor(rewriteMap));
                guarantees.add(patStatement);
            }
        }
    }
    return guarantees;
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) PatternStatement(com.rockwellcollins.atc.agree.agree.PatternStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreePatternBuilder(com.rockwellcollins.atc.agree.analysis.realtime.AgreePatternBuilder)

Example 4 with GuaranteeStatement

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

the class RenamingVisitor method visit.

@Override
public Void visit(VarDecl e) {
    if (isFunction) {
        renaming.addUninterpretedFnIONames(e.id);
        return null;
    }
    if (e instanceof AgreeVar) {
        AgreeVar var = (AgreeVar) e;
        String category = getCategory(rootInstance, var);
        String refStr = getReferenceStr(var);
        if (isMainNode && var.reference != null) {
            // TODO: the means of detecting whether this is a consistency analysis is a hack. Fix it.
            if ((var.reference instanceof AssumeStatement || (nodeName.contains("consistency") && var.reference instanceof GuaranteeStatement)) && category != null && category.equals("")) {
                renaming.addSupportRename(var.id, var.id);
                renaming.addSupportRefString(var.id, refStr);
                renaming.getRefMap().put(refStr, var.reference);
            } else {
                renaming.addExplicitRename(var.id, refStr);
                renaming.addToRefMap(var.id, var.reference);
            }
        } else if (var.reference instanceof GuaranteeStatement) {
            renaming.addSupportRename(nodeName + "." + var.id, category + "." + var.id);
            renaming.addSupportRefString(nodeName + "." + var.id, refStr);
            renaming.getRefMap().put(refStr, var.reference);
        } else {
            return null;
        }
        if (category != null && !layout.getCategories().contains(category)) {
            layout.addCategory(category);
        }
        layout.addElement(category, refStr, SigType.INPUT);
    }
    return null;
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 5 with GuaranteeStatement

use of com.rockwellcollins.atc.agree.agree.GuaranteeStatement in project AMASE by loonwerks.

the class FaultsVerifyAllHandler method doFaultPropagationInjection.

protected Program doFaultPropagationInjection(JKindResult result, Program program) {
    List<JKindResult> childVerifications = getChildContractResults(result);
    // com.rockwellcollins.atc.agree.analysis.VerifyHandler#wrapVerificationResult(ComponentInstance, CompositeAnalysisResult)
    if ("Contract Guarantees".equals(result.getName())) {
        for (JKindResult childResult : childVerifications) {
            AgreeRenaming childRenaming = (AgreeRenaming) linker.getRenaming(childResult);
            for (PropertyResult propertyResult : childResult.getPropertyResults()) {
                // where it is protected and we need to duplicate the literal here.
                if (propertyResult.getProperty() instanceof InvalidProperty && childRenaming.getRefMap().get(propertyResult.getProperty().getName()) instanceof GuaranteeStatement) {
                    String guaranteeName = propertyResult.getProperty().getName();
                    String lustreVarName = childRenaming.getLustreNameFromAgreeVar(guaranteeName);
                    // WARNING: Here we assume that the subnode id of interest is named as given below.
                    // We need to introduce this literal "_TOP__" here because the computation is hidden in AGREE
                    // literals in com.rockwellcollins.atc.agree.analysis.LustreAstBuilder#getAssumeGuaranteeLustreProgram(AgreeProgram)
                    // WARNING: the string literal "Verification for " in the line below needs to match that in
                    // com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#runJob(Element, IProgressMonitor) and
                    // com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#buildAnalysisResult(String, ComponentInstance)
                    String subnodeName = "_TOP__" + childResult.getParent().getName().replaceFirst("Verification for ", "");
                    // TODO: The string concatenation is also done in the AddFaultDriverVisitor; unify them
                    program = new AddFaultDriverVisitor(subnodeName, lustreVarName).visit(program);
                } else if (propertyResult.getProperty() instanceof ValidProperty && propertyResult.getProperty().getName().contains(childRenaming.forceRename(AddPairwiseFaultDriverWitnesses.FAULT_DRIVER_PAIR_WITNESS_BASENAME)) && pairwiseFaultDriverProperties.containsKey(childResult) && pairwiseFaultDriverProperties.get(childResult).containsKey(propertyResult.getName()) && // invalidated and have corresponding fault drivers that are present in this verification
                pairwiseFaultDriverProperties.get(childResult).get(propertyResult.getName()).entrySet().stream().allMatch(e -> {
                    PropertyResult p = childResult.getPropertyResult(childRenaming.rename(e.getKey()));
                    return (p != null) ? p.getProperty() instanceof InvalidProperty : false;
                })) {
                    program = new AddFaultDriverGuardAssertionVisitor(program.main, pairwiseFaultDriverProperties.get(childResult).get(propertyResult.getName()).values().stream().collect(Collectors.toList())).visit(program);
                }
            }
        }
        /* If not the top analysis, that is the parent of the composite parent of the composite parent of this result is not null */
        if (result.getParent().getParent().getParent() != null) {
            Map<PropertyResult, String> accumulatedGuarantees = Maps.newLinkedHashMap();
            for (PropertyResult propertyResult : result.getPropertyResults()) {
                AgreeRenaming renaming = (AgreeRenaming) linker.getRenaming(result);
                if (renaming.getRefMap().get(propertyResult.getName()) instanceof GuaranteeStatement) {
                    String guaranteeName = propertyResult.getName();
                    String lustreVarName = renaming.getLustreNameFromAgreeVar(guaranteeName);
                    accumulatedGuarantees.put(propertyResult, lustreVarName);
                }
            }
            AddPairwiseFaultDriverWitnesses pairwiseFaultVisitor = new AddPairwiseFaultDriverWitnesses(Lists.newArrayList(accumulatedGuarantees.values()));
            program = pairwiseFaultVisitor.visit(program);
            result.addProperties(pairwiseFaultVisitor.getProperties());
            // WARNING: the string literal "Verification for " in the line below needs to match that in
            // com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#runJob(Element, IProgressMonitor) and
            // com.rockwellcollins.atc.agree.analysis.handlers.VerifyHandler#buildAnalysisResult(String, ComponentInstance)
            // TODO: the concatenation of nodeName with fault driver is done elsewhere too, unify
            String nodeName = "_TOP__" + result.getParent().getName().replaceFirst("Verification for ", "");
            pairwiseFaultDriverProperties.put(result, pairwiseFaultVisitor.getPairwiseWitnesses().entrySet().stream().collect(Collectors.toMap(e -> ((AgreeRenaming) linker.getRenaming(result)).forceRename(e.getKey()), e -> e.getValue().stream().collect(Collectors.toMap(id -> id, id -> nodeName + AddFaultDriverVisitor.getFaultDriverId(id))))));
        }
    }
    return program;
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) ValidProperty(jkind.results.ValidProperty) AddFaultDriverGuardAssertionVisitor(edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultDriverGuardAssertionVisitor) AddFaultDriverVisitor(edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultDriverVisitor) InvalidProperty(jkind.results.InvalidProperty) PropertyResult(jkind.api.results.PropertyResult) AddPairwiseFaultDriverWitnesses(edu.umn.cs.crisys.safety.analysis.ast.visitors.AddPairwiseFaultDriverWitnesses) SafetyJKindResult(edu.umn.cs.crisys.safety.analysis.results.SafetyJKindResult) JKindResult(jkind.api.results.JKindResult)

Aggregations

GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)8 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)6 EObject (org.eclipse.emf.ecore.EObject)5 LemmaStatement (com.rockwellcollins.atc.agree.agree.LemmaStatement)4 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)3 PropertyResult (jkind.api.results.PropertyResult)3 AssertStatement (com.rockwellcollins.atc.agree.agree.AssertStatement)2 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)2 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)2 AgreeRenaming (com.rockwellcollins.atc.agree.analysis.AgreeRenaming)2 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)2 Node (jkind.lustre.Node)2 Program (jkind.lustre.Program)2 VarDecl (jkind.lustre.VarDecl)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1