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