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;
}
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));
}
}
}
}
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;
}
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;
}
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;
}
Aggregations