use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitContractMode.
/**
* Extract a contract mode.
*/
@Override
public void exitContractMode(LustreParser.ContractModeContext ctx) {
ctx.mode = new ContractMode();
ctx.mode.setName(ctx.ID().getText());
ctx.require.forEach(require -> {
ContractItem contractItem = new ContractItem();
contractItem.setExpression(require.expression);
ctx.mode.getRequire().add(contractItem);
});
ctx.ensure.forEach(ensure -> {
ContractItem contractItem = new ContractItem();
contractItem.setExpression(ensure.expression);
ctx.mode.getEnsure().add(contractItem);
});
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
public void visit(ContractMode contractMode) {
contractMode.getName();
sb.append(NL);
// Ensure
for (ContractItem contractItem : contractMode.getEnsure()) {
sb.append(TAB);
sb.append("require ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
// Require
for (ContractItem contractItem : contractMode.getRequire()) {
sb.append(TAB);
sb.append("ensure ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
public void visit(ContractSpec contractSpec) {
// Symbols
for (SymbolDefinition symbolDef : contractSpec.getSymbol()) {
sb.append(TAB);
sb.append("var ");
visit(symbolDef);
sb.append(";");
sb.append(NL);
}
// Assumuptions
for (ContractItem contractItem : contractSpec.getAssume()) {
sb.append(TAB).append("assume ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
sb.append(NL);
// Guarantees
for (ContractItem contractItem : contractSpec.getGuarantee()) {
sb.append(TAB).append("guarantee ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
sb.append(NL);
// Modes
for (ContractMode contractMode : contractSpec.getMode()) {
sb.append(TAB).append("mode ");
sb.append(TAB).append(" (");
sb.append(TAB).append(NL);
visit(contractMode);
sb.append(";");
sb.append(NL);
}
// Imports
for (ContractImport contractImport : contractSpec.getImport()) {
sb.append(TAB);
sb.append("import ");
visit(contractImport);
sb.append(";");
sb.append(NL);
}
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class Agree2Vdm method translateAssumeStatement.
private ContractItem translateAssumeStatement(AssumeStatement assumeStmt, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
ContractItem contractItem = new ContractItem();
contractItem.setName(assumeStmt.getStr());
Expr agreeExpr = assumeStmt.getExpr();
Expression vdmlustrExpr = getVdmExpressionFromAgreeExpression(agreeExpr, dataTypeDecl, nodeDecl, model);
contractItem.setExpression(vdmlustrExpr);
return contractItem;
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class VerdictTestInstrumentor method instrumentTests.
/**
* Produce one affirmative and one negated guarantee for every cyber requirement in the
* top-level system of the model.
*/
public void instrumentTests() {
ComponentType topLevel = getTopLevelSystemType();
List<ContractItem> guarantees = topLevel.getContract().getGuarantee();
List<ContractItem> replaceWith = new ArrayList<>();
for (ContractItem guarantee : guarantees) {
String name = guarantee.getName();
// Build negated expression
Expression negExpr = new Expression();
negExpr.setNot(guarantee.getExpression());
ContractItem pos = new ContractItem();
pos.setExpression(guarantee.getExpression());
pos.setName("pos_" + name);
ContractItem neg = new ContractItem();
neg.setExpression(negExpr);
neg.setName("neg_" + name);
replaceWith.add(pos);
replaceWith.add(neg);
}
// Remove old guarantees and use our own
guarantees.clear();
guarantees.addAll(replaceWith);
}
Aggregations