use of verdict.vdm.vdm_lustre.ContractMode in project VERDICT by ge-high-assurance.
the class VDMLustre2Kind2 method visit.
/**
* Translate VDM model contract specification to Kind 2 Lustre contract body.
*
* @param modelSpec the VDM model contract spec
* @return the Kind 2 Lustre contract body builder
*/
private static ContractBodyBuilder visit(ContractSpec modelSpec) {
ContractBodyBuilder cbb = new ContractBodyBuilder();
for (ContractImport contractImport : modelSpec.getImport()) {
cbb.importContract(contractImport.getContractId(), contractImport.getInputArgument().stream().map(input -> (IdExpr) visit(input)).collect(Collectors.toList()), contractImport.getOutputArgument().stream().map(output -> (IdExpr) visit(output)).collect(Collectors.toList()));
}
for (SymbolDefinition symbol : modelSpec.getSymbol()) {
if (symbol.isIsConstant() != null && symbol.isIsConstant()) {
if (symbol.getDataType() != null) {
if (symbol.getDefinition() != null) {
cbb.createConstant(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
} else {
cbb.createConstant(symbol.getName(), visit(symbol.getDataType()));
}
} else {
cbb.createConstant(symbol.getName(), visit(symbol.getDefinition()));
}
} else {
cbb.createVarDef(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
}
}
for (ContractItem assumption : modelSpec.getWeaklyassume()) {
cbb.weaklyAssume(assumption.getName(), visit(assumption.getExpression()));
}
for (ContractItem assumption : modelSpec.getAssume()) {
cbb.assume(assumption.getName(), visit(assumption.getExpression()));
}
for (ContractItem guarantee : modelSpec.getGuarantee()) {
cbb.guarantee(guarantee.getName(), visit(guarantee.getExpression()));
}
for (ContractMode mode : modelSpec.getMode()) {
ModeBuilder mb = new ModeBuilder(mode.getName());
for (ContractItem require : mode.getRequire()) {
mb.require(require.getName(), visit(require.getExpression()));
}
for (ContractItem ensure : mode.getEnsure()) {
mb.ensure(ensure.getName(), visit(ensure.getExpression()));
}
cbb.addMode(mb);
}
return cbb;
}
use of verdict.vdm.vdm_lustre.ContractMode 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.ContractMode 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);
}
}
Aggregations