use of edu.uiowa.cs.clc.kind2.lustre.ContractBodyBuilder 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;
}
Aggregations